summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.hs13
1 files 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> [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]