-----------------------------------------------------------------------------
--- $Id: DriverPipeline.hs,v 1.57 2001/03/23 16:36:20 simonmar Exp $
+-- $Id: DriverPipeline.hs,v 1.63 2001/04/03 15:36:44 sewardj Exp $
--
-- GHC Driver
--
([] , 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")
-----------------------------------------------------------------------------
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
-- 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
-- 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
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
cmdline_includes <- dynFlag cmdlineHcIncludes -- -#include options
let cc_injects = unlines (map mk_include
- (c_includes ++ reverse cmdline_includes))
+ (c_includes ++ reverse cmdline_includes))
mk_include h_file =
case h_file of
'"':_{-"-} -> "#include "++h_file
-- 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
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
-- 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 (ProgramError (
basename ++ "." ++ suff
++ ": static flags are not allowed in {-# OPTIONS #-} pragmas:\n\t"
++ unwords flags)) (ExitFailure 1))
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
#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" }
+
+ -- figure out which header files to #include in a generated .hc file
+ c_includes <- getPackageCIncludes
+ cmdline_includes <- dynFlag cmdlineHcIncludes -- -#include options
+
+ let cc_injects = unlines (map mk_include
+ (c_includes ++ reverse cmdline_includes))
+ mk_include h_file =
+ case h_file of
+ '"':_{-"-} -> "#include "++h_file
+ '<':_ -> "#include "++h_file
+ _ -> "#include \""++h_file++"\""
+
+ writeIORef v_HCHeader cc_injects
+
-- 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
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 ]
-----------------------------------------------------------------------------
-- stub .h and .c files (for foreign export support)
-dealWithStubs basename maybe_stub_h maybe_stub_c
+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-}
- = 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)
-
- -- #include <..._stub.h> in .hc file
- addCmdlineHCInclude tmp_stub_h -- hack
-
- -- 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)
+ return (Just stub_o)