[project @ 2001-03-08 12:07:38 by simonpj]
[ghc-hetmet.git] / ghc / compiler / main / DriverPipeline.hs
index b0f2915..f568672 100644 (file)
@@ -1,5 +1,5 @@
 -----------------------------------------------------------------------------
--- $Id: DriverPipeline.hs,v 1.48 2001/01/16 21:05:51 qrczak Exp $
+-- $Id: DriverPipeline.hs,v 1.53 2001/03/06 15:00:25 rrt Exp $
 --
 -- GHC Driver
 --
@@ -36,6 +36,7 @@ import DriverPhases
 import DriverFlags
 import HscMain
 import TmpFiles
+import Finder
 import HscTypes
 import Outputable
 import Module
@@ -100,7 +101,7 @@ getGhcMode flags
 -- genPipeline
 --
 -- Herein is all the magic about which phases to run in which order, whether
--- the intermediate files should be in /tmp or in the current directory,
+-- the intermediate files should be in TMPDIR or in the current directory,
 -- what the suffix of the intermediate files should be, etc.
 
 -- The following compilation pipeline algorithm is fairly hacky.  A
@@ -184,6 +185,10 @@ genPipeline todo stop_flag persistent_output lang filename
 
        HscJava | split           -> not_valid
                | otherwise       -> error "not implemented: compiling via Java"
+#ifdef ILX
+       HscILX  | split           -> not_valid
+               | otherwise       -> [ Unlit, Cpp, Hsc ]
+#endif
 
       | cish      = [ Cc, As ]
 
@@ -322,7 +327,7 @@ run_phase Cpp basename suff input_fn output_fn
                           ++ ": static flags are not allowed in {-# OPTIONS #-} pragmas:\n\t" 
                           ++ unwords unhandled_flags)) (ExitFailure 1))
 
-       do_cpp <- readState cpp_flag
+       do_cpp <- dynFlag cppFlag
        if do_cpp
           then do
                    cpp <- readIORef v_Pgm_P
@@ -335,6 +340,7 @@ run_phase Cpp basename suff input_fn output_fn
                                                        ++ pkg_include_dirs)
 
            verb <- getVerbFlag
+           (md_c_flags, _) <- machdepCCOpts
 
            runSomething "C pre-processor" 
                (unwords
@@ -343,6 +349,7 @@ run_phase Cpp basename suff input_fn output_fn
                    ++ include_paths
                    ++ hs_src_cpp_opts
                    ++ hscpp_opts
+                   ++ md_c_flags
                    ++ [ "-x", "c", input_fn, ">>", output_fn ]
                   ))
          else do
@@ -459,13 +466,12 @@ run_phase Hsc basename suff input_fn output_fn
                                  then return True
                                  else return False
 
-   -- build a ModuleLocation to pass to hscMain.
-        let location = ModuleLocation {
-                          ml_hs_file   = Nothing,
-                          ml_hspp_file = Just input_fn,
-                          ml_hi_file   = Just hifile,
-                          ml_obj_file  = Just o_file
-                       }
+        -- build a ModuleLocation to pass to hscMain.
+        modsrc <- readFile input_fn
+        let (srcimps,imps,mod_name) = getImports modsrc
+
+       Just (mod, location)
+          <- mkHomeModuleLocn mod_name basename (basename ++ '.':suff)
 
   -- get the DynFlags
         dyn_flags <- readIORef v_DynFlags
@@ -474,8 +480,9 @@ run_phase Hsc basename suff input_fn output_fn
         pcs <- initPersistentCompilerState
        result <- hscMain OneShot
                           dyn_flags{ hscOutName = output_fn }
+                         mod
+                         location{ ml_hspp_file=Just input_fn }
                          source_unchanged
-                         location
                          Nothing        -- no iface
                          emptyModuleEnv -- HomeSymbolTable
                          emptyModuleEnv -- HomeIfaceTable
@@ -525,7 +532,7 @@ run_phase cc_phase _basename _suff input_fn output_fn
                                                        ++ pkg_include_dirs)
 
        c_includes <- getPackageCIncludes
-       cmdline_includes <- readState cmdline_hc_includes -- -#include options
+       cmdline_includes <- dynFlag cmdlineHcIncludes -- -#include options
 
        let cc_injects | hcc = unlines (map mk_include 
                                        (c_includes ++ reverse cmdline_includes))
@@ -588,7 +595,7 @@ run_phase Mangle _basename _suff input_fn output_fn
        mangler_opts <- getOpts opt_m
        machdep_opts <-
         if (prefixMatch "i386" cTARGETPLATFORM)
-           then do n_regs <- readState stolen_x86_regs
+           then do n_regs <- dynFlag stolen_x86_regs
                    return [ show n_regs ]
            else return []
        runSomething "Assembly Mangler"
@@ -811,14 +818,12 @@ doMkDLL o_files = do
 preprocess :: FilePath -> IO FilePath
 preprocess filename =
   ASSERT(haskellish_file filename) 
-  do init_driver_state <- readIORef v_InitDriverState
-     writeIORef v_Driver_state init_driver_state
-
+  do init_dyn_flags <- readIORef v_InitDynFlags
+     writeIORef v_DynFlags init_dyn_flags
      pipeline <- genPipeline (StopBefore Hsc) ("preprocess") False 
                        defaultHscLang filename
      runPipeline pipeline filename False{-no linking-} False{-no -o flag-}
 
-
 -----------------------------------------------------------------------------
 -- Compile a single module, under the control of the compilation manager.
 --
@@ -858,8 +863,6 @@ data CompResult
 compile ghci_mode summary source_unchanged old_iface hst hit pcs = do 
    init_dyn_flags <- readIORef v_InitDynFlags
    writeIORef v_DynFlags init_dyn_flags
-   init_driver_state <- readIORef v_InitDriverState
-   writeIORef v_Driver_state init_driver_state
 
    showPass init_dyn_flags 
        (showSDoc (text "Compiling" <+> ppr (name_of_summary summary)))
@@ -880,12 +883,15 @@ compile ghci_mode summary source_unchanged old_iface hst hit pcs = do
                    HscAsm         -> newTempName (phaseInputExt As)
                    HscC           -> newTempName (phaseInputExt HCc)
                    HscJava        -> newTempName "java" -- ToDo
+#ifdef ILX
+                   HscILX         -> newTempName (phaseInputExt Ilx)
+#endif
                    HscInterpreted -> return (error "no output file")
 
    -- run the compiler
    hsc_result <- hscMain ghci_mode dyn_flags{ hscOutName = output_fn } 
-                        source_unchanged
-                         location old_iface hst hit pcs
+                        (ms_mod summary) location
+                        source_unchanged old_iface hst hit pcs
 
    case hsc_result of
       HscFail pcs -> return (CompErrs pcs)