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