提问 HN:如何测试编译器的 AST 或汇编输出?
2 分•作者: backslash_16•8 个月前
各位 Hacker News 的朋友,
我正在从头开始编写一个 C 编译器,目前在测试生成的 AST(抽象语法树)和汇编输出方面遇到了一些瓶颈。我特别难以找到一个既适合单人项目又实用的方法。
我研究了 Clang,发现他们使用了一个自定义的 Filecheck 库。这对于生产级编译器来说非常棒,但对于我的编译器,我不确定是否要投入这么多精力(尤其因为我的宿主语言 F# 没有 Filecheck 库,我需要重新创建它)。
AST 方面也是一样——我能想到的最好方法是在我的宿主代码语言中创建节点。但这很冗长。
你们是如何测试和检查编译器输出的?有什么好的建议吗?我很乐意研究或阅读任何内容。请记住,我追求的是一个良好的投入产出比。
查看原文
Hi Hacker News,<p>I'm working on a c compiler from scratch and am in a bit of a deadzone figuring out how I can test the generated AST and assembly output. I'm specifically having a hard time finding something that is viable for a one person project and which is also useful.<p>I did some research on Clang and saw they use a custom Filecheck library. This looks incredible for a production grade compiler but for mine I'm not sure if I want to put in all of the effort (especially because my host language F# doesn't have a Filecheck lib and I would have to re-create it).<p>Same with the AST - the best I can think of is creating the nodes in my host code language. This is verbose.<p>What have you done to test and check your compiler output, any good recommendations for me? I'm happy to research or read anything. Please keep in mind I'm going for a good effort to reward ratio.