[project @ 2001-02-07 16:12:47 by simonmar]
[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, name_of_summary, pprSummaryTime
11   ) where
12
13 import Interpreter
14 import HscTypes
15 import Module
16 --import CmStaticInfo
17 import Outputable
18
19 import Time             ( ClockTime )
20
21
22 data Unlinked
23    = DotO FilePath
24    | DotA FilePath
25    | DotDLL FilePath
26    | BCOs [UnlinkedBCO] ItblEnv  -- bunch of interpretable bindings, +
27                                  -- a mapping from DataCons to their itbls
28
29 instance Outputable Unlinked where
30    ppr (DotO path)   = text "DotO" <+> text path
31    ppr (DotA path)   = text "DotA" <+> text path
32    ppr (DotDLL path) = text "DotDLL" <+> text path
33    ppr (BCOs bcos _) = text "BCOs" <+> vcat (map ppr bcos)
34
35 isObject (DotO _) = True
36 isObject (DotA _) = True
37 isObject (DotDLL _) = True
38 isObject _ = False
39
40 nameOfObject (DotO fn)   = fn
41 nameOfObject (DotA fn)   = fn
42 nameOfObject (DotDLL fn) = fn
43
44 isInterpretable (BCOs _ _) = True
45 isInterpretable _          = False
46
47 data Linkable = LM {
48   linkableTime :: ClockTime,
49   linkableModName ::  ModuleName,
50   linkableUnlinked ::  [Unlinked]
51  }
52
53 isObjectLinkable :: Linkable -> Bool
54 isObjectLinkable l = all isObject (linkableUnlinked l)
55
56 instance Outputable Linkable where
57    ppr (LM when_made mod_nm unlinkeds)
58       = text "LinkableM" <+> parens (text (show when_made)) <+> ppr mod_nm 
59                          <+> ppr unlinkeds
60
61 -- The ModuleLocation contains both the original source filename and the
62 -- filename of the cleaned-up source file after all preprocessing has been
63 -- done.  The point is that the summariser will have to cpp/unlit/whatever
64 -- all files anyway, and there's no point in doing this twice -- just 
65 -- park the result in a temp file, put the name of it in the location,
66 -- and let @compile@ read from that file on the way back up.
67 data ModSummary
68    = ModSummary {
69         ms_mod      :: Module,               -- name, package
70         ms_location :: ModuleLocation,       -- location
71         ms_srcimps  :: [ModuleName],         -- source imports
72         ms_imps     :: [ModuleName],         -- non-source imports
73         ms_hs_date  :: Maybe ClockTime       -- timestamp of summarised
74                                              -- file, if home && source
75      }
76
77 -- ToDo: shouldn't ms_srcimps and ms_imps be [Module]?  --SDM
78
79 instance Outputable ModSummary where
80    ppr ms
81       = sep [text "ModSummary {",
82              nest 3 (sep [text "ms_hs_date = " <> text (show (ms_hs_date ms)),
83                           text "ms_mod =" <+> ppr (ms_mod ms) <> comma,
84                           text "ms_imps =" <+> ppr (ms_imps ms),
85                           text "ms_srcimps =" <+> ppr (ms_srcimps ms)]),
86              char '}'
87             ]
88
89 pprSummaryTime ms
90    = text "ms_hs_date = " <> parens (text (show (ms_hs_date ms)))
91
92 ms_allimps ms 
93    = ms_srcimps ms ++ ms_imps ms
94
95 name_of_summary :: ModSummary -> ModuleName
96 name_of_summary = moduleName . ms_mod
97 \end{code}