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 )
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 isObject (DotO _) = True
53 isObject (DotA _) = True
54 isObject (DotDLL _) = True
57 isInterpretable (Trees _) = True
58 isInterpretable _ = False
61 = LM {-should be:Module-} String{- == ModName-} [Unlinked]
65 emptyPLS = return (MkPLS { closure_env = emptyFM,
70 link :: PCI -> [SCC Linkable] -> PLS -> IO LinkResult
73 link = panic "CmLink.link: not implemented"
75 link pci [] pls = return (LinkOK pls)
76 link pci (group:groups) pls = do
77 -- the group is either all objects or all interpretable, for now
79 then do mapM loadObj [ file | DotO file <- group ]
82 else if all isInterpretable group
83 then do (new_closure_env, new_itbl_env) <-
84 linkIModules (closure_env pls)
86 [ trees | Trees trees <- group ]
87 link pci groups MkPLS{closure_env=new_closure_env,
88 itbl_env=new_itbl_env}
90 return (LinkErrs pls (ptext SLIT("linker: group must contain all objects or all interpreted modules")))
93 modname_of_linkable (LM nm _) = nm
94 modname_of_linkable (LP _) = panic "modname_of_linkable: package"
96 is_package_linkable (LP _) = True
97 is_package_linkable (LM _ _) = False
99 filterModuleLinkables :: (String{- ==ModName-} -> Bool)
102 filterModuleLinkables p [] = []
103 filterModuleLinkables p (li:lis)
106 LM modnm _ -> if p modnm then retain else dump
108 dump = filterModuleLinkables p lis