On 6/27/07, Neil Mitchell <[EMAIL PROTECTED]> wrote:
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?
Yeah, I figured that might be a source of complaint :-)
With a bit more digging around, I figured out how to get the module
name from the filename, so compileToCore now takes just a session and
a filename as an argument; you don't need the module name anymore. The
sample program now looks like:
----------------------------------
import GHC
import DynFlags
import PackageConfig
import BasicTypes
import Outputable
ghcBaseDir = -- whatever
coreFileName = -- whatever
main = defaultErrorHandler defaultDynFlags $ do
-- Set up flags...
s <- newSession (Just ghcBaseDir)
flags1 <- getSessionDynFlags s
(flags2, _) <- parseDynamicFlags flags1 ["-cpp"]
setSessionDynFlags s flags2
-- Load the module...
target <- guessTarget coreFileName Nothing
addTarget s target
sc <- load s LoadAllTargets
-- Compile to Core
ghc_core <- compileToCore s coreFileName
case ghc_core of
Just cb -> pprTrace "Core binds: " (ppr cb)
return ()
_ -> putStrLn "error compiling to Core"
---------------------------
Notice that the call to setContext is no longer necessary.
The new code should be in the next nightly snapshot; if you
run into anything else, let me know!
Cheers,
Tim
--
Tim Chevalier* catamorphism.org *Often in error, never in doubt
"I don't like your I-can-use-anything-as-an-adjective attitude." -- Larry Wall
_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc