[project @ 2001-10-01 14:01:42 by rrt]
[ghc-hetmet.git] / ghc / compiler / main / DriverPipeline.hs
index e0dc7ee..2e5902b 100644 (file)
@@ -1,5 +1,4 @@
 -----------------------------------------------------------------------------
--- $Id: DriverPipeline.hs,v 1.100 2001/08/16 14:43:59 rrt Exp $
 --
 -- GHC Driver
 --
@@ -136,6 +135,7 @@ genPipeline todo stop_flag persistent_output lang (filename,suffix)
    split      <- readIORef v_Split_object_files
    mangle     <- readIORef v_Do_asm_mangling
    keep_hc    <- readIORef v_Keep_hc_files
+   keep_il    <- readIORef v_Keep_il_files
    keep_raw_s <- readIORef v_Keep_raw_s_files
    keep_s     <- readIORef v_Keep_s_files
    osuf       <- readIORef v_Object_suf
@@ -178,6 +178,7 @@ genPipeline todo stop_flag persistent_output lang (filename,suffix)
        HscILX  | split           -> not_valid
                | otherwise       -> [ Unlit, Cpp, Hsc, Ilx2Il, Ilasm ]
 #endif
+       HscNothing                -> [ Unlit, Cpp, Hsc ]
 
       | cish      = [ Cc, As ]
 
@@ -188,6 +189,7 @@ genPipeline todo stop_flag persistent_output lang (filename,suffix)
 
     stop_phase = case todo of 
                        StopBefore As | split -> SplitAs
+                                      | real_lang == HscILX -> Ilasm
                        StopBefore phase      -> phase
                        DoMkDependHS          -> Ln
                        DoLink                -> Ln
@@ -235,6 +237,7 @@ genPipeline todo stop_flag persistent_output lang (filename,suffix)
                             Mangle | keep_raw_s -> Persistent
                             As     | keep_s     -> Persistent
                             HCc    | keep_hc    -> Persistent
+                            Ilasm  | keep_il    -> Persistent
                             _other              -> Temporary
 
        -- add information about output files to the pipeline
@@ -266,7 +269,7 @@ runPipeline pipeline (input_fn,suffix) do_linking use_ofile
   where (basename, _) = splitFilename input_fn
 
 pipeLoop [] input_fn _ _ _ _ = return input_fn
-pipeLoop ((phase, keep, o_suffix):phases) 
+pipeLoop (all_phases@((phase, keep, o_suffix):phases))
        (input_fn,real_suff) do_linking use_ofile orig_basename orig_suffix
   = do
 
@@ -277,7 +280,7 @@ pipeLoop ((phase, keep, o_suffix):phases)
        -- checker has determined that recompilation isn't necessary.
      case mbCarryOn of
        Nothing -> do
-             let (_,keep,final_suffix) = last phases
+             let (_,keep,final_suffix) = last all_phases
              ofile <- outputFileName True keep final_suffix
              return (ofile, final_suffix)
           -- carry on ...
@@ -332,8 +335,8 @@ run_phase Unlit _basename _suff input_fn output_fn
        SysTools.runUnlit (map SysTools.Option unlit_flags ++
                                  [ SysTools.Option     "-h"
                          , SysTools.Option     input_fn
-                         , SysTools.FileOption input_fn
-                         , SysTools.FileOption output_fn
+                         , SysTools.FileOption "" input_fn
+                         , SysTools.FileOption "" output_fn
                          ])
        return (Just output_fn)
 
@@ -369,9 +372,9 @@ run_phase Cpp basename suff input_fn output_fn
                            ++ map SysTools.Option md_c_flags
                            ++ [ SysTools.Option     "-x"
                               , SysTools.Option     "c"
-                              , SysTools.FileOption input_fn
+                              , SysTools.FileOption "" input_fn
                               , SysTools.Option     "-o"
-                              , SysTools.FileOption output_fn
+                              , SysTools.FileOption "" output_fn
                               ])
            return (Just output_fn)
 
