diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-01-24 21:53:12 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-01-24 21:53:12 +0100 |
commit | 42e484fd8552d480becafcfecbaeac826466b88c (patch) | |
tree | c54e173a9dde9a9929127d3d7547ec03a8b9f66b | |
parent | 935f59da631ec97f6c7a0b49caae127e7a9aaa78 (diff) |
Compile to LLVM IR
-rw-r--r-- | main.hs | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -1,9 +1,13 @@ module Main where import Control.Monad +import Control.Monad.Except import Data.Either import System.Environment import System.Exit +import qualified LLVM.General as General +import qualified LLVM.General.Context as General +import qualified LLVM.General.Target as General import Check import Codegen @@ -23,6 +27,11 @@ dieShow :: (Show a) => a -> IO () dieShow = die . show +assert :: ExceptT String IO a -> IO a +assert ex = do + e <- runExceptT ex + either die return e >> (return $ (\(Right r) -> r) e) + main :: IO () main = do args <- getArgs @@ -43,3 +52,16 @@ main = do llvmMod <- either die return $ codegen checked "Module" fname putStrLn "Module:" print llvmMod + + General.withContext $ \context -> do + assert $ General.withModuleFromAST context llvmMod $ \genmod -> do + llvmasm <- General.moduleLLVMAssembly genmod + putStr llvmasm + putStrLn "" + -- assert $ General.withHostTargetMachine $ \machine -> do + -- General.getTargetMachineTriple machine >>= putStrLn + -- putStrLn "" + -- assert (General.moduleTargetAssembly machine genmod) + -- >>= putStr + -- bs <- assert $ General.moduleObject machine genmod + -- BS.writeFile "output_gen.o" bs |