[project @ 2001-03-28 11:01:19 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / DriverPipeline.hs
index d281c95..1e4705f 100644 (file)
@@ -1,5 +1,5 @@
 -----------------------------------------------------------------------------
--- $Id: DriverPipeline.hs,v 1.58 2001/03/23 17:04:56 simonmar Exp $
+-- $Id: DriverPipeline.hs,v 1.61 2001/03/28 11:01:19 simonmar Exp $
 --
 -- GHC Driver
 --
@@ -94,7 +94,7 @@ getGhcMode flags
        ([]   , rest) -> return (rest, DoLink,  "") -- default is to do linking
        ([(flag,one)], rest) -> return (rest, one, flag)
        (_    , _   ) -> 
-         throwDyn (OtherError 
+         throwDyn (UsageError 
                "only one of the flags -M, -E, -C, -S, -c, --make, --interactive, -mk-dll is allowed")
 
 -----------------------------------------------------------------------------
@@ -148,6 +148,9 @@ genPipeline todo stop_flag persistent_output lang filename
    keep_hc    <- readIORef v_Keep_hc_files
    keep_raw_s <- readIORef v_Keep_raw_s_files
    keep_s     <- readIORef v_Keep_s_files
+#ifdef ILX
+   writeIORef v_Object_suf (Just "ilx")
+#endif
    osuf       <- readIORef v_Object_suf
 
    let
@@ -196,13 +199,13 @@ genPipeline todo stop_flag persistent_output lang filename
 
        -- ToDo: this is somewhat cryptic
 
-    not_valid = throwDyn (OtherError ("invalid option combination"))
+    not_valid = throwDyn (UsageError ("invalid option combination"))
    ----------- -----  ----   ---   --   --  -  -  -
 
        -- this shouldn't happen.
    if start_phase /= Ln && start_phase `notElem` pipeline
-       then throwDyn (OtherError ("can't find starting phase for "
-                                   ++ filename))
+       then throwDyn (CmdLineError ("can't find starting phase for "
+                                    ++ filename))
        else do
 
    let
@@ -253,7 +256,7 @@ genPipeline todo stop_flag persistent_output lang filename
        -- is already in linkable form (for example).
    if start_phase `elem` pipeline && 
        (stop_phase /= Ln && stop_phase `notElem` pipeline)
-      then throwDyn (OtherError 
+      then throwDyn (UsageError 
                ("flag " ++ stop_flag
                 ++ " is incompatible with source file `" ++ filename ++ "'"))
       else do
@@ -363,8 +366,8 @@ run_phase MkDependHS basename suff input_fn _output_fn = do
    src <- readFile input_fn
    let (import_sources, import_normals, module_name) = getImports src
 
-   deps_sources <- mapM (findDependency True basename)  import_sources
-   deps_normals <- mapM (findDependency False basename) import_normals
+   deps_sources <- mapM (findDependency True  src)  import_sources
+   deps_normals <- mapM (findDependency False src) import_normals
    let deps = deps_sources ++ deps_normals
 
    osuf_opt <- readIORef v_Object_suf
@@ -487,11 +490,14 @@ run_phase Hsc basename suff input_fn output_fn
   -- get the DynFlags
         dyn_flags <- readIORef v_DynFlags
 
+        let dyn_flags' = dyn_flags { hscOutName = output_fn,
+                                    hscStubCOutName = basename ++ "_stub.c",
+                                    hscStubHOutName = basename ++ "_stub.h" }
+
   -- run the compiler!
         pcs <- initPersistentCompilerState
        result <- hscMain OneShot
-                          dyn_flags{ hscOutName = output_fn }
-                         mod
+                          dyn_flags' mod
                          location{ ml_hspp_file=Just input_fn }
                          source_unchanged
                          False
@@ -510,11 +516,11 @@ run_phase Hsc basename suff input_fn output_fn
                  return False;
                };
 
-           HscRecomp pcs details iface maybe_stub_h maybe_stub_c 
+           HscRecomp pcs details iface stub_h_exists stub_c_exists
                      _maybe_interpreted_code -> do
 
            -- deal with stubs
-       maybe_stub_o <- dealWithStubs basename maybe_stub_h maybe_stub_c
+       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
@@ -756,7 +762,7 @@ mk_pvm_wrapper_script pvm_executable pvm_executable_base sysMan = unlines $
 -- Complain about non-dynamic flags in OPTIONS pragmas
 
 checkProcessArgsResult flags basename suff
-  = do when (not (null flags)) (throwDyn (OtherError (
+  = do when (not (null flags)) (throwDyn (UserError (
            basename ++ "." ++ suff 
            ++ ": static flags are not allowed in {-# OPTIONS #-} pragmas:\n\t" 
            ++ unwords flags)) (ExitFailure 1))
@@ -832,7 +838,7 @@ doLink o_files = do
     when (WayPar `elem` ways_) (do 
                                   success <- run_phase_MoveBinary output_fn
                                   if success then return ()
-                                             else throwDyn (OtherError ("cannot move binary to PVM dir")))
+                                             else throwDyn (InstallationError ("cannot move binary to PVM dir")))
 
 -----------------------------------------------------------------------------
 -- Making a DLL
@@ -981,8 +987,13 @@ compile ghci_mode summary source_unchanged have_object
 #endif
                    HscInterpreted -> return (error "no output file")
 
+   let (basename, _) = splitFilename input_fn
+       dyn_flags' = dyn_flags { hscOutName = output_fn,
+                               hscStubCOutName = basename ++ "_stub.c",
+                               hscStubHOutName = basename ++ "_stub.h" }
+
    -- run the compiler
-   hsc_result <- hscMain ghci_mode dyn_flags{ hscOutName = output_fn } 
+   hsc_result <- hscMain ghci_mode dyn_flags'
                         (ms_mod summary) location
                         source_unchanged have_object old_iface hst hit pcs
 
@@ -992,10 +1003,10 @@ compile ghci_mode summary source_unchanged have_object
       HscNoRecomp pcs details iface -> return (CompOK pcs details iface Nothing)
 
       HscRecomp pcs details iface
-       maybe_stub_h maybe_stub_c maybe_interpreted_code -> do
+       stub_h_exists stub_c_exists maybe_interpreted_code -> do
           
-          let (basename, _) = splitFilename input_fn
-          maybe_stub_o <- dealWithStubs basename maybe_stub_h maybe_stub_c
+          let 
+          maybe_stub_o <- compileStub dyn_flags' stub_c_exists
           let stub_unlinked = case maybe_stub_o of
                                  Nothing -> []
                                  Just stub_o -> [ DotO stub_o ]
@@ -1032,33 +1043,13 @@ compile ghci_mode summary source_unchanged have_object
 -----------------------------------------------------------------------------
 -- stub .h and .c files (for foreign export support)
 
-dealWithStubs basename maybe_stub_h maybe_stub_c
-
- = do  let stub_h = basename ++ "_stub.h"
-       let stub_c = basename ++ "_stub.c"
-
-  -- copy the .stub_h file into the current dir if necessary
-       case maybe_stub_h of
-          Nothing -> return ()
-          Just tmp_stub_h -> do
-               runSomething "Copy stub .h file"
-                               ("cp " ++ tmp_stub_h ++ ' ':stub_h)
-
-  -- copy the .stub_c file into the current dir, and compile it, if necessary
-       case maybe_stub_c of
-          Nothing -> return Nothing
-          Just tmp_stub_c -> do  -- copy the _stub.c file into the current dir
-               runSomething "Copy stub .c file" 
-                   (unwords [ 
-                       "rm -f", stub_c, "&&",
-                       "echo \'#include \"Stg.h\"\n#include \""++stub_h++"\"\' >"++stub_c, " &&",
-                       "cat", tmp_stub_c, ">> ", stub_c
-                       ])
-
-                       -- compile the _stub.c file w/ gcc
-               pipeline <- genPipeline (StopBefore Ln) "" True 
-                               defaultHscLang stub_c
-               stub_o <- runPipeline pipeline stub_c False{-no linking-} 
-                               False{-no -o option-}
-
-               return (Just stub_o)
+compileStub dflags stub_c_exists
+  | not stub_c_exists = return Nothing
+  | stub_c_exists = do
+       -- compile the _stub.c file w/ gcc
+       let stub_c = hscStubCOutName dflags
+       pipeline <- genPipeline (StopBefore Ln) "" True defaultHscLang stub_c
+       stub_o <- runPipeline pipeline stub_c False{-no linking-} 
+                       False{-no -o option-}
+
+       return (Just stub_o)