From 42e484fd8552d480becafcfecbaeac826466b88c Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Tue, 24 Jan 2017 21:53:12 +0100 Subject: Compile to LLVM IR --- main.hs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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 -- cgit v1.2.3-70-g09d2