[project @ 2000-10-06 13:07:32 by sewardj]
[ghc-hetmet.git] / ghc / compiler / ghci / CmLink.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1993-2000
3 %
4 \section[CmLink]{Linker for GHCI}
5
6 \begin{code}
7 module CmLink ( Linkable(..), 
8                 filterModuleLinkables, modname_of_linkable,
9                 LinkResult(..),
10                 HValue,
11                 link, 
12                 PLS{-abstractly!-}, emptyPLS )
13                   
14 where
15
16 import CmStaticInfo     ( PCI )
17 import CmFind           ( Path, PkgName )
18 import Module           ( Module )
19 import Outputable       ( SDoc )
20 import FiniteMap        ( FiniteMap, emptyFM )
21 import RdrName          ( RdrName )
22 import Digraph          ( SCC )
23 import Addr             ( Addr )
24 import Panic            ( panic )
25
26 #include "HsVersions.h"
27
28 \end{code}
29
30 \begin{code}
31 data PLS 
32    = MkPLS {
33         source_symtab :: FiniteMap RdrName HValue,
34         object_symtab :: FiniteMap String Addr
35      }
36
37 data HValue = HValue -- fix this ... just temporary?
38
39
40 link :: PCI -> [SCC Linkable] -> PLS -> IO LinkResult
41 link pci linkabless pls
42    = return (error "link:unimp")
43
44 data LinkResult 
45    = LinkOK   PLS
46    | LinkErrs PLS [SDoc]
47
48 data Unlinked
49    = DotO Path
50    | DotA Path
51    | DotDLL Path
52    -- | Trees [StgTree RdrName]
53
54 data Linkable
55    = LM {-should be:Module-} String{- == ModName-} [Unlinked]
56    | LP PkgName
57
58 modname_of_linkable (LM nm _) = nm
59 modname_of_linkable (LP _)    = panic "modname_of_linkable: package"
60
61 filterModuleLinkables :: (String{- ==ModName-} -> Bool) 
62                       -> [Linkable] 
63                       -> [Linkable]
64 filterModuleLinkables p [] = []
65 filterModuleLinkables p (li:lis)
66    = case li of
67         LP _       -> retain
68         LM modnm _ -> if p modnm then retain else dump
69      where
70         dump   = filterModuleLinkables p lis
71         retain = li : dump
72
73 emptyPLS :: IO PLS
74 emptyPLS = return (MkPLS { source_symtab = emptyFM, 
75                            object_symtab = emptyFM })
76 \end{code}