90123e0c334730842706bbef76021c1bb5b7492f
[ghc-hetmet.git] / ghc / compiler / compMan / CmTypes.lhs
1 %
2 % (c) The University of Glasgow, 2000
3 %
4 \section[CmTypes]{Types for the compilation manager}
5
6 \begin{code}
7 module CmTypes ( 
8    Unlinked(..),  isObject, nameOfObject, isInterpretable,
9    Linkable(..), isObjectLinkable, 
10    ModSummary(..), ms_allimps, pprSummaryTime, modSummaryName,
11   ) where
12
13 import Interpreter
14 import HscTypes
15 import Module
16 import Outputable
17
18 import Time             ( ClockTime )
19
20
21 data Unlinked
22    = DotO FilePath
23    | DotA FilePath
24    | DotDLL FilePath
25    | BCOs [UnlinkedBCO] ItblEnv  -- bunch of interpretable bindings, +
26                                  -- a mapping from DataCons to their itbls
27
28 instance Outputable Unlinked where
29    ppr (DotO path)   = text "DotO" <+> text path
30    ppr (DotA path)   = text "DotA" <+> text path
31    ppr (DotDLL path) = text "DotDLL" <+> text path
32    ppr (BCOs bcos _) = text "BCOs" <+> ppr bcos
33
34 isObject (DotO _) = True
35 isObject (DotA _) = True
36 isObject (DotDLL _) = True
37 isObject _ = False
38
39 nameOfObject (DotO fn)   = fn
40 nameOfObject (DotA fn)   = fn
41 nameOfObject (DotDLL fn) = fn
42
43 isInterpretable (BCOs _ _) = True
44 isInterpretable _          = False
45
46 data Linkable = LM {
47   linkableTime     :: ClockTime,
48   linkableModName  :: ModuleName,       -- should be Module, but see below
49   linkableUnlinked :: [Unlinked]
50  }
51
52 isObjectLinkable :: Linkable -> Bool
53 isObjectLinkable l = all isObject (linkableUnlinked l)
54
55 instance Outputable Linkable where
56    ppr (LM when_made mod unlinkeds)
57       = (text "LinkableM" <+> parens (text (show when_made)) <+> ppr mod)
58         $$ nest 3 (ppr unlinkeds)
59
60 -- The ModuleLocation contains both the original source filename and the
61 -- filename of the cleaned-up source file after all preprocessing has been
62 -- done.  The point is that the summariser will have to cpp/unlit/whatever
63 -- all files anyway, and there's no point in doing this twice -- just 
64 -- park the result in a temp file, put the name of it in the location,
65 -- and let @compile@ read from that file on the way back up.
66 data ModSummary
67    = ModSummary {
68         ms_mod      :: Module,                  -- name, package
69         ms_location :: ModuleLocation,          -- location
70         ms_srcimps  :: [ModuleName],            -- source imports
71         ms_imps     :: [ModuleName],            -- non-source imports
72         ms_hs_date  :: ClockTime                -- timestamp of summarised file
73      }
74
75 instance Outputable ModSummary where
76    ppr ms
77       = sep [text "ModSummary {",
78              nest 3 (sep [text "ms_hs_date = " <> text (show (ms_hs_date ms)),
79                           text "ms_mod =" <+> ppr (ms_mod ms) <> comma,
80                           text "ms_imps =" <+> ppr (ms_imps ms),
81                           text "ms_srcimps =" <+> ppr (ms_srcimps ms)]),
82              char '}'
83             ]
84
85 pprSummaryTime ms
86    = text "ms_hs_date = " <> parens (text (show (ms_hs_date ms)))
87
88 ms_allimps ms 
89    = ms_srcimps ms ++ ms_imps ms
90
91 modSummaryName :: ModSummary -> ModuleName
92 modSummaryName = moduleName . ms_mod
93 \end{code}