Hi Tim (and all other GHC API gurus)
I managed to get most of the way towards where I was aiming for.
Ideally I want an interface such that loading a filename gives me the
GHC Core out of it.
Here is what I have so far (strongly stolen from Tim):
import GHC
import Outputable
import CoreSyn
ghcBaseDir = "D:/ghc/ghc-6.7.20070626"
main = do
core <- loadCoreFile "D:/ghc/Main.hs" "Main"
case core of
Just c -> pprTrace "Core binds: " (ppr c) return ()
_ -> putStrLn "error compiling to Core"
loadCoreFile :: FilePath -> String -> IO (Maybe [CoreBind])
loadCoreFile file modname = do
s <- newSession (Just ghcBaseDir)
-- turn on CPP
flags <- getSessionDynFlags s
(flags, _) <- parseDynamicFlags flags ["-cpp"]
setSessionDynFlags s flags
-- find the target
target <- guessTarget file Nothing
addTarget s target
sc <- load s LoadAllTargets
-- set the context
let mkModname = mkModuleName modname
mod <- findModule s (mkModuleName modname) Nothing
setContext s [] [mod]
-- compile to Core
compileToCore s mkModname file
It works fine. The problem is that loadCoreFile takes a filename, and
the module name of that filename. Is there any way I can modify this
code to not require the module name, but get it from the API?
Thanks
Neil
_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc