[project @ 2003-05-21 12:46:19 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / DriverPhases.hs
1 -----------------------------------------------------------------------------
2 -- $Id: DriverPhases.hs,v 1.24 2003/05/21 12:46:19 simonmar 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    objish_file, objish_suffix,
20    cish_file, cish_suffix,
21    isExtCore_file, extcoreish_suffix,
22    isSourceFile         -- :: FilePath -> Bool
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         | Cc
49         | HCc           -- Haskellised C (as opposed to vanilla C) compilation
50         | Mangle        -- assembly mangling, now done by a separate script.
51         | SplitMangle   -- after mangler if splitting
52         | SplitAs
53         | As
54         | Ln
55 #ifdef ILX
56         | Ilx2Il
57         | Ilasm
58 #endif
59   deriving (Eq, Show)
60
61 -- the first compilation phase for a given file is determined
62 -- by its suffix.
63 startPhase "lhs"   = Unlit
64 startPhase "hs"    = Cpp
65 startPhase "hscpp" = HsPp
66 startPhase "hspp"  = Hsc
67 startPhase "hcr"   = Hsc
68 startPhase "hc"    = HCc
69 startPhase "c"     = Cc
70 startPhase "cpp"   = Cc
71 startPhase "C"     = Cc
72 startPhase "cc"    = Cc
73 startPhase "cxx"   = Cc
74 startPhase "raw_s" = Mangle
75 startPhase "s"     = As
76 startPhase "S"     = As
77 startPhase "o"     = Ln
78 startPhase _       = Ln    -- all unknown file types
79
80 -- the output suffix for a given phase is uniquely determined by
81 -- the input requirements of the next phase.
82 phaseInputExt Unlit       = "lhs"
83 phaseInputExt Cpp         = "lpp"       -- intermediate only
84 phaseInputExt HsPp        = "hscpp"
85 phaseInputExt Hsc         = "hspp"
86 phaseInputExt HCc         = "hc"
87 phaseInputExt Cc          = "c"
88 phaseInputExt Mangle      = "raw_s"
89 phaseInputExt SplitMangle = "split_s"   -- not really generated
90 phaseInputExt As          = "s"
91 phaseInputExt SplitAs     = "split_s"   -- not really generated
92 phaseInputExt Ln          = "o"
93 phaseInputExt MkDependHS  = "dep"
94 #ifdef ILX
95 phaseInputExt Ilx2Il      = "ilx"
96 phaseInputExt Ilasm       = "il"
97 #endif
98
99 haskellish_suffix     = (`elem` [ "hs", "lhs", "hspp", "hscpp", "hcr", "hc", "raw_s" ])
100 haskellish_src_suffix = (`elem` [ "hs", "lhs", "hspp", "hscpp", "hcr"])
101 cish_suffix           = (`elem` [ "c", "cpp", "C", "cc", "cxx", "s", "S" ])
102 extcoreish_suffix     = (`elem` [ "hcr" ])
103
104 -- Use the appropriate suffix for the system on which 
105 -- the GHC-compiled code will run
106 #if mingw32_TARGET_OS || cygwin32_TARGET_OS
107 objish_suffix     = (`elem` [ "o", "O", "obj", "OBJ" ])
108 #else
109 objish_suffix     = (`elem` [ "o" ])
110 #endif
111
112 haskellish_file     = haskellish_suffix     . getFileSuffix
113 haskellish_src_file = haskellish_src_suffix . getFileSuffix
114 cish_file           = cish_suffix           . getFileSuffix
115 isExtCore_file      = extcoreish_suffix     . getFileSuffix
116 objish_file         = objish_suffix         . getFileSuffix
117
118 isSourceFile :: FilePath -> Bool
119 isSourceFile   f    =
120    haskellish_file f ||
121    cish_file   f