Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use the GHC API to modify a program while compiling it?

I want to test the implementation a compiler optimization by piggybacking into the GHC compilation process and altering its Core representation. The idea would be to have something like:

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

where modify takes the Core representation and returns the modified version. This code, however, fails (even when modify does nothing at all) with the not very helpful message:

expectJust mkStubPaths

Any ideas on how to make this work, or if it's even possible to implement a code transformation this way?

like image 920
matiash Avatar asked Oct 05 '10 14:10

matiash


2 Answers

That sounds like a bug in compileCoreToObj to me. Please report it.

like image 144
Simon Marlow Avatar answered Oct 21 '22 14:10

Simon Marlow


GHC has support for plugins now, which appear to do exactly what you want.

like image 6
FunctorSalad Avatar answered Oct 21 '22 14:10

FunctorSalad