diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-07-14 08:41:43 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-07-14 08:41:43 +0200 |
commit | e65072b6efe6692c90919410c54cf2d14d20f3d5 (patch) | |
tree | b1c0d12d3288c398a7b3f1470aeb5a423be73d4a | |
parent | d015d797fe8d152864cdd5f1ce284bd5ff467f9e (diff) |
Auto-assemble-link
-rw-r--r-- | main.hs | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -5,6 +5,7 @@ import Control.Monad import Data.Char import System.Environment import System.Exit +import System.Process import AST import Compiler @@ -23,9 +24,9 @@ main :: IO () main = do args <- getArgs when (length args == 0 || length args > 2) - $ die "Usage: bfcomphs <source.bf> [source.bf.asm]" + $ die "Usage: bfcomphs <source.bf> [source.bf.exe]" let fname = head args - destfname = if length args == 2 then args !! 1 else fname ++ ".asm" + destfname = if length args == 2 then args !! 1 else fname ++ ".exe" prog <- readFile fname >>= either die return . parseProgram @@ -33,14 +34,14 @@ main = do -- print prog let opt = optimise prog showopt = force $ show opt - when False $ putStrLn $ astSuccinct opt + when True $ putStrLn $ astSuccinct opt when False $ putStrLn showopt case executionMode of EMInterpret -> do - -- input <- getContents - -- putStr $ map (chr . fromIntegral) $ interpret opt (map (fromIntegral . ord) input) input <- getContents interpret opt (map (fromIntegral . ord) input) >>= (putStr . map (chr . fromIntegral)) EMCompile -> do - writeFile destfname $ compile opt + writeFile (fname ++ ".asm") $ compile opt + callProcess "yasm" ["-f", "macho64", fname ++ ".asm", "-o", fname ++ ".o"] + callProcess "gcc" [fname ++ ".o", "-o", destfname] |