我正在尝试通过
编辑:对于以下程序,STG翻译似乎成功了,其中
事实上,乍一看,如果诱导的Core Haskell不强制执行原始操作,事情似乎是有效的。例如,
Outputable
从Haskell源代码中提取STG表示作为String
,但似乎coreToStgArgs
出现以下转储信息时会发生错误:user@machine ~/Desktop/hue $ runhaskell test.hs
[foo :: forall a. Num a => a -> a
[GblId, Arity=2, Caf=NoCafRefs, Str=DmdType] =
\r srt:SRT:[] [$dNum a1] + $dNum a1 a1;,
bar :: Int -> Int
[GblId,test.hs: test.hs: panic! (the 'impossible' happened)
(GHC version 7.10.3 for x86_64-unknown-linux):
coreToStgArgs I# 3
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
这里有一个名为 FooBar.hs
的文件,我想要提取它:
module FooBar where
foo a = a + a
bar :: Int -> Int
bar b = b + 3
这是我使用的 test.hs
的源代码:
import CoreToStg
import GHC
import GHC.Paths
import Outputable
import StgSyn
mkDynFlags :: IO DynFlags
mkDynFlags = runGhc (Just libdir) getSessionDynFlags
mkSTG :: FilePath -> FilePath -> IO [StgBinding]
mkSTG proj src = do
dflags <- mkDynFlags
ghc_core <- runGhc (Just libdir) $ do
setSessionDynFlags (dflags {importPaths = [proj]})
compileToCoreSimplified src
-- compileToCoreModule src
coreToStg dflags (cm_module ghc_core) (cm_binds ghc_core)
mkIOStr :: (Outputable a) => a -> IO String
mkIOStr obj = do
dflags <- mkDynFlags
let ppr_str = showPpr dflags obj
return ppr_str
main :: IO ()
main = do
let proj = "/home/user/Desktop/hue"
let src = proj ++ "/FooBar.hs"
res <- mkIOStr =<< mkSTG proj src
putStrLn res
看起来有人在我之前几年遇到了类似的问题:
https://ghc.haskell.org/trac/ghc/ticket/7159
然而,我不知道之后发生了什么。我也不确定这是否是从任意Haskell源代码中提取STG的正确方法,如果有更好的替代方案可行,我想听听它们的建议。编辑:对于以下程序,STG翻译似乎成功了,其中
bar b = b + 3
被改为bar b = 3
:module FooBar where
foo a = a + a
bar :: Int -> Int
bar b = 3
事实上,乍一看,如果诱导的Core Haskell不强制执行原始操作,事情似乎是有效的。例如,
bar b = 3 + 9
失败了。
CoreToStg.coreToStg
之前,我需要使用CorePrep.corePrepPgm
*”。 - melpomene