Add standard library
[kaleidoscope-hs.git] / Main.hs
diff --git a/Main.hs b/Main.hs
index 97407fee2fbf6ef7907f3f45a934e737fa29d593..64d73e60e0a059864222aec09f8b2ad0803adcfd 100644 (file)
--- a/Main.hs
+++ b/Main.hs
@@ -19,12 +19,14 @@ import LLVM.AST.Operand
 import LLVM.AST.Type as Type
 import LLVM.Context
 import LLVM.IRBuilder
+import LLVM.Linking
 import LLVM.Module
 import LLVM.OrcJIT
 import LLVM.OrcJIT.CompileLayer
 import LLVM.PassManager
 import LLVM.Pretty
 import LLVM.Target
+import Numeric
 import System.IO
 import System.IO.Error
 import Text.Read (readMaybe)
@@ -38,7 +40,8 @@ data JITEnv = JITEnv
   }
 
 main :: IO ()
-main =
+main = do
+  loadLibraryPermanently (Just "stdlib.dylib")
   withContext $ \ctx -> withHostTargetMachineDefault $ \tm ->
     withExecutionSession $ \exSession ->
       withSymbolResolver exSession (SymbolResolver symResolver) $ \symResolverPtr ->
@@ -51,7 +54,10 @@ main =
 
 -- This can eventually be used to resolve external functions, e.g. a stdlib call
 symResolver :: MangledSymbol -> IO (Either JITSymbolError JITSymbol)
-symResolver sym = undefined
+symResolver sym = do
+  ptr <- getSymbolAddressInProcess sym
+  putStrLn $ "Resolving " <> show sym <> " to 0x" <> showHex ptr ""
+  return (Right (JITSymbol ptr defaultJITSymbolFlags))
 
 repl :: ModuleBuilderT (ReaderT JITEnv IO) ()
 repl = do