Remove the v_Split_info global variable and use a field of dflags instead
[ghc-hetmet.git] / compiler / main / DriverPipeline.hs
index 818a00c..53ace5c 100644 (file)
@@ -19,7 +19,7 @@ module DriverPipeline (
 
        -- Interfaces for the compilation manager (interpreted/batch-mode)
    preprocess, 
-   compile,
+   compile, compile',
    link, 
 
   ) where
@@ -52,7 +52,7 @@ import MonadUtils
 
 import Data.Either
 import Exception
-import Data.IORef      ( readIORef, writeIORef, IORef )
+import Data.IORef      ( readIORef )
 import GHC.Exts                ( Int(..) )
 import System.Directory
 import System.FilePath
@@ -103,7 +103,26 @@ compile :: GhcMonad m =>
         -> Maybe Linkable  -- ^ old linkable, if we have one
         -> m HomeModInfo   -- ^ the complete HomeModInfo, if successful
 
-compile hsc_env0 summary mod_index nmods mb_old_iface maybe_old_linkable
+compile = compile' (hscCompileNothing, hscCompileInteractive, hscCompileBatch)
+
+type Compiler m a = HscEnv -> ModSummary -> Bool
+                  -> Maybe ModIface -> Maybe (Int, Int)
+                  -> m a
+
+compile' :: GhcMonad m =>
+           (Compiler m (HscStatus, ModIface, ModDetails),
+            Compiler m (InteractiveStatus, ModIface, ModDetails),
+            Compiler m (HscStatus, ModIface, ModDetails))
+        -> HscEnv
+        -> ModSummary      -- ^ summary for module being compiled
+        -> Int             -- ^ module N ...
+        -> Int             -- ^ ... of M
+        -> Maybe ModIface  -- ^ old interface, if we have one
+        -> Maybe Linkable  -- ^ old linkable, if we have one
+        -> m HomeModInfo   -- ^ the complete HomeModInfo, if successful
+
+compile' (nothingCompiler, interactiveCompiler, batchCompiler)
+        hsc_env0 summary mod_index nmods mb_old_iface maybe_old_linkable
  = do
    let dflags0     = ms_hspp_opts summary
        this_mod    = ms_mod summary
@@ -153,7 +172,7 @@ compile hsc_env0 summary mod_index nmods mb_old_iface maybe_old_linkable
            = ASSERT (isJust maybe_old_linkable)
              return maybe_old_linkable
 
-       handleBatch (HscRecomp hasStub)
+       handleBatch (HscRecomp hasStub _)
            | isHsBoot src_flavour
                = do when (isObjectTarget hsc_lang) $ -- interpreted reaches here too
                        liftIO $ SysTools.touch dflags' "Touching object file"
@@ -179,10 +198,13 @@ compile hsc_env0 summary mod_index nmods mb_old_iface maybe_old_linkable
                                   (hs_unlinked ++ stub_unlinked)
                     return (Just linkable)
 
-       handleInterpreted InteractiveNoRecomp
+       handleInterpreted HscNoRecomp
            = ASSERT (isJust maybe_old_linkable)
              return maybe_old_linkable
-       handleInterpreted (InteractiveRecomp hasStub comp_bc modBreaks)
+       handleInterpreted (HscRecomp _hasStub Nothing)
+           = ASSERT (isHsBoot src_flavour)
+             return maybe_old_linkable
+       handleInterpreted (HscRecomp hasStub (Just (comp_bc, modBreaks)))
            = do stub_unlinked <- getStubLinkable hasStub
                 let hs_unlinked = [BCOs comp_bc modBreaks]
                     unlinked_time = ms_hs_date summary
@@ -208,15 +230,13 @@ compile hsc_env0 summary mod_index nmods mb_old_iface maybe_old_linkable
                                      hm_linkable = linkable })
    -- run the compiler
    case hsc_lang of
-      HscInterpreted
-        | isHsBoot src_flavour -> 
-                runCompiler hscCompileNothing handleBatch
-        | otherwise -> 
-                runCompiler hscCompileInteractive handleInterpreted
+      HscInterpreted ->
+                runCompiler interactiveCompiler handleInterpreted
       HscNothing -> 
-                runCompiler hscCompileNothing handleBatch
+                runCompiler nothingCompiler handleBatch
       _other -> 
-                runCompiler hscCompileBatch handleBatch
+                runCompiler batchCompiler handleBatch
+
 
 -----------------------------------------------------------------------------
 -- stub .h and .c files (for foreign export support)
@@ -666,8 +686,8 @@ runPhase (Cpp sf) _stop hsc_env _basename _suff input_fn get_output_fn maybe_loc
        src_opts <- liftIO $ getOptionsFromFile dflags0 input_fn
        (dflags, unhandled_flags, warns)
            <- liftIO $ parseDynamicNoPackageFlags dflags0 src_opts
