cc268cee3b2e2547c2f6f3d2c43cd7c295bbd2fd
[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 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,
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_nm unlinkeds)
57       = (text "LinkableM" <+> parens (text (show when_made)) <+> ppr mod_nm)
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 -- ToDo: shouldn't ms_srcimps and ms_imps be [Module]?  --SDM
76
77 instance Outputable ModSummary where
78    ppr ms
79       = sep [text "ModSummary {",
80              nest 3 (sep [text "ms_hs_date = " <> text (show (ms_hs_date ms)),
81                           text "ms_mod =" <+> ppr (ms_mod ms) <> comma,
82                           text "ms_imps =" <+> ppr (ms_imps ms),
83                           text "ms_srcimps =" <+> ppr (ms_srcimps ms)]),
84              char '}'
85             ]
86
87 pprSummaryTime ms
88    = text "ms_hs_date = " <> parens (text (show (ms_hs_date ms)))
89
90 ms_allimps ms 
91    = ms_srcimps ms ++ ms_imps ms
92
93 name_of_summary :: ModSummary -> ModuleName
94 name_of_summary = moduleName . ms_mod
95 \end{code}