Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial work on refactor to LLVM 9.0 #52

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Recover from verify failure
  • Loading branch information
sdiehl committed Jan 9, 2020
commit 792c63fc2afa0a759095824e629137ace6fb7b5f
9 changes: 9 additions & 0 deletions src/chapter6/JIT.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 5,15 @@ module JIT
)
where

import Control.Exception (SomeException, catch)
import Control.Monad.Except
import qualified Data.ByteString.Char8 as ByteString
import Data.Int
import Data.Word
import Foreign.Ptr (FunPtr, castFunPtr)
import qualified LLVM.AST as AST
import LLVM.Analysis
import qualified LLVM.Analysis as L
import LLVM.CodeModel
import LLVM.Context
import qualified LLVM.ExecutionEngine as EE
Expand All @@ -33,6 35,11 @@ jit c = EE.withMCJIT c optlevel model ptrelim fastins
ptrelim = Nothing -- frame pointer elimination
fastins = Nothing -- fast instruction selection

verifyAndRecover :: Mod.Module -> IO String
verifyAndRecover m =
(L.verify m >> return "")
`catch` (\e -> return ("\nVerification error:\n" show (e :: SomeException) "\n"))

passes :: PassSetSpec
passes = defaultCuratedPassSetSpec {optLevel = Just 3}

Expand All @@ -44,6 51,8 @@ runJIT mod = do
withPassManager passes $ \pm -> do
-- Optimization Pass
{-runPassManager pm m-}
L.verify m
verifyErr <- verifyAndRecover m
optmod <- moduleAST m
s <- moduleLLVMAssembly m
ByteString.putStrLn s
Expand Down