2 % (c) The University of Glasgow, 2000
4 \section[CmLink]{Linker for GHCI}
7 module CmLink ( Linkable(..),
9 modname_of_linkable, is_package_linkable,
12 PLS{-abstractly!-}, emptyPLS )
15 import StgInterp ( linkIModules, ClosureEnv, ItblEnv )
18 import CmStaticInfo ( PCI )
19 import CmFind ( Path, PkgName )
20 import InterpSyn ( UnlinkedIBind, HValue, binder )
21 import Module ( Module )
22 import Outputable ( SDoc )
23 import FiniteMap ( FiniteMap, emptyFM )
24 import RdrName ( RdrName )
25 import Digraph ( SCC(..) )
28 import Panic ( panic )
30 #include "HsVersions.h"
36 closure_env :: ClosureEnv,
38 -- notionally here, but really lives in the C part of the linker:
39 -- object_symtab :: FiniteMap String Addr
50 | Trees [UnlinkedIBind] -- bunch of interpretable bindings
52 instance Outputable Unlinked where
53 ppr (DotO path) = text "DotO" <+> text path
54 ppr (DotA path) = text "DotA" <+> text path
55 ppr (DotDLL path) = text "DotDLL" <+> text path
56 ppr (Trees binds) = text "Trees" <+> ppr (map binder binds)
59 isObject (DotO _) = True
60 isObject (DotA _) = True
61 isObject (DotDLL _) = True
64 isInterpretable (Trees _) = True
65 isInterpretable _ = False
68 = LM {-should be:Module-} String{- == ModName-} [Unlinked]
71 instance Outputable Linkable where
72 ppr (LM mod_nm unlinkeds) = text "LinkableM" <+> text mod_nm <+> ppr unlinkeds
73 ppr (LP package_nm) = text "LinkableP" <+> text package_nm
76 emptyPLS = return (MkPLS { closure_env = emptyFM,
81 link :: PCI -> [SCC Linkable] -> PLS -> IO LinkResult
84 --link = panic "CmLink.link: not implemented"
86 = do putStrLn "Hello from the Linker!"
87 putStrLn (showSDoc (vcat (map ppLinkableSCC groups)))
88 putStrLn "Bye-bye from the Linker!"
91 ppLinkableSCC :: SCC Linkable -> SDoc
92 ppLinkableSCC (CyclicSCC xs) = ppr xs
93 ppLinkableSCC (AcyclicSCC x) = ppr [x]
97 link pci [] pls = return (LinkOK pls)
98 link pci (group:groups) pls = do
99 -- the group is either all objects or all interpretable, for now
100 if all isObject group
101 then do mapM loadObj [ file | DotO file <- group ]
104 else if all isInterpretable group
105 then do (new_closure_env, new_itbl_env) <-
106 linkIModules (closure_env pls)
108 [ trees | Trees trees <- group ]
109 link pci groups MkPLS{closure_env=new_closure_env,
110 itbl_env=new_itbl_env}
112 return (LinkErrs pls (ptext SLIT("linker: group must contain all objects or all interpreted modules")))
115 modname_of_linkable (LM nm _) = nm
116 modname_of_linkable (LP _) = panic "modname_of_linkable: package"
118 is_package_linkable (LP _) = True
119 is_package_linkable (LM _ _) = False
121 filterModuleLinkables :: (String{- ==ModName-} -> Bool)
124 filterModuleLinkables p [] = []
125 filterModuleLinkables p (li:lis)
128 LM modnm _ -> if p modnm then retain else dump
130 dump = filterModuleLinkables p lis