简体   繁体   English

是否可以在编译时使用GHC API修改程序?

[英]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. 我想通过捎带进入GHC编译过程并改变其核心表示来测试实现编译器优化。 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. 其中modify采用Core表示并返回修改后的版本。 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? 关于如何使这项工作的任何想法,或者甚至可能以这种方式实现代码转换?

That sounds like a bug in compileCoreToObj to me. 这听起来像是compileCoreToObj一个错误。 Please report it . 报告

GHC现在支持插件 ,它看起来完全符合您的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM