[project @ 2001-08-15 09:32:40 by rrt]
[ghc-hetmet.git] / ghc / compiler / main / DriverPhases.hs
1 -----------------------------------------------------------------------------
2 -- $Id: DriverPhases.hs,v 1.12 2001/08/15 09:32:40 rrt Exp $
3 --
4 -- GHC Driver
5 --
6 -- (c) Simon Marlow 2000
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    objish_file, objish_suffix,
20    cish_file, cish_suffix
21  ) where
22
23 import DriverUtil
24
25 -----------------------------------------------------------------------------
26 -- Phases
27
28 {-
29    Phase of the           | Suffix saying | Flag saying   | (suffix of)
30    compilation system     | ``start here''| ``stop after''| output file
31    
32    literate pre-processor | .lhs          | -             | -
33    C pre-processor (opt.) | -             | -E            | -
34    Haskell compiler       | .hs           | -C, -S        | .hc, .s
35    C compiler (opt.)      | .hc or .c     | -S            | .s
36    assembler              | .s  or .S     | -c            | .o
37    linker                 | other         | -             | a.out
38 -}
39
40 data Phase 
41         = MkDependHS    -- haskell dependency generation
42         | Unlit
43         | Cpp
44         | Hsc -- ToDo: HscTargetLang
45         | Cc
46         | HCc           -- Haskellised C (as opposed to vanilla C) compilation
47         | Mangle        -- assembly mangling, now done by a separate script.
48         | SplitMangle   -- after mangler if splitting
49         | SplitAs
50         | As
51         | Ln
52 #ifdef ILX
53         | Ilx2Il
54         | Ilasm
55 #endif
56   deriving (Eq, Show)
57
58 -- the first compilation phase for a given file is determined
59 -- by its suffix.
60 startPhase "lhs"   = Unlit
61 startPhase "hs"    = Cpp
62 startPhase "hspp"  = Hsc
63 startPhase "hc"    = HCc
64 startPhase "c"     = Cc
65 startPhase "raw_s" = Mangle
66 startPhase "s"     = As
67 startPhase "S"     = As
68 startPhase "o"     = Ln
69 startPhase _       = Ln    -- all unknown file types
70
71 -- the output suffix for a given phase is uniquely determined by
72 -- the input requirements of the next phase.
73 phaseInputExt Unlit       = "lhs"
74 phaseInputExt Cpp         = "lpp"       -- intermediate only
75 phaseInputExt Hsc         = "hspp"
76 phaseInputExt HCc         = "hc"
77 phaseInputExt Cc          = "c"
78 phaseInputExt Mangle      = "raw_s"
79 phaseInputExt SplitMangle = "split_s"   -- not really generated
80 phaseInputExt As          = "s"
81 phaseInputExt SplitAs     = "split_s"   -- not really generated
82 phaseInputExt Ln          = "o"
83 phaseInputExt MkDependHS  = "dep"
84 #ifdef ILX
85 phaseInputExt Ilx2Il      = "ilx"
86 phaseInputExt Ilasm       = "il"
87 #endif
88
89 haskellish_suffix     = (`elem` [ "hs", "hspp", "lhs", "hc", "raw_s" ])
90 haskellish_src_suffix = (`elem` [ "hs", "hspp", "lhs" ])
91 cish_suffix           = (`elem` [ "c", "s", "S" ])  -- maybe .cc et al.??
92
93 #if mingw32_TARGET_OS || cygwin32_TARGET_OS
94 objish_suffix     = (`elem` [ "o", "O", "obj", "OBJ" ])
95 #else
96 objish_suffix     = (`elem` [ "o" ])
97 #endif
98
99 haskellish_file     = haskellish_suffix     . getFileSuffix
100 haskellish_src_file = haskellish_src_suffix . getFileSuffix
101 cish_file           = cish_suffix           . getFileSuffix
102 objish_file         = objish_suffix         . getFileSuffix