2d64043ef7cdff3d025dfe01dfc69e9c69236b68 — JoJo 3 years ago dac5a6d
Verify LLVM module before compiling to catch errors

Of course, these are internal compiler errors, but they're better to
catch in `verify` for debugging purposes. Previously, LLVM would just
segfault when processing a malformed module.
1 files changed, 2 insertions(+), 2 deletions(-)

M src/Compile.hs
M src/Compile.hs => src/Compile.hs +2 -2
@@ 3,6 3,7 @@ module Compile (compile, CompileConfig(..), defaultCompileConfig) where
import LLVM.Context
import LLVM.Module
import LLVM.Target
import LLVM.Analysis
import Data.Maybe
import System.FilePath
import System.Process

@@ 38,10 39,9 @@ compileModule :: TargetMachine -> CompileConfig -> Module -> IO ()
compileModule t cfg m = do
    let binfile = fromMaybe "out" (outfile cfg)
        llfile = replaceExtension binfile "ll"
        bcfile = replaceExtension binfile "bc"
        ofile = replaceExtension binfile "o"
    writeLLVMAssemblyToFile' llfile m
    writeBitcodeToFile (File bcfile) m
    verify m
    writeObjectToFile t (File ofile) m
        (cc cfg)