X-Git-Url: https://git.lukelau.me/?p=kaleidoscope-hs-old.git;a=blobdiff_plain;f=Main.hs;h=f721911af3da8488e855ca46c966b736da2a5440;hp=fcfe5dfff83e36cdf16525069f89620bf581e9df;hb=882cd77116f1f1688022e69a469b62f97a831725;hpb=808a6ae35fb1f2ff61a84991af1e7722298a4d62 diff --git a/Main.hs b/Main.hs index fcfe5df..f721911 100644 --- a/Main.hs +++ b/Main.hs @@ -11,6 +11,7 @@ import System.IO import LLVM.Context import LLVM.ExecutionEngine import LLVM.Module +import LLVM.PassManager import LLVM.IRBuilder import LLVM.AST.AddrSpace import LLVM.AST.Constant @@ -18,17 +19,20 @@ import LLVM.AST.Float import LLVM.AST.Operand import LLVM.AST.Type as Type import LLVM.Pretty +import Control.Monad foreign import ccall "dynamic" exprFun :: FunPtr (IO Float) -> IO Float main :: IO () main = do - program <- read <$> getContents - let mdl = buildModule "main" $ mapM buildAST program - Text.hPutStrLn stderr (ppllvm mdl) + AST.Program asts <- read <$> getContents + let mdl = buildModule "main" $ mapM buildAST asts withContext $ \ctx -> withMCJIT ctx Nothing Nothing Nothing Nothing $ \mcjit -> withModuleFromAST ctx mdl $ \mdl' -> + withPassManager defaultCuratedPassSetSpec $ \pm -> do + runPassManager pm mdl' >>= guard + Text.hPutStrLn stderr . ppllvm =<< moduleAST mdl' withModuleInEngine mcjit mdl' $ \emdl -> do Just f <- getFunction emdl "expr" let f' = castFunPtr f :: FunPtr (IO Float)