-       liftIO $ handleFlagWarnings dflags warns  -- XXX: may exit the program
-       liftIO $ checkProcessArgsResult unhandled_flags -- XXX: may throw program error
+       handleFlagWarnings dflags warns
+       checkProcessArgsResult unhandled_flags
 
        if not (dopt Opt_Cpp dflags) then
            -- no need to preprocess CPP, just pass input file along
@@ -726,8 +746,8 @@ runPhase (Hsc src_flavour) stop hsc_env basename suff input_fn get_output_fn _ma
                     m <- liftIO $ getCoreModuleName input_fn
                     return (Nothing, mkModuleName m, [], [])
 
-                _           -> liftIO $ do
-                    buf <- hGetStringBuffer input_fn
+                _           -> do
+                    buf <- liftIO $ hGetStringBuffer input_fn
                     (src_imps,imps,L _ mod_name) <- getImports dflags buf input_fn (basename <.> suff)
                     return (Just buf, mod_name, imps, src_imps)
 
@@ -830,7 +850,7 @@ runPhase (Hsc src_flavour) stop hsc_env basename suff input_fn get_output_fn _ma
                     -- than the source file (else we wouldn't be in HscNoRecomp)
                     -- but we touch it anyway, to keep 'make' happy (we think).
                     return (StopLn, dflags', Just location4, o_file)
-          (HscRecomp hasStub)
+          (HscRecomp hasStub _)
               -> do when hasStub $
                          do stub_o <- compileStub hsc_env' mod location4
                             liftIO $ consIORef v_Ld_inputs stub_o
@@ -1048,13 +1068,13 @@ runPhase SplitMangle _stop hsc_env _basename _suff input_fn _get_output_fn maybe
        -- Save the number of split files for future references
        s <- readFile n_files_fn
        let n_files = read s :: Int
-       writeIORef v_Split_info (split_s_prefix, n_files)
+           dflags' = dflags { splitInfo = Just (split_s_prefix, n_files) }
 
        -- Remember to delete all these files
        addFilesToClean [ split_s_prefix ++ "__" ++ show n ++ ".s"
                        | n <- [1..n_files]]
 
-       return (SplitAs, dflags, maybe_loc, "**splitmangle**")
+       return (SplitAs, dflags', maybe_loc, "**splitmangle**")
          -- we don't use the filename
 
 -----------------------------------------------------------------------------
@@ -1112,7 +1132,9 @@ runPhase SplitAs _stop hsc_env _basename _suff _input_fn get_output_fn maybe_loc
 
         let as_opts = getOpts dflags opt_a
 
-        (split_s_prefix, n) <- readIORef v_Split_info
+        let (split_s_prefix, n) = case splitInfo dflags of
+                                  Nothing -> panic "No split info"
+                                  Just x -> x
 
         let split_s   n = split_s_prefix ++ "__" ++ show n <.> "s"
             split_obj n = split_odir </>
@@ -1188,8 +1210,8 @@ runPhase_MoveBinary dflags input_fn dep_packages
          Wrapped wrapmode ->
              do
                let (o_base, o_ext) = splitExtension input_fn
-               let wrapped_executable | o_ext == "exe" = (o_base ++ "_real") <.> o_ext
-                                      | otherwise = input_fn ++ "_real"
+               let wrapped_executable | o_ext == "exe" = (o_base ++ ".dyn") <.> o_ext
+                                      | otherwise = input_fn ++ ".dyn"
                behaviour <- wrapper_behaviour dflags wrapmode dep_packages
 
                 -- THINKME isn't this possible to do a bit nicer?
@@ -1494,8 +1516,14 @@ linkDynLib dflags o_files dep_packages = do
     -- because the RTS lib comes in several flavours and we want to be
     -- able to pick the flavour when a binary is linked.
     pkgs <- getPreloadPackagesAnd dflags dep_packages
-    let pkgs_no_rts = filter ((/= rtsPackageId) . packageConfigId) pkgs
 
+    -- On Windows we need to link the RTS import lib as Windows does
+    -- not allow undefined symbols.
+#if !defined(mingw32_HOST_OS)
+    let pkgs_no_rts = filter ((/= rtsPackageId) . packageConfigId) pkgs
+#else
+    let pkgs_no_rts = pkgs
+#endif
     let pkg_lib_paths = collectLibraryPaths pkgs_no_rts
     let pkg_lib_path_opts = map ("-L"++) pkg_lib_paths
 
@@ -1700,5 +1728,3 @@ hscMaybeAdjustTarget dflags stop _ current_hsc_lang
                -- otherwise, stick to the plan
                 | otherwise = current_hsc_lang
 
-GLOBAL_VAR(v_Split_info, ("",0), (String,Int))
-       -- The split prefix and number of files