import LLVM.Context
import LLVM.ExecutionEngine
import LLVM.Module
+import LLVM.PassManager
import LLVM.IRBuilder
import LLVM.AST.AddrSpace
import LLVM.AST.Constant
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)