diff --git a/app/Main.hs b/app/Main.hs index 25acb9c..8618420 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,5 +1,6 @@ {-# LANGUAGE OverloadedLabels #-} {-# LANGUAGE OverloadedLists #-} +{-# LANGUAGE ViewPatterns #-} module Main (main) where @@ -15,7 +16,7 @@ import Options.Applicative import Control.Lens import Data.Generics.Labels import System.OsPath (OsPath) -import System.FilePath ((-<.>)) +import System.FilePath ((-<.>), dropExtension) import Effectful.FileSystem import Effectful import Effectful.FileSystem.IO qualified as FS @@ -88,13 +89,29 @@ callQBE callQBE f = do let asm_file = f -<.> "s" qbe_file = f -<.> "ssa" - C.StdoutTrimmed stdout <- + C.StdoutUntrimmed stdout <- C.run $ C.cmd "qbe" & C.addArgs [qbe_file] FS.withFile asm_file FS.WriteMode \h -> do hPutStr h stdout hPutStrLn FS.stderr $ "wrote " <> T.pack asm_file pure asm_file +callGCC + :: (GenSym :> es, FileSystem :> es, IOE :> es) + => FilePath -> List String -> Eff es FilePath +callGCC f args = do + let asm_file = f -<.> "s" + exe = dropExtension f + C.StdoutTrimmed (T.words -> flags) <- + C.run $ C.cmd "pkg-config" + & C.addArgs @String ["--cflags", "--libs", "bdw-gc"] + C.run_ $ C.cmd "cc" + & C.addArgs flags + & C.addArgs ["-o", exe, asm_file] + & C.addArgs args + hPutStrLn FS.stderr $ "wrote " <> T.pack exe + pure exe + driver :: (GenSym :> es, FileSystem :> es, IOE :> es) => Options -> Eff es () @@ -103,4 +120,5 @@ driver = runGenSym . traverseOf_ (#sourceFiles . folded) \f -> do anfs <- toANF f exps qbe <- toQBE f anfs callQBE f + callGCC f ["../runtime/gyehoek.c"] pure () diff --git a/play/t b/play/t new file mode 100755 index 0000000..b1af0b5 Binary files /dev/null and b/play/t differ diff --git a/play/t.anf b/play/t.anf index 1026f62..831ceda 100644 --- a/play/t.anf +++ b/play/t.anf @@ -1,4 +1,4 @@ ;;; -*- mode:scheme -*- -(let ((x0 (prim:write 4))) x0) +(let ((x0 (prim:+ 2 4)) (x1 (prim:write x0))) x1) diff --git a/play/t.s b/play/t.s index 83a7477..f8824c4 100644 --- a/play/t.s +++ b/play/t.s @@ -3,7 +3,7 @@ main: pushq %rbp movq %rsp, %rbp - movl $18, %edi + movl $30, %edi callq scm_write leave ret @@ -11,4 +11,4 @@ main: .size main, .-main /* end function main */ -.section .note.GNU-stack,"",@progbits \ No newline at end of file +.section .note.GNU-stack,"",@progbits diff --git a/play/t.scm b/play/t.scm index 321e540..8895d2c 100644 --- a/play/t.scm +++ b/play/t.scm @@ -1 +1 @@ -(prim:write 4) +(prim:write (prim:+ 2 4)) diff --git a/play/t.ssa b/play/t.ssa index 8e05fd5..9b6d236 100644 --- a/play/t.ssa +++ b/play/t.ssa @@ -1,6 +1,9 @@ export function w $main () { @start - %x0 =l call $scm_write (l 18) - ret %x0 + %.2 =l add 10, 18 + %.3 =l and %.2, 18446744073709551613 + %x0 =l or %.3, 2 + %x1 =l call $scm_write (l %x0) + ret %x1 } \ No newline at end of file