From: Luke Lau Date: Sun, 10 Mar 2019 15:03:03 +0000 (+0000) Subject: Add default optimisation passes X-Git-Url: https://git.lukelau.me/?p=kaleidoscope-hs-old.git;a=commitdiff_plain;h=882cd77116f1f1688022e69a469b62f97a831725 Add default optimisation passes --- 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)