@@ -471,7 +474,7 @@ run_phase Hsc basename suff input_fn output_fn
 
   -- build a ModuleLocation to pass to hscMain.
        (mod, location')
-          <- mkHomeModuleLocn mod_name basename (Just (basename ++ '.':suff))
+          <- mkHomeModuleLocn mod_name basename (basename ++ '.':suff)
 
   -- take -ohi into account if present
        ohi <- readIORef v_Output_hi
@@ -512,7 +515,7 @@ run_phase Hsc basename suff input_fn output_fn
         let dyn_flags' = dyn_flags { hscOutName = output_fn,
                                     hscStubCOutName = basename ++ "_stub.c",
                                     hscStubHOutName = basename ++ "_stub.h",
-                                    extCoreName = basename ++ ".core" }
+                                    extCoreName = basename ++ ".hcr" }
 
   -- run the compiler!
         pcs <- initPersistentCompilerState
@@ -536,13 +539,14 @@ run_phase Hsc basename suff input_fn output_fn
            HscRecomp pcs details iface stub_h_exists stub_c_exists
                      _maybe_interpreted_code -> do
 
-           -- deal with stubs
-       maybe_stub_o <- compileStub dyn_flags' stub_c_exists
-       case maybe_stub_o of
-               Nothing -> return ()
-               Just stub_o -> add v_Ld_inputs stub_o
-
-       return (Just output_fn)
+                           -- deal with stubs
+                           maybe_stub_o <- compileStub dyn_flags' stub_c_exists
+                           case maybe_stub_o of
+                             Nothing -> return ()
+                             Just stub_o -> add v_Ld_inputs stub_o
+                           case hscLang dyn_flags of
+                              HscNothing -> return Nothing
+                             _ -> return (Just output_fn)
     }
 
 -----------------------------------------------------------------------------
@@ -582,9 +586,9 @@ run_phase cc_phase basename suff input_fn output_fn
 
        excessPrecision <- readIORef v_Excess_precision
        SysTools.runCc ([ SysTools.Option "-x", SysTools.Option "c"
-                       , SysTools.FileOption input_fn
+                       , SysTools.FileOption "" input_fn
                        , SysTools.Option "-o"
-                       , SysTools.FileOption output_fn
+                       , SysTools.FileOption "" output_fn
                        ]
                       ++ map SysTools.Option (
                          md_c_flags
@@ -614,8 +618,8 @@ run_phase Mangle _basename _suff input_fn output_fn
                       else return []
 
        SysTools.runMangle (map SysTools.Option mangler_opts
-                         ++ [ SysTools.FileOption input_fn
-                            , SysTools.FileOption output_fn
+                         ++ [ SysTools.FileOption "" input_fn
+                            , SysTools.FileOption "" output_fn
                             ]
                          ++ map SysTools.Option machdep_opts)
        return (Just output_fn)
@@ -629,9 +633,9 @@ run_phase SplitMangle _basename _suff input_fn output_fn
        split_s_prefix <- SysTools.newTempName "split"
        let n_files_fn = split_s_prefix
 
-       SysTools.runSplit [ SysTools.FileOption input_fn
-                         , SysTools.FileOption split_s_prefix
-                         , SysTools.FileOption n_files_fn
+       SysTools.runSplit [ SysTools.FileOption "" input_fn
+                         , SysTools.FileOption "" split_s_prefix
+                         , SysTools.FileOption "" n_files_fn
                          ]
 
        -- Save the number of split files for future references
@@ -655,9 +659,9 @@ run_phase As _basename _suff input_fn output_fn
        SysTools.runAs (map SysTools.Option as_opts
                       ++ [ SysTools.Option ("-I" ++ p) | p <- cmdline_include_paths ]
                       ++ [ SysTools.Option "-c"
-                         , SysTools.FileOption input_fn
+                         , SysTools.FileOption "" input_fn
                          , SysTools.Option "-o"
-                         , SysTools.FileOption output_fn
+                         , SysTools.FileOption "" output_fn
                          ])
        return (Just output_fn)
 
@@ -679,8 +683,8 @@ run_phase SplitAs basename _suff _input_fn output_fn
                    SysTools.runAs (map SysTools.Option as_opts ++
                                    [ SysTools.Option "-c"
                                    , SysTools.Option "-o"
-                                   , SysTools.FileOption real_o
-                                   , SysTools.FileOption input_s
+                                   , SysTools.FileOption "" real_o
+                                   , SysTools.FileOption "" input_s
                                    ])
        
        mapM_ assemble_file [1..n]
@@ -697,8 +701,8 @@ run_phase Ilx2Il _basename _suff input_fn output_fn
                            ++ [ SysTools.Option "--no-add-suffix-to-assembly",
                                SysTools.Option "mscorlib",
                                SysTools.Option "-o",
-                               SysTools.FileOption output_fn,
-                               SysTools.FileOption input_fn ])
+                               SysTools.FileOption "" output_fn,
+                               SysTools.FileOption "" input_fn ])
        return (Just output_fn)
 
 -----------------------------------------------------------------------------
@@ -710,8 +714,8 @@ run_phase Ilasm _basename _suff input_fn output_fn
         SysTools.runIlasm (map SysTools.Option ilasm_opts
                           ++ [ SysTools.Option "/QUIET",
                                SysTools.Option "/DLL",
-                               SysTools.Option ("/OUT="++output_fn),
-                               SysTools.FileOption input_fn ])
+                               SysTools.FileOption "/OUT=" output_fn,
+                               SysTools.FileOption "" input_fn ])
        return (Just output_fn)
 
 #endif -- ILX
