[project @ 2001-06-14 15:42:35 by simonpj]
[ghc-hetmet.git] / ghc / compiler / main / DriverPhases.hs
1 -----------------------------------------------------------------------------
2 -- $Id: DriverPhases.hs,v 1.10 2001/06/14 15:42:35 simonpj Exp $
3 --
4 -- GHC Driver
5 --
6 -- (c) Simon Marlow 2000
7 --
8 -----------------------------------------------------------------------------
9
10 module DriverPhases (
11    Phase(..),
12    startPhase,          -- :: String -> Phase
13    phaseInputExt,       -- :: Phase -> String
14
15    haskellish_file, haskellish_suffix,
16    haskellish_src_file, haskellish_src_suffix,
17    objish_file, objish_suffix,
18    cish_file, cish_suffix
19  ) where
20
21 #include "../includes/config.h"
22
23 import DriverUtil
24
25 -----------------------------------------------------------------------------
26 -- Phases
27
28 {-
29    Phase of the           | Suffix saying | Flag saying   | (suffix of)
30    compilation system     | ``start here''| ``stop after''| output file
31    
32    literate pre-processor | .lhs          | -             | -
33    C pre-processor (opt.) | -             | -E            | -
34    Haskell compiler       | .hs           | -C, -S        | .hc, .s
35    C compiler (opt.)      | .hc or .c     | -S            | .s
36    assembler              | .s  or .S     | -c            | .o
37    linker                 | other         | -             | a.out
38 -}
39
40 data Phase 
41         = MkDependHS    -- haskell dependency generation
42         | Unlit
43         | Cpp
44         | Hsc -- ToDo: HscTargetLang
45         | Cc
46         | HCc           -- Haskellised C (as opposed to vanilla C) compilation
47         | Mangle        -- assembly mangling, now done by a separate script.
48         | SplitMangle   -- after mangler if splitting
49         | SplitAs
50         | As
51         | Ln 
52   deriving (Eq, Show)
53
54 -- the first compilation phase for a given file is determined
55 -- by its suffix.
56 startPhase "lhs"   = Unlit
57 startPhase "hs"    = Cpp
58 startPhase "hspp"  = Hsc
59 startPhase "hc"    = HCc
60 startPhase "c"     = Cc
61 startPhase "raw_s" = Mangle
62 startPhase "s"     = As
63 startPhase "S"     = As
64 startPhase "o"     = Ln
65 startPhase _       = Ln    -- all unknown file types
66
67 -- the output suffix for a given phase is uniquely determined by
68 -- the input requirements of the next phase.
69 phaseInputExt Unlit       = "lhs"
70 phaseInputExt Cpp         = "lpp"       -- intermediate only
71 phaseInputExt Hsc         = "hspp"
72 phaseInputExt HCc         = "hc"
73 phaseInputExt Cc          = "c"
74 phaseInputExt Mangle      = "raw_s"
75 phaseInputExt SplitMangle = "split_s"   -- not really generated
76 phaseInputExt As          = "s"
77 phaseInputExt SplitAs     = "split_s"   -- not really generated
78 phaseInputExt Ln          = "o"
79 phaseInputExt MkDependHS  = "dep"
80
81 haskellish_suffix     = (`elem` [ "hs", "hspp", "lhs", "hc", "raw_s" ])
82 haskellish_src_suffix = (`elem` [ "hs", "hspp", "lhs" ])
83 cish_suffix           = (`elem` [ "c", "s", "S" ])  -- maybe .cc et al.??
84
85 #if mingw32_TARGET_OS || cygwin32_TARGET_OS
86 objish_suffix     = (`elem` [ "o", "O", "obj", "OBJ" ])
87 #else
88 objish_suffix     = (`elem` [ "o" ])
89 #endif
90
91 haskellish_file     = haskellish_suffix     . getFileSuffix
92 haskellish_src_file = haskellish_src_suffix . getFileSuffix
93 cish_file           = cish_suffix           . getFileSuffix
94 objish_file         = objish_suffix         . getFileSuffix