[project @ 2002-03-04 17:01:26 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / DriverPhases.hs
1 -----------------------------------------------------------------------------
2 -- $Id: DriverPhases.hs,v 1.16 2002/03/04 17:01:30 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    hsbootish_file, hsbootish_suffix,
20    objish_file, objish_suffix,
21    cish_file, cish_suffix
22  ) where
23
24 import DriverUtil
25
26 -----------------------------------------------------------------------------
27 -- Phases
28
29 {-
30    Phase of the           | Suffix saying | Flag saying   | (suffix of)
31    compilation system     | ``start here''| ``stop after''| output file
32    
33    literate pre-processor | .lhs          | -             | -
34    C pre-processor (opt.) | -             | -E            | -
35    Haskell compiler       | .hs           | -C, -S        | .hc, .s
36    C compiler (opt.)      | .hc or .c     | -S            | .s
37    assembler              | .s  or .S     | -c            | .o
38    linker                 | other         | -             | a.out
39 -}
40
41 data Phase 
42         = MkDependHS    -- haskell dependency generation
43         | Unlit
44         | Cpp
45         | HsPp
46         | Hsc
47         | HsBoot
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 "hs-boot" = HsBoot
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 phaseInputExt HsBoot      = "hs-boot"
95 #ifdef ILX
96 phaseInputExt Ilx2Il      = "ilx"
97 phaseInputExt Ilasm       = "il"
98 #endif
99
100 haskellish_suffix     = (`elem` [ "hs", "hspp", "hscpp", "lhs", "hc", "raw_s" ])
101 haskellish_src_suffix = (`elem` [ "hs", "hspp", "hscpp", "lhs" ])
102 cish_suffix           = (`elem` [ "c", "cpp", "C", "cc", "cxx", "s", "S" ])
103 hsbootish_suffix      = (`elem` [ "hs-boot" ])
104
105 #if mingw32_TARGET_OS || cygwin32_TARGET_OS
106 objish_suffix     = (`elem` [ "o", "O", "obj", "OBJ" ])
107 #else
108 objish_suffix     = (`elem` [ "o" ])
109 #endif
110
111 haskellish_file     = haskellish_suffix     . getFileSuffix
112 haskellish_src_file = haskellish_src_suffix . getFileSuffix
113 cish_file           = cish_suffix           . getFileSuffix
114 objish_file         = objish_suffix         . getFileSuffix
115 hsbootish_file      = hsbootish_suffix      . getFileSuffix