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

2

11

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?

Felicity answered 5/10, 2010 at 14:42 Comment(0)
P
9

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

Produce answered 5/10, 2010 at 19:40 Comment(3)
I was hesitant to report it because I wasn't sure if I was using the functions correctly. Are there any examples of these kinds of transformations?Felicity
I don't know of any specific examples, no.Produce
Is there any progress with this issue? I've tried today exactly the same code and it resulted in the same error message.Spherics
B
6

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

Bajaj answered 21/1, 2012 at 8:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.