X-Git-Url: http://git.lukelau.me/?p=kaleidoscope-hs.git;a=blobdiff_plain;f=Main.hs;fp=Main.hs;h=64d73e60e0a059864222aec09f8b2ad0803adcfd;hp=97407fee2fbf6ef7907f3f45a934e737fa29d593;hb=58bc647a182a51f277577aa7c46381a2138a2e06;hpb=705b0b8458673edb7273e6e19914390a55e51d23 diff --git a/Main.hs b/Main.hs index 97407fe..64d73e6 100644 --- 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