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 ()
|
||||
|
||||
Reference in New Issue
Block a user