[project @ 2002-03-29 21:39:36 by sof]
[ghc-hetmet.git] / ghc / compiler / main / DriverPhases.hs
1 -----------------------------------------------------------------------------
2 -- $Id: DriverPhases.hs,v 1.17 2002/03/29 21:39:37 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    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 "hcr"   = Hsc
68 startPhase "hs-boot" = HsBoot
69 startPhase "hc"    = HCc
70 startPhase "c"     = Cc
71 startPhase "cpp"   = Cc
72 startPhase "C"     = Cc
73 startPhase "cc"    = Cc
74 startPhase "cxx"   = Cc
75 startPhase "raw_s" = Mangle
76 startPhase "s"     = As
77 startPhase "S"     = As
78 startPhase "o"     = Ln
79 startPhase _       = Ln    -- all unknown file types
80
81 -- the output suffix for a given phase is uniquely determined by
82 -- the input requirements of the next phase.
83 phaseInputExt Unlit       = "lhs"
84 phaseInputExt Cpp         = "lpp"       -- intermediate only
85 phaseInputExt HsPp        = "hscpp"
86 phaseInputExt Hsc         = "hspp"
87 phaseInputExt HCc         = "hc"
88 phaseInputExt Cc          = "c"
89 phaseInputExt Mangle      = "raw_s"
90 phaseInputExt SplitMangle = "split_s"   -- not really generated
91 phaseInputExt As          = "s"
92 phaseInputExt SplitAs     = "split_s"   -- not really generated
93 phaseInputExt Ln          = "o"
94 phaseInputExt MkDependHS  = "dep"
95 phaseInputExt HsBoot      = "hs-boot"
96 #ifdef ILX
97 phaseInputExt Ilx2Il      = "ilx"
98 phaseInputExt Ilasm       = "il"
99 #endif
100
101 haskellish_suffix     = (`elem` [ "hs", "lhs", "hspp", "hscpp", "hcr", "hc", "raw_s" ])
102 haskellish_src_suffix = (`elem` [ "hs", "lhs", "hspp", "hscpp", "hcr"])
103 cish_suffix           = (`elem` [ "c", "cpp", "C", "cc", "cxx", "s", "S" ])
104 hsbootish_suffix      = (`elem` [ "hs-boot" ])
105
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 objish_file         = objish_suffix         . getFileSuffix
116 hsbootish_file      = hsbootish_suffix      . getFileSuffix