summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-01-24 21:53:12 +0100
committertomsmeding <tom.smeding@gmail.com>2017-01-24 21:53:12 +0100
commit42e484fd8552d480becafcfecbaeac826466b88c (patch)
treec54e173a9dde9a9929127d3d7547ec03a8b9f66b
parent935f59da631ec97f6c7a0b49caae127e7a9aaa78 (diff)
Compile to LLVM IR
-rw-r--r--main.hs22
1 files changed, 22 insertions, 0 deletions
diff --git a/main.hs b/main.hs
index 7828034..b4a66d0 100644
--- a/main.hs
+++ b/main.hs
@@ -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