1
1
mirror of https://github.com/tweag/asterius.git synced 2024-09-11 08:55:32 +03:00

Run all Cmm through the unregisterised C pipeline

This commit is contained in:
Cheng Shao 2021-12-13 15:24:14 +00:00
parent 506fa3b3b7
commit e176ea9541
2 changed files with 35 additions and 0 deletions

View File

@ -33,6 +33,7 @@ import qualified Stream
import System.Environment.Blank
import System.FilePath
import qualified ToolSettings as GHC
import Asterius.Internals.Staging
frontendPlugin :: GHC.Ghc ()
frontendPlugin = do
@ -80,6 +81,7 @@ frontendPlugin = do
hooksFromCompiler
( Compiler
{ withCmmIR = \dflags this_mod ir@CmmIR {..} obj_path -> do
checkC dflags cmmRaw
ffi_mod <- getFFIModule dflags this_mod
m' <- runCodeGen
( marshalCmmIR this_mod ir

View File

@ -0,0 +1,33 @@
module Asterius.Internals.Staging
( checkC,
)
where
import Asterius.Internals.Temp
import Cmm
import GhcPlugins
import PprC
import Stream (Stream)
import qualified Stream
import System.Environment.Blank
import System.FilePath
import System.IO
import System.IO.Unsafe
import System.Process
{-# NOINLINE clangBin #-}
clangBin :: FilePath
clangBin = unsafePerformIO $ do
Just p <- getEnv "WASI_SDK_PREFIX"
pure $ p </> "bin" </> "clang"
outputC :: DynFlags -> Handle -> Stream IO RawCmmGroup a -> IO a
outputC dflags h cmm_stream = do
hPutStr h "#include \"Stg.h\"\n"
Stream.consume cmm_stream (writeC dflags h)
checkC :: DynFlags -> Stream IO RawCmmGroup a -> IO ()
checkC dflags cmm_stream = withTempDir "ahc-staging" $ \d -> do
let p = d </> "test.c"
_ <- withFile p WriteMode $ \h -> outputC dflags h cmm_stream
callProcess "ahc" ["-o", d </> "test.o", "-c", p]