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