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