[Haskell-cafe] Using GHC Api to affect compilation of a module

Matias Hernandez mhernand at gmail.com
Sun Aug 29 22:41:13 EDT 2010


Hello people,

I'm evaluating the use of the GHC API (6.12.3) to piggyback into the
compilation process (in order, for example, to implement a custom
optimization) and I'm having a lot of trouble doing so.

In particular, I tried to modify a program being compiled, by working
on its Core representation. The idea is that the skeleton of the
program would be something like:

runGhc (Just libdir) $ do
    ...
    c <- compileToCoreModule targetFile
    compileCoreToObj False (modify c)
    ...

with modify :: CoreModule -> CoreModule being, for now, a rather
trivial (identity) function. The first issue I've found is that
compileCoreToObj fails (the error is "expectJust mkStubPaths").
However, I've also found that when compileToCoreModule ends, the .hi
and .o files have already been produced, which kind of defeats any
attempt to change the core code and then proceeding with the rest of
the compilation.

Am I doing this right? By scanning over the GHC API documentation
those functions seemed to be the appropriate ones to start testing
with, but I guess there's something trivial (or not) I'm missing.

I'd be really thankful for any input.

Best regards,
- Matias H.


More information about the Haskell-Cafe mailing list