问HN:测试编译器的AST或汇编输出

2作者: backslash_1625 天前原帖
嗨,Hacker News, 我正在从零开始开发一个C编译器,目前在测试生成的抽象语法树(AST)和汇编输出方面遇到了一些困难。我特别难以找到适合一个人项目且实用的解决方案。 我对Clang进行了一些研究,发现他们使用了一个自定义的Filecheck库。这对于一个生产级编译器来说非常出色,但对于我的项目,我不确定是否值得投入所有的精力(尤其是因为我的主语言F#没有Filecheck库,我需要重新创建一个)。 AST也是同样的情况——我能想到的最好方法就是在我的主代码语言中创建节点。这显得有些冗长。 你们是如何测试和检查编译器输出的?有没有什么好的推荐给我?我乐意进行研究或阅读任何相关内容。请记住,我希望努力与回报之间达到一个良好的平衡。
查看原文
Hi Hacker News,<p>I&#x27;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&#x27;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&#x27;m not sure if I want to put in all of the effort (especially because my host language F# doesn&#x27;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&#x27;m happy to research or read anything. Please keep in mind I&#x27;m going for a good effort to reward ratio.