diff options
| -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  | 
