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

发布于 2024-09-26 08:07:00 字数 375 浏览 0 评论 0原文

我想通过搭载 GHC 编译过程并更改其核心表示来测试编译器优化的实现。这个想法是这样的:

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

其中 modify 接受 Core 表示并返回修改后的版本。但是,此代码失败(即使修改根本不执行任何操作),并显示不太有用的消息:

expectJust mkStubPaths

有关如何使此工作的任何想法,或者甚至可以通过这种方式实现代码转换吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

御弟哥哥 2024-10-03 08:07:00

对我来说,这听起来像是 compileCoreToObj 中的一个错误。请举报

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

歌入人心 2024-10-03 08:07:00

GHC 现在支持插件,这似乎完全符合您的要求。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文