[project @ 2003-06-04 15:47:58 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / DriverPhases.hs
1 -----------------------------------------------------------------------------
2 -- $Id: DriverPhases.hs,v 1.25 2003/06/04 15:47:59 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    happensBefore,
15    startPhase,          -- :: String -> Phase
16    phaseInputExt,       -- :: Phase -> String
17
18    haskellish_file, haskellish_suffix,
19    haskellish_src_file, haskellish_src_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         = 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 -- Partial ordering on phases: we want to know which phases will occur before 
62 -- which others.  This is used for sanity checking, to ensure that the
63 -- pipeline will stop at some point (see DriverPipeline.runPipeline).
64 x `happensBefore` y 
65         | x `elem` haskell_pipe = y `elem` tail (dropWhile (/= x) haskell_pipe)
66         | x `elem` c_pipe       = y `elem` tail (dropWhile (/= x) c_pipe)
67         | otherwise = False
68
69 haskell_pipe = [Unlit,Cpp,HsPp,Hsc,HCc,Mangle,As,Ln]
70 c_pipe       = [Cc,As,Ln]
71
72 -- the first compilation phase for a given file is determined
73 -- by its suffix.
74 startPhase "lhs"   = Unlit
75 startPhase "hs"    = Cpp
76 startPhase "hscpp" = HsPp
77 startPhase "hspp"  = Hsc
78 startPhase "hcr"   = Hsc
79 startPhase "hc"    = HCc
80 startPhase "c"     = Cc
81 startPhase "cpp"   = Cc
82 startPhase "C"     = Cc
83 startPhase "cc"    = Cc
84 startPhase "cxx"   = Cc
85 startPhase "raw_s" = Mangle
86 startPhase "s"     = As
87 startPhase "S"     = As
88 startPhase "o"     = Ln
89 startPhase _       = Ln    -- all unknown file types
90
91 -- the output suffix for a given phase is uniquely determined by
92 -- the input requirements of the next phase.
93 phaseInputExt Unlit       = "lhs"
94 phaseInputExt Cpp         = "lpp"       -- intermediate only
95 phaseInputExt HsPp        = "hscpp"
96 phaseInputExt Hsc         = "hspp"
97 phaseInputExt HCc         = "hc"
98 phaseInputExt Cc          = "c"
99 phaseInputExt Mangle      = "raw_s"
100 phaseInputExt SplitMangle = "split_s"   -- not really generated
101 phaseInputExt As          = "s"
102 phaseInputExt SplitAs     = "split_s"   -- not really generated
103 phaseInputExt Ln          = "o"
104 #ifdef ILX
105 phaseInputExt Ilx2Il      = "ilx"
106 phaseInputExt Ilasm       = "il"
107 #endif
108
109 haskellish_suffix     = (`elem` [ "hs", "lhs", "hspp", "hscpp", "hcr", "hc", "raw_s" ])
110 haskellish_src_suffix = (`elem` [ "hs", "lhs", "hspp", "hscpp", "hcr"])
111 cish_suffix           = (`elem` [ "c", "cpp", "C", "cc", "cxx", "s", "S" ])
112 extcoreish_suffix     = (`elem` [ "hcr" ])
113
114 -- Use the appropriate suffix for the system on which 
115 -- the GHC-compiled code will run
116 #if mingw32_TARGET_OS || cygwin32_TARGET_OS
117 objish_suffix     = (`elem` [ "o", "O", "obj", "OBJ" ])
118 #else
119 objish_suffix     = (`elem` [ "o" ])
120 #endif
121
122 haskellish_file     = haskellish_suffix     . getFileSuffix
123 haskellish_src_file = haskellish_src_suffix . getFileSuffix
124 cish_file           = cish_suffix           . getFileSuffix
125 isExtCore_file      = extcoreish_suffix     . getFileSuffix
126 objish_file         = objish_suffix         . getFileSuffix
127
128 isSourceFile :: FilePath -> Bool
129 isSourceFile   f    =
130    haskellish_file f ||
131    cish_file   f