From e65072b6efe6692c90919410c54cf2d14d20f3d5 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 14 Jul 2017 08:41:43 +0200 Subject: Auto-assemble-link --- main.hs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.hs b/main.hs index c46e5da..7d82362 100644 --- a/main.hs +++ b/main.hs @@ -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.asm]" + $ die "Usage: bfcomphs [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] -- cgit v1.2.3-70-g09d2