diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-08-19 11:05:43 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-08-19 11:05:43 +0200 |
commit | 694ec05bcad01fd27606aace73b49cdade16945e (patch) | |
tree | 5c7a0433232f0860ef18f1634510d4f823ce5bdb /Main.hs |
Initial
Diffstat (limited to 'Main.hs')
-rw-r--r-- | Main.hs | 56 |
1 files changed, 56 insertions, 0 deletions
@@ -0,0 +1,56 @@ +module Main where + +import System.Exit +import System.IO +import System.Process +import Debug.Trace + +import BuildIR +import CodeGen +import Defs +import Optimiser +import Pretty +import ProgramParser +import TypeCheck +import Verify + + +infix 2 <?> +(<?>) :: (a -> Error b) -> String -> a -> Error b +f <?> pre = \a -> case f a of + Left e -> Left $ pre ++ ": " ++ e + Right x -> Right x + + +tracePrettyId :: Pretty a => a -> a +tracePrettyId x = trace (pretty x) x + +eitherToIO :: Either String a -> IO a +eitherToIO = either die return + + +main :: IO () +main = do + source <- getContents + + let eres = return source + >>= parseProgram <?> "Parse error" + -- >>= return . traceShowId + >>= typeCheck <?> "Type error" + >>= buildIR <?> "IR building error" + -- >>= return . tracePrettyId + >>= optimise <?> "Error while optimising" + >>= verify <?> "Verify error" + >>= return . tracePrettyId + >>= codegen <?> "Codegen error" + + asm <- eitherToIO eres + -- hPutStr stderr asm + + writeFile "z_output.asm" asm + + hPutStrLn stderr "Assembling with yasm..." + callCommand "yasm -w+all -fmacho64 z_output.asm -o z_output.o" + + hPutStrLn stderr "Linking with ld..." + callCommand "ld z_output.o -o z_output" |