{-# OPTIONS -fno-warn-incomplete-patterns #-}
-----------------------------------------------------------------------------
--- $Id: Main.hs,v 1.77 2001/06/29 12:58:20 rrt Exp $
+-- $Id: Main.hs,v 1.84 2001/08/07 10:54:01 simonmar Exp $
--
-- GHC Driver program
--
import DriverPhases ( Phase(Hsc, HCc), haskellish_src_file, objish_file )
import DriverUtil ( add, handle, handleDyn, later, splitFilename,
- unknownFlagErr )
+ unknownFlagErr, getFileSuffix )
import CmdLineOpts ( dynFlag, defaultDynFlags, restoreDynFlags,
saveDynFlags, setDynFlags,
DynFlags(..), HscLang(..), v_Static_hsc_opts
main =
-- top-level exception handler: any unrecognised exception is a compiler bug.
- handle (\exn -> case exn of
- IOException _ -> do hPutStr stderr (show exn)
- exitWith (ExitFailure 1)
- _ -> do hPutStr stderr (show (Panic (show exn)))
- exitWith (ExitFailure 1)
- ) $ do
+ handle (\exception -> do
+ case exception of
+ -- an IO exception probably isn't our fault, so don't panic
+ IOException _ -> hPutStr stderr (show exception)
+ _other -> hPutStr stderr (show (Panic (show exception)))
+ exitWith (ExitFailure 1)
+ ) $ do
-- all error messages are propagated as exceptions
handleDyn (\dyn -> case dyn of
- PhaseFailed _phase code -> exitWith code
+ PhaseFailed _phase code -> do
+ hPutStr stderr "\nCompilation had errors\n"
+ exitWith code
Interrupted -> exitWith (ExitFailure 1)
_ -> do hPutStrLn stderr (show (dyn :: GhcException))
exitWith (ExitFailure 1)
(flags2, mode, stop_flag) <- getGhcMode argv'
writeIORef v_GhcMode mode
- -- Show the GHCi banner?
-# ifdef GHCI
- when (mode == DoInteractive) $
- hPutStrLn stdout ghciWelcomeMsg
-# endif
-
-- process all the other arguments, and get the source files
non_static <- processArgs static_flags flags2 []
-- complain about any unknown flags
mapM unknownFlagErr [ f | f@('-':_) <- srcs ]
- -- Display details of the configuration in verbose mode
verb <- dynFlag verbosity
+ -- Show the GHCi banner
+# ifdef GHCI
+ when (mode == DoInteractive && verb >= 1) $
+ hPutStrLn stdout ghciWelcomeMsg
+# endif
+
+ -- Display details of the configuration in verbose mode
when (verb >= 2)
(do hPutStr stderr "Glasgow Haskell Compiler, Version "
hPutStr stderr cProjectVersion
let (basename, suffix) = splitFilename src
-- just preprocess (Haskell source only)
+ let src_and_suff = (src, getFileSuffix src)
pp <- if not (haskellish_src_file src) || mode == StopBefore Hsc
- then return src else do
+ then return src_and_suff else do
phases <- genPipeline (StopBefore Hsc) stop_flag
- False{-not persistent-} defaultHscLang src
- pipeLoop phases src False{-no linking-} False{-no -o flag-}
+ False{-not persistent-} defaultHscLang
+ src_and_suff
+ pipeLoop phases src_and_suff False{-no linking-} False{-no -o flag-}
basename suffix
-- rest of compilation
hsc_lang <- dynFlag hscLang
- phases <- genPipeline mode stop_flag True hsc_lang pp
- r <- pipeLoop phases pp (mode==DoLink || mode==DoMkDLL) True{-use -o flag-}
- basename suffix
+ phases <- genPipeline mode stop_flag True hsc_lang pp
+ (r,_) <- pipeLoop phases pp (mode==DoLink || mode==DoMkDLL)
+ True{-use -o flag-} basename suffix
return r
o_files <- mapM compileFile srcs
case mods of
[] -> throwDyn (UsageError "no input files")
mod -> do state <- cmInit Batch
- cmLoadModule state mods
+ (_, ok, _) <- cmLoadModule state mods
+ when (not ok) (exitWith (ExitFailure 1))
return ()