X-Git-Url: https://git.lukelau.me/?p=kaleidoscope-hs.git;a=blobdiff_plain;f=Main.hs;h=48d93a224de17958d9f4586bc1aa079e43aee5c5;hp=5bc3a3e0bde961a310f4d1e1a7fce733e20917d1;hb=HEAD;hpb=2fd7e4f3686c3b977881f995ec12b8dd60e72254 diff --git a/Main.hs b/Main.hs index 5bc3a3e..48d93a2 100644 --- a/Main.hs +++ b/Main.hs @@ -9,6 +9,7 @@ import Control.Monad.IO.Class import Data.String import qualified Data.Map as Map import qualified Data.Text.Lazy.IO as Text +import Foreign.Ptr import LLVM.AST.AddrSpace import LLVM.AST.Constant import LLVM.AST.Float @@ -27,6 +28,8 @@ import System.IO import System.IO.Error import Text.Read (readMaybe) +foreign import ccall "dynamic" mkFun :: FunPtr (IO Double) -> IO Double + data JITEnv = JITEnv { jitEnvContext :: Context , jitEnvCompileLayer :: IRCompileLayer ObjectLinkingLayer @@ -84,7 +87,9 @@ repl = do jit :: JITEnv -> Module -> IO Double jit JITEnv{jitEnvCompileLayer=compLayer, jitEnvModuleKey=mdlKey} mdl = withModule compLayer mdlKey mdl $ do - return 0 + mangled <- mangleSymbol compLayer "__anon_expr" + Right (JITSymbol fPtr _) <- findSymbolIn compLayer mdlKey mangled False + mkFun (castPtrToFunPtr (wordPtrToPtr fPtr)) type Binds = Map.Map String Operand