[project @ 2001-10-29 11:31:51 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / DriverPhases.hs
1 -----------------------------------------------------------------------------
2 -- $Id: DriverPhases.hs,v 1.14 2001/10/29 11:31:51 simonmar Exp $
3 --
4 -- GHC Driver
5 --
6 -- (c) Simon Marlow 2000
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    objish_file, objish_suffix,
20    cish_file, cish_suffix
21  ) where
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         | HsPp
45         | Hsc -- ToDo: HscTargetLang
46         | Cc
47         | HCc           -- Haskellised C (as opposed to vanilla C) compilation
48         | Mangle        -- assembly mangling, now done by a separate script.
49         | SplitMangle   -- after mangler if splitting
50         | SplitAs
51         | As
52         | Ln
53 #ifdef ILX
54         | Ilx2Il
55         | Ilasm
56 #endif
57   deriving (Eq, Show)
58
59 -- the first compilation phase for a given file is determined
60 -- by its suffix.
61 startPhase "lhs"   = Unlit
62 startPhase "hs"    = Cpp
63 startPhase "hscpp" = HsPp
64 startPhase "hspp"  = Hsc
65 startPhase "hc"    = HCc
66 startPhase "c"     = Cc
67 startPhase "cpp"   = Cc
68 startPhase "C"     = Cc
69 startPhase "cc"    = Cc
70 startPhase "cxx"   = Cc
71 startPhase "raw_s" = Mangle
72 startPhase "s"     = As
73 startPhase "S"     = As
74 startPhase "o"     = Ln
75 startPhase _       = Ln    -- all unknown file types
76
77 -- the output suffix for a given phase is uniquely determined by
78 -- the input requirements of the next phase.
79 phaseInputExt Unlit       = "lhs"
80 phaseInputExt Cpp         = "lpp"       -- intermediate only
81 phaseInputExt HsPp        = "hscpp"
82 phaseInputExt Hsc         = "hspp"
83 phaseInputExt HCc         = "hc"
84 phaseInputExt Cc          = "c"
85 phaseInputExt Mangle      = "raw_s"
86 phaseInputExt SplitMangle = "split_s"   -- not really generated
87 phaseInputExt As          = "s"
88 phaseInputExt SplitAs     = "split_s"   -- not really generated
89 phaseInputExt Ln          = "o"
90 phaseInputExt MkDependHS  = "dep"
91 #ifdef ILX
92 phaseInputExt Ilx2Il      = "ilx"
93 phaseInputExt Ilasm       = "il"
94 #endif
95
96 haskellish_suffix     = (`elem` [ "hs", "hspp", "hscpp", "lhs", "hc", "raw_s" ])
97 haskellish_src_suffix = (`elem` [ "hs", "hspp", "hscpp", "lhs" ])
98 cish_suffix           = (`elem` [ "c", "cpp", "C", "cc", "cxx", "s", "S" ])
99
100 #if mingw32_TARGET_OS || cygwin32_TARGET_OS
101 objish_suffix     = (`elem` [ "o", "O", "obj", "OBJ" ])
102 #else
103 objish_suffix     = (`elem` [ "o" ])
104 #endif
105
106 haskellish_file     = haskellish_suffix     . getFileSuffix
107 haskellish_src_file = haskellish_src_suffix . getFileSuffix
108 cish_file           = cish_suffix           . getFileSuffix
109 objish_file         = objish_suffix         . getFileSuffix