@@ -32,6 +32,7 @@ import Control.Applicative
3232import Control.Monad.RWS
3333import Control.Monad.Writer
3434import Control.Monad.State
35+import Control.Monad.Error
3536
3637import qualified System.Info as SI (arch, os)
3738import System.IO
@@ -50,7 +51,7 @@ codegenLLVM :: [(TT.Name, SDecl)] ->
5051codegenLLVM defs file outty = withContext $ \context -> do
5152 let target = Target { arch = SI.arch, os = SI.os }
5253 let ast = codegen target (map snd defs)
53− result <- M.withModuleFromAST context ast (outputModule file outty)
54+ result <- runErrorT $ M.withModuleFromAST context ast (outputModule file outty)
5455 case result of
5556 Right _ -> return ()
5657 Left msg -> ierror msg
@@ -60,7 +61,7 @@ itWidth ITNative = 32
6061itWidth x = fromIntegral $ intTyWidth x
6162
6263outputModule :: FilePath -> OutputType -> M.Module -> IO ()
63−outputModule file Raw m = M.writeBitcodeToFile file m
64+outputModule file Raw m = either fail return <=< runErrorT $ M.writeBitcodeToFile file m
6465outputModule file Object m = withTmpFile $ \bc -> do
6566 outputModule bc Raw m
6667 exit <- rawSystem "llc" ["-filetype=obj", "--disable-fp-elim", "-o", file, bc]