From 882cd77116f1f1688022e69a469b62f97a831725 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Sun, 10 Mar 2019 15:03:03 +0000 Subject: [PATCH] Add default optimisation passes --- Main.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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) -- 2.30.2