@@ -853,7 +857,7 @@ doLink o_files = do
     (md_c_flags, _) <- machdepCCOpts
     SysTools.runLink ( [ SysTools.Option verb
                       , SysTools.Option "-o"
-                      , SysTools.FileOption output_fn
+                      , SysTools.FileOption "" output_fn
                       ]
                      ++ map SysTools.Option (
                         md_c_flags
@@ -867,13 +871,8 @@ doLink o_files = do
                      ++ pkg_extra_ld_opts
                      ++ extra_ld_opts
                      ++ if static && not no_hs_main then
-#ifdef LEADING_UNDERSCORE
-                           [ "-u", "_PrelMain_mainIO_closure" ,
-                             "-u", "___init_PrelMain"] 
-#else
-                           [ "-u", prefixUnderscore "PrelMain_mainIO_closure" ,
-                             "-u", prefixUnderscore "__init_PrelMain"] 
-#endif
+                           [ "-u", prefixUnderscore "PrelMain_mainIO_closure",
+                             "-u", prefixUnderscore "__stginit_PrelMain"] 
                         else []))
 
     -- parallel only: move binary to another dir -- HWL
@@ -929,7 +928,7 @@ doMkDLL o_files = do
     SysTools.runMkDLL
         ([ SysTools.Option verb
          , SysTools.Option "-o"
-         , SysTools.FileOption output_fn
+         , SysTools.FileOption "" output_fn
          ]
         ++ map SysTools.Option (
            md_c_flags
@@ -1022,6 +1021,7 @@ compile ghci_mode summary source_unchanged have_object
        (basename, _) = splitFilename input_fn
        
    keep_hc <- readIORef v_Keep_hc_files
+   keep_il <- readIORef v_Keep_il_files
    keep_s  <- readIORef v_Keep_s_files
 
    output_fn <- 
@@ -1032,14 +1032,16 @@ compile ghci_mode summary source_unchanged have_object
                   | otherwise -> newTempName (phaseInputExt HCc)
            HscJava             -> newTempName "java" -- ToDo
 #ifdef ILX
-          HscILX              -> return (phaseInputExt Ilx2Il)         
+          HscILX  | keep_il   -> return (basename ++ '.':phaseInputExt Ilasm)
+                   | otherwise -> newTempName (phaseInputExt Ilx2Il)   
 #endif
           HscInterpreted      -> return (error "no output file")
+           HscNothing         -> return (error "no output file")
 
    let dyn_flags' = dyn_flags { hscOutName = output_fn,
                                hscStubCOutName = basename ++ "_stub.c",
                                hscStubHOutName = basename ++ "_stub.h",
-                               extCoreName = basename ++ ".core" }
+                               extCoreName = basename ++ ".hcr" }
 
    -- figure out which header files to #include in a generated .hc file
    c_includes <- getPackageCIncludes
@@ -1055,10 +1057,14 @@ compile ghci_mode summary source_unchanged have_object
 
    writeIORef v_HCHeader cc_injects
 
+   -- -no-recomp should also work with --make
+   do_recomp <- readIORef v_Recomp
+   let source_unchanged' = source_unchanged && do_recomp
+
    -- run the compiler
    hsc_result <- hscMain ghci_mode dyn_flags'
                         (ms_mod summary) location
-                        source_unchanged have_object old_iface hst hit pcs
+                        source_unchanged' have_object old_iface hst hit pcs
 
    case hsc_result of
       HscFail pcs -> return (CompErrs pcs)