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:
parent
506fa3b3b7
commit
e176ea9541
@ -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
|
||||
|
33
asterius/src/Asterius/Internals/Staging.hs
Normal file
33
asterius/src/Asterius/Internals/Staging.hs
Normal 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]
|
Loading…
Reference in New Issue
Block a user