Commit 7b2ac617 authored by Thomas Schilling's avatar Thomas Schilling
Browse files

Return parser errors and warnings instead of dying.

parent 46aff945
...@@ -53,6 +53,7 @@ import FastString ...@@ -53,6 +53,7 @@ import FastString
import Panic import Panic
import Constants import Constants
import Outputable import Outputable
import Bag ( emptyBag, unitBag )
import Control.Monad import Control.Monad
import Data.Array import Data.Array
...@@ -1092,7 +1093,7 @@ initEnv = listToUFM [ ...@@ -1092,7 +1093,7 @@ initEnv = listToUFM [
Var (CmmLit (CmmInt (fromIntegral stdInfoTableSizeB) wordRep) )) Var (CmmLit (CmmInt (fromIntegral stdInfoTableSizeB) wordRep) ))
] ]
parseCmmFile :: DynFlags -> FilePath -> IO (Maybe Cmm) parseCmmFile :: DynFlags -> FilePath -> IO (Messages, Maybe Cmm)
parseCmmFile dflags filename = do parseCmmFile dflags filename = do
showPass dflags "ParseCmm" showPass dflags "ParseCmm"
buf <- hGetStringBuffer filename buf <- hGetStringBuffer filename
...@@ -1102,14 +1103,17 @@ parseCmmFile dflags filename = do ...@@ -1102,14 +1103,17 @@ parseCmmFile dflags filename = do
-- reset the lex_state: the Lexer monad leaves some stuff -- reset the lex_state: the Lexer monad leaves some stuff
-- in there we don't want. -- in there we don't want.
case unP cmmParse init_state of case unP cmmParse init_state of
PFailed span err -> do printError span err; return Nothing PFailed span err -> do
let msg = mkPlainErrMsg span err
return ((emptyBag, unitBag msg), Nothing)
POk pst code -> do POk pst code -> do
cmm <- initC dflags no_module (getCmm (unEC code initEnv [] >> return ())) cmm <- initC dflags no_module (getCmm (unEC code initEnv [] >> return ()))
let ms = getMessages pst let ms = getMessages pst
printErrorsAndWarnings dflags ms if (errorsFound dflags ms)
when (errorsFound dflags ms) $ exitWith (ExitFailure 1) then return (ms, Nothing)
dumpIfSet_dyn dflags Opt_D_dump_cmm "Cmm" (ppr cmm) else do
return (Just cmm) dumpIfSet_dyn dflags Opt_D_dump_cmm "Cmm" (ppr cmm)
return (ms, Just cmm)
where where
no_module = panic "parseCmmFile: no module" no_module = panic "parseCmmFile: no module"
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment