callGCC
This commit is contained in:
22
app/Main.hs
22
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 ()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
;;; -*- mode:scheme -*-
|
||||
|
||||
(let ((x0 (prim:write 4))) x0)
|
||||
(let ((x0 (prim:+ 2 4)) (x1 (prim:write x0))) x1)
|
||||
|
||||
|
||||
4
play/t.s
4
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
|
||||
.section .note.GNU-stack,"",@progbits
|
||||
|
||||
@@ -1 +1 @@
|
||||
(prim:write 4)
|
||||
(prim:write (prim:+ 2 4))
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user