-----------------------------------------------------------------------------
--- $Id: DriverPipeline.hs,v 1.60 2001/03/27 16:32:46 rrt Exp $
+-- $Id: DriverPipeline.hs,v 1.66 2001/05/08 10:58:48 simonmar 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")
-----------------------------------------------------------------------------
cish = cish_suffix suffix
-- for a .hc file we need to force lang to HscC
- real_lang | start_phase == HCc = HscC
- | otherwise = lang
+ real_lang | start_phase == HCc || start_phase == Mangle = HscC
+ | otherwise = lang
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
+ print (show pipeline ++ show annotated_pipeline ++ show stop_phase)
+
return (
takeWhile (phase_ne stop_phase ) $
dropWhile (phase_ne start_phase) $
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
+ let orig_fn = basename ++ '.':suff
+ deps_sources <- mapM (findDependency True orig_fn) import_sources
+ deps_normals <- mapM (findDependency False orig_fn) 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
else return False
-- build a ModuleLocation to pass to hscMain.
- modsrc <- readFile input_fn
- let (srcimps,imps,mod_name) = getImports modsrc
+ (srcimps,imps,mod_name) <- getImportsFromFile input_fn
Just (mod, location)
<- mkHomeModuleLocn mod_name basename (basename ++ '.':suff)
-- 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
preprocess :: FilePath -> IO FilePath
preprocess filename =
- ASSERT(haskellish_file filename)
+ ASSERT(haskellish_src_file filename)
do init_dyn_flags <- readIORef v_InitDynFlags
writeIORef v_DynFlags init_dyn_flags
pipeline <- genPipeline (StopBefore Hsc) ("preprocess") False
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'
(ms_mod summary) location