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

fixed orc example, fixed part of arith example #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions arith/Arith.hs
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,6 @@ symbolFromProcess sym =
(\addr -> JIT.JITSymbol addr JIT.defaultJITSymbolFlags)
<$> JIT.getSymbolAddressInProcess sym

resolv :: JIT.IRCompileLayer l -> JIT.SymbolResolver
resolv cl = JIT.SymbolResolver (\sym -> JIT.findSymbol cl sym True)

printIR :: MonadIO m => ByteString -> m ()
printIR = liftIO . BS.putStrLn . ("\n*** LLVM IR ***\n\n" <>)

Expand All @@ -337,12 +334,14 @@ withSimpleJIT expr doFun = do
printExpr expr
printIR asm
JIT.withModuleKey es $ \k ->
JIT.withModule compileLayer k mod' $ do
JIT.withSymbolResolver es (JIT.SymbolResolver (resolver compileLayer)) $ \sresolver -> do
fSymbol <- JIT.mangleSymbol compileLayer "f"
Right (JIT.JITSymbol fnAddr _) <- JIT.findSymbol compileLayer fSymbol True
let f = mkDoubleFun . castPtrToFunPtr $ wordPtrToPtr fnAddr
liftIO (putStrLn "*** Result ***\n")
evaluate $ force (doFun f)
modifyIORef' resolvers (Map.insert k sresolver)
JIT.withModule compileLayer k mod' $ do
Right (JIT.JITSymbol fnAddr _) <- JIT.findSymbol compileLayer fSymbol True
let f = mkDoubleFun . castPtrToFunPtr $ wordPtrToPtr fnAddr
liftIO (putStrLn "*** Result ***\n")
evaluate $ force (doFun f)

-- * Utilities

Expand Down
15 changes: 8 additions & 7 deletions orc/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ eagerJit amod = do
withModuleKey es $ \k ->
withSymbolResolver es (SymbolResolver (resolver compileLayer)) $ \sresolver -> do
modifyIORef' resolvers (Map.insert k sresolver)
rsym <- findSymbol compileLayer mainSymbol True
case rsym of
Left err -> do
print err
Right (JITSymbol mainFn _) -> do
result <- mkMain (castPtrToFunPtr (wordPtrToPtr mainFn))
print result
withModule compileLayer k mod $ do
rsym <- findSymbol compileLayer mainSymbol True
case rsym of
Left err -> do
print err
Right (JITSymbol mainFn _) -> do
result <- mkMain (castPtrToFunPtr (wordPtrToPtr mainFn))
print result

main :: IO ()
main = do
Expand Down