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