[project @ 2005-03-28 22:03:33 by wolfgang]
[ghc-hetmet.git] / ghc / compiler / ghci / Linker.lhs
index d87c2bb..4ebbc8b 100644 (file)
@@ -1,5 +1,5 @@
 %
-% (c) The University of Glasgow 2000
+% (c) The University of Glasgow 2005
 %
 
 -- --------------------------------------
@@ -30,18 +30,19 @@ import ByteCodeAsm  ( CompiledByteCode(..), bcoFreeNames, UnlinkedBCO(..))
 import Packages
 import DriverPhases    ( isObjectFilename, isDynLibFilename )
 import Util            ( getFileSuffix )
-import Finder          ( findModule, findLinkable, FindResult(..) )
+import Finder          ( findModule, findObjectLinkableMaybe, FindResult(..) )
 import HscTypes
 import Name            ( Name, nameModule, isExternalName, isWiredInName )
 import NameEnv
 import NameSet         ( nameSetToList )
 import Module
 import ListSetOps      ( minusList )
-import DynFlags        ( DynFlags(..) )
+import DynFlags                ( DynFlags(..), getOpts )
 import BasicTypes      ( SuccessFlag(..), succeeded, failed )
 import Outputable
 import Panic            ( GhcException(..) )
 import Util             ( zipLazy, global )
+import StaticFlags     ( v_Ld_inputs )
 
 -- Standard libraries
 import Control.Monad   ( when, filterM, foldM )
@@ -53,6 +54,7 @@ import System.IO      ( putStr, putStrLn, hPutStrLn, stderr, fixIO )
 import System.Directory        ( doesFileExist )
 
 import Control.Exception ( block, throwDyn )
+import Maybe           ( isJust, fromJust )
 
 #if __GLASGOW_HASKELL__ >= 503
 import GHC.IOBase      ( IO(..) )
@@ -202,19 +204,19 @@ reallyInitDynLinker dflags
        ; linkPackages dflags (explicitPackages (pkgState dflags))
 
                -- (c) Link libraries from the command-line
-       ; opt_l  <- getStaticOpts v_Opt_l
-       ; let minus_ls = [ lib | '-':'l':lib <- opt_l ]
+       ; let optl = getOpts dflags opt_l
+       ; let minus_ls = [ lib | '-':'l':lib <- optl ]
 
                -- (d) Link .o files from the command-line
-       ; lib_paths <- readIORef v_Library_paths
+       ; let lib_paths = libraryPaths dflags
        ; cmdline_ld_inputs <- readIORef v_Ld_inputs
 
        ; classified_ld_inputs <- mapM classifyLdInput cmdline_ld_inputs
 
                -- (e) Link any MacOS frameworks
 #ifdef darwin_TARGET_OS        
-       ; framework_paths <- readIORef v_Framework_paths
-       ; frameworks      <- readIORef v_Cmdline_frameworks
+       ; let framework_paths = frameworkPaths dflags
+       ; let frameworks      = cmdlineFrameworks dflags
 #else
        ; let frameworks      = []
        ; let framework_paths = []
@@ -314,7 +316,7 @@ linkExpr hsc_env root_ul_bco
 
        -- Find what packages and linkables are required
    ; eps <- readIORef (hsc_EPS hsc_env)
-   ; (lnks, pkgs) <- getLinkDeps dflags hpt (eps_PIT eps) needed_mods
+   ; (lnks, pkgs) <- getLinkDeps hsc_env hpt (eps_PIT eps) needed_mods
 
        -- Link the packages and modules required
    ; linkPackages dflags pkgs
@@ -349,12 +351,12 @@ linkExpr hsc_env root_ul_bco
  
 dieWith msg = throwDyn (ProgramError (showSDoc msg))
 
-getLinkDeps :: DynFlags -> HomePackageTable -> PackageIfaceTable
+getLinkDeps :: HscEnv -> HomePackageTable -> PackageIfaceTable
            -> [Module]                         -- If you need these
            -> IO ([Linkable], [PackageId])     -- ... then link these first
 -- Fails with an IO exception if it can't find enough files
 
-getLinkDeps dflags hpt pit mods
+getLinkDeps hsc_env hpt pit mods
 -- Find all the packages and linkables that a set of modules depends on
  = do {        pls <- readIORef v_PersistentLinkerState ;
        let {
@@ -399,11 +401,12 @@ getLinkDeps dflags hpt pit mods
 
     get_linkable mod_name      -- A home-package module
        | Just mod_info <- lookupModuleEnv hpt mod_name 
-       = return (hm_linkable mod_info)
+       = ASSERT(isJust (hm_linkable mod_info))
+         return (fromJust (hm_linkable mod_info))
        | otherwise     
        =       -- It's not in the HPT because we are in one shot mode, 
                -- so use the Finder to get a ModLocation...
-         do { mb_stuff <- findModule dflags mod_name False ;
+         do { mb_stuff <- findModule hsc_env mod_name False ;
               case mb_stuff of {
                  Found loc _ -> found loc mod_name ;
                  _ -> no_obj mod_name
@@ -411,7 +414,7 @@ getLinkDeps dflags hpt pit mods
 
     found loc mod_name = do {
                -- ...and then find the linkable for it
-              mb_lnk <- findLinkable mod_name loc ;
+              mb_lnk <- findObjectLinkableMaybe mod_name loc ;
               case mb_lnk of {
                  Nothing -> no_obj mod_name ;
                  Just lnk -> return lnk