[project @ 2001-08-03 23:38:50 by ken]
[ghc-hetmet.git] / ghc / compiler / main / Main.hs
index bf34a74..5a7d6c5 100644 (file)
@@ -1,6 +1,6 @@
 {-# OPTIONS -fno-warn-incomplete-patterns #-}
 -----------------------------------------------------------------------------
--- $Id: Main.hs,v 1.79 2001/07/03 11:14:33 simonmar Exp $
+-- $Id: Main.hs,v 1.83 2001/08/03 23:38:50 ken Exp $
 --
 -- GHC Driver program
 --
@@ -45,7 +45,7 @@ import DriverMkDepend ( beginMkDependHS, endMkDependHS )
 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
@@ -114,14 +114,20 @@ main =
   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)))
+               IOException _   ->  hPutStr stderr (show exception)
+#if __GLASGOW_HASKELL__ >= 501
+                 -- let exit exceptions bubble all the way out.
+               ExitException e ->  exitWith e
+#endif
+               _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)
@@ -160,12 +166,6 @@ main =
    (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 []
 
@@ -233,9 +233,15 @@ main =
        -- 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
@@ -288,18 +294,20 @@ main =
          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