External Core in binary format

Tim Chevalier catamorphism at gmail.com
Mon Jun 25 18:24:50 EDT 2007


I've checked in code for the function Neil asked for:

Mon Jun 25 15:06:08 PDT 2007  Tim Chevalier <chevalier at alum.wellesley.edu>
  * Add a compileToCore function to the GHC API

Here is the program I used for testing it:
---------
import GHC
import DynFlags
import PackageConfig
import BasicTypes
import Outputable

ghcBaseDir = "/home/krc/ghc_june24_complete/ghc_1"
preludeModName = mkModuleName "Prelude"
preludeFileName = ghcBaseDir ++ "/libraries/base/Prelude.hs"

main = defaultErrorHandler defaultDynFlags $ do
  -- Set up flags...
  s <- newSession (Just ghcBaseDir)
  flags1 <- getSessionDynFlags s
  (flags2, _) <- parseDynamicFlags flags1 ["-cpp"]
  setSessionDynFlags s flags2
  -- Load the module...
  let mod = mkModule (stringToPackageId "base")
                     preludeModName
  target <- guessTarget preludeFileName Nothing
  addTarget s target
  sc <- load s LoadAllTargets
  setContext s [] [mod]
  -- Compile to Core
  ghc_core <- compileToCore s preludeModName preludeFileName
  case ghc_core of
     Just cb -> pprTrace "Core binds: " (ppr cb)
                  return ()
     _      -> putStrLn "error compiling to Core"
------------
So it's not quite as simple as just calling two functions :-) Most of
the incantations here are documented on the "GHC as a library" page on
the wiki, though. I'm happy to take suggestions as to whether any of
the extra code can be incorporated into compileToCore so that the user
doesn't have to invoke it separately; I'm not very familiar with the
GHC API. I also haven't tested the code that extensively, so I'm happy
to fix any bugs that might come up.

Cheers,
Tim

-- 
Tim Chevalier* catamorphism.org *Often in error, never in doubt
"Nuclear war can ruin your whole compile." -- Karl Lehenbauer



More information about the Cvs-ghc mailing list