[project @ 2000-10-24 15:55:35 by simonpj]
[ghc-hetmet.git] / ghc / compiler / main / Finder.lhs
index 8408501..d0de38f 100644 (file)
@@ -7,11 +7,13 @@
 module Finder (
     Finder,            -- =  ModuleName -> IO (Maybe (Module, ModuleLocation))
     newFinder,                 -- :: PackageConfigInfo -> IO Finder, 
-    ModuleLocation(..)
+    ModuleLocation(..),
+    mkHomeModuleLocn
   ) where
 
 #include "HsVersions.h"
 
+import HscTypes                ( Finder, ModuleLocation(..) )
 import CmStaticInfo
 import DriverPhases
 import DriverState
@@ -27,15 +29,12 @@ import IO
 import Monad
 \end{code}
 
-\begin{code}
-type Finder = ModuleName -> IO (Maybe (Module, ModuleLocation))
+The Finder provides a thin filesystem abstraction to the rest of the
+compiler.  For a given module, it knows (a) which package the module
+lives in, so it can make a Module from a ModuleName, and (b) where the
+source, interface, and object files for a module live.
 
-data ModuleLocation
-   = ModuleLocation {
-       hs_file  :: FilePath,
-       hi_file  :: FilePath,
-       obj_file :: FilePath
-      }
+\begin{code}
 
 -- caches contents of package directories, never expunged
 GLOBAL_VAR(pkgDirCache,    Nothing,  Maybe (FiniteMap String (PackageName, FilePath)))
@@ -103,28 +102,28 @@ maybeHomeModule mod_name = do
        lhs = basename ++ ".lhs"
 
    case lookupFM home_cache hs of {
-       Just path -> mkHomeModuleLocn mod_name basename path hs;
+       Just path -> mkHomeModuleLocn mod_name (path ++ '/':basename) hs;
        Nothing ->
 
    case lookupFM home_cache lhs of {
-       Just path ->  mkHomeModuleLocn mod_name basename path lhs;
+       Just path ->  mkHomeModuleLocn mod_name (path ++ '/':basename) lhs;
        Nothing -> return Nothing
 
    }}
 
-mkHomeModuleLocn mod_name basename path source_fn = do
+mkHomeModuleLocn mod_name basename source_fn = do
 
    -- figure out the .hi file name: it lives in the same dir as the
    -- source, unless there's a -ohi flag on the command line.
    ohi    <- readIORef output_hi
    hisuf  <- readIORef hi_suf
    let hifile = case ohi of
-                  Nothing -> path ++ '/':basename ++ hisuf
+                  Nothing -> basename ++ hisuf
                   Just fn -> fn
 
    -- figure out the .o file name.  It also lives in the same dir
    -- as the source, but can be overriden by a -odir flag.
-   o_file <- odir_ify (path ++ '/':basename ++ '.':phaseInputExt Ln)
+   o_file <- odir_ify (basename ++ '.':phaseInputExt Ln)
 
    return (Just (mkHomeModule mod_name,
                  ModuleLocation{