[project @ 2003-06-26 21:55:46 by sof]
[ghc-hetmet.git] / ghc / compiler / main / DriverPhases.hs
1 -----------------------------------------------------------------------------
2 -- $Id: DriverPhases.hs,v 1.27 2003/06/26 21:55:47 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    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    haskellish_user_src_file,
24    isSourceFile         -- :: FilePath -> Bool
25  ) where
26
27 import DriverUtil
28
29 -----------------------------------------------------------------------------
30 -- Phases
31
32 {-
33    Phase of the           | Suffix saying | Flag saying   | (suffix of)
34    compilation system     | ``start here''| ``stop after''| output file
35    
36    literate pre-processor | .lhs          | -             | -
37    C pre-processor (opt.) | -             | -E            | -
38    Haskell compiler       | .hs           | -C, -S        | .hc, .s
39    C compiler (opt.)      | .hc or .c     | -S            | .s
40    assembler              | .s  or .S     | -c            | .o
41    linker                 | other         | -             | a.out
42 -}
43
44 data Phase 
45         = Unlit
46         | Cpp
47         | HsPp
48         | Hsc
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 -- Partial ordering on phases: we want to know which phases will occur before 
63 -- which others.  This is used for sanity checking, to ensure that the
64 -- pipeline will stop at some point (see DriverPipeline.runPipeline).
65 x `happensBefore` y 
66         | x `elem` haskell_pipe = y `elem` tail (dropWhile (/= x) haskell_pipe)
67         | x `elem` c_pipe       = y `elem` tail (dropWhile (/= x) c_pipe)
68         | otherwise = False
69
70 haskell_pipe = [Unlit,Cpp,HsPp,Hsc,HCc,Mangle,SplitMangle,As,SplitAs,Ln]
71 c_pipe       = [Cc,As,Ln]
72
73 -- the first compilation phase for a given file is determined
74 -- by its suffix.
75 startPhase "lhs"   = Unlit
76 startPhase "hs"    = Cpp
77 startPhase "hscpp" = HsPp
78 startPhase "hspp"  = Hsc
79 startPhase "hcr"   = Hsc
80 startPhase "hc"    = HCc
81 startPhase "c"     = Cc
82 startPhase "cpp"   = Cc
83 startPhase "C"     = Cc
84 startPhase "cc"    = Cc
85 startPhase "cxx"   = Cc
86 startPhase "raw_s" = Mangle
87 startPhase "s"     = As
88 startPhase "S"     = As
89 startPhase "o"     = Ln
90 startPhase _       = Ln    -- all unknown file types
91
92 -- the output suffix for a given phase is uniquely determined by
93 -- the input requirements of the next phase.
94 phaseInputExt Unlit       = "lhs"
95 phaseInputExt Cpp         = "lpp"       -- intermediate only
96 phaseInputExt HsPp        = "hscpp"
97 phaseInputExt Hsc         = "hspp"
98 phaseInputExt HCc         = "hc"
99 phaseInputExt Cc          = "c"
100 phaseInputExt Mangle      = "raw_s"
101 phaseInputExt SplitMangle = "split_s"   -- not really generated
102 phaseInputExt As          = "s"
103 phaseInputExt SplitAs     = "split_s"   -- not really generated
104 phaseInputExt Ln          = "o"
105 #ifdef ILX
106 phaseInputExt Ilx2Il      = "ilx"
107 phaseInputExt Ilasm       = "il"
108 #endif
109
110 haskellish_suffix          = (`elem` [ "hs", "lhs", "hspp", "hscpp", "hcr", "hc", "raw_s" ])
111 haskellish_src_suffix      = (`elem` [ "hs", "lhs", "hspp", "hscpp", "hcr"])
112 cish_suffix                = (`elem` [ "c", "cpp", "C", "cc", "cxx", "s", "S" ])
113 extcoreish_suffix          = (`elem` [ "hcr" ])
114 haskellish_user_src_suffix = (`elem` [ "hs", "lhs" ])
115
116 -- Use the appropriate suffix for the system on which 
117 -- the GHC-compiled code will run
118 #if mingw32_TARGET_OS || cygwin32_TARGET_OS
119 objish_suffix     = (`elem` [ "o", "O", "obj", "OBJ" ])
120 #else
121 objish_suffix     = (`elem` [ "o" ])
122 #endif
123
124 haskellish_file          = haskellish_suffix     . getFileSuffix
125 haskellish_src_file      = haskellish_src_suffix . getFileSuffix
126 cish_file                = cish_suffix           . getFileSuffix
127 isExtCore_file           = extcoreish_suffix     . getFileSuffix
128 objish_file              = objish_suffix         . getFileSuffix
129 haskellish_user_src_file = haskellish_user_src_suffix . getFileSuffix
130
131 isSourceFile :: FilePath -> Bool
132 isSourceFile   f    =
133    haskellish_file f ||
134    cish_file   f