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