算法与计算机科学c9x.me编辑精选
业余编译器作者的资源清单
Resources for Amateur Compiler Writers
2016 — 2021,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这是编译器作者 c9x.me 站点维护的一份面向业余编译器编写者的文献资源列表,偏重后端与机器码方向,涵盖寄存器分配、指令选择、优化等主题的经典论文与书籍。页面在 2016 和 2021 两次登上 Hacker News 首页,评论中不少人补充了自己用过的资料并讨论这份清单适合什么水平的读者。
为什么经久不衰:它把散落各处的编译器后端经典文献集中成一份清单,多年后仍被反复推荐,是自学编译器时省去大量检索成本的起点。
HN 评论精选
这份清单偏后端,更适合中级而非初学编译器作者
这份清单明显偏后端、偏机器码方向。如果你写的是编译到 WebAssembly 甚至 JVM 的编译器,很多资料用不上。而且我认为它更适合中级水平的编译器作者:初学者不需要懂寄存器分配,他们需要理解如何思考语言翻译、如何写中间表示、如何学习目标语言。一个简单但重要的例子是:有了健全的类型检查器后,代码生成阶段几乎不应该报错——到那时你应该已经证明了足够多的不变量,使代码生成不可能失败。
hardwaregeek查看英文原文
This is definitely a backend, machine code focused list. If you're writing a compiler to WebAssembly or even the JVM you're probably not gonna need a lot of these resources. Indeed I'd argue that these lists are more for an intermediate compiler writer. Beginner compiler writers don't need to know register allocation. They need to understand how to think about language translation, how to write an intermediate representation, how to learn a target language. I've been toying with the idea of writing a post that goes through the thought process of translation. Specifically, how you build states, and invariants. When I write code generation I spend time thinking about the different states the stack could be in, or what invariant I need to keep across this expression (do I need to save a register or global?). One simple but important example of this is realizing that given a proper, sound type checker, your code generator should almost never give errors. By the time you reach code generation you should have proven enough invariants that code generation cannot fail. This isn't always true but I've found it to be the case.
指出列表作者是轻量级编译器项目 c9x.me/compile 的作者
这是 c9x.me/compile/(一份优秀的轻量级 LLVM 替代方案)作者整理的列表。
iTokio查看英文原文
By the author of the excellent https://c9x.me/compile/ A lightweight alternative to llvm https://c9x.me/compile/doc/llvm.html
逐条分享列表中几份资料的实际使用体验
列表里的 Zephyr ASDL 对我创建 AST(以及即将做的 IR 节点)帮助极大,虽然为此重写自己的 ASDL 生成器至少三次,颇费周折。Parr 的《Language Implementation Patterns》偏 Java/ANTLR,但概念不难迁移到我用 C++ 写的转译器上。Cliff Click 的论文和博士论文是我接下来要钻研的方向。
UncleEntity查看英文原文
The Zephyr Abstract Syntax Description Language, Wang et al. Has been invaluable for creating the AST (and soon the IR nodes)-- though it has been a source of much yak shaving as I've rewritten my asdl generator at least 3 times. Language Implementation Patterns: Create Your Own Domain-Specific and General Programming Languages Book, Terence Parr Pretty java/antlr focused but wasn't too hard to take the concepts and apply them to a C++ based transpiler I've been slowly poking at. Combining Analyses, Combining Optimizations, Cliff Click His thesis and an extension of the linked paper Global Code Motion, Global Value Numbering -- my next step down the rabbit hole... Tree Automata Techniques and Applications, Comon et al. Still on the fence on this one vs the iburg/burs algorithm, probably be more useful and match better with the way Parr's book goes about things.
认为对业余爱好者来说这份清单太重,实用路线是写编译到现有语言的 DSL
坦白说,我觉得这份列表没什么意思,尤其对业余爱好者而言。业余编译器作者大概想在几周内做出点有用的东西,而不是花一年瞎折腾。那其实是另一回事:做一个元 DSL,编译成另一种语言,与现有库、工具链和整个生态良好配合,同时为你做点特别有用的事。你只需要学点解析(递归下降之类)、一点 AST 操作,差不多就够了。
zzzcpan查看英文原文
Frankly, I don't see anything interesting in that list, especially for amateurs. As an amateur compiler writer you would probably want to make something useful in a few weeks, not waste a year playing around. And it's a very different story. It's essentially about making a meta DSL, that compiles into another language and plays well with existing libraries, tooling, the whole ecosystem, but also does something special and useful for you. So, you should learn parsing, possibly recursive descend for the code and something else for expressions, a bit about working with ASTs and that's pretty much it.
历次讨论
同类还值得读
位运算技巧集
Bit Twiddling Hacks
斯坦福页面上的经典位运算技巧合集,收录了 popcount、前导/尾随零、位反转、交换、舍入等大量技巧,并附有解释和性能讨论。
算法与计算机科学上首页 8 次 · 2011–2024graphics.stanford.edu编辑精选如何不按平均评分排序
How Not To Sort By Average Rating
经典文章解释了为什么按平均评分排序不可靠:只有少量评价的条目(比如仅一条五星)会轻易排到最前,而评价数量的差异被忽略。
算法与计算机科学上首页 7 次 · 2009–2024evanmiller.org编辑精选数据结构可视化
Data Structure Visualizations
旧金山大学 David Galles 教授制作的数据结构与算法交互式可视化网站,涵盖 B 树、红黑树、排序、图算法等,可逐步操作观察其运行过程。
算法与计算机科学上首页 6 次 · 2011–2021cs.usfca.edu编辑精选1996 年以来的计算机科学最佳论文奖
Best Paper Awards in Computer Science since 1996
Jeff Huang 维护的一个汇总页面,收录了自 1996 年以来计算机科学各主要会议的“最佳论文奖”获奖名单,并按年份和会议整理,方便读者一站式浏览历届获奖论文。
算法与计算机科学上首页 6 次 · 2010–2018jeffhuang.com编辑精选算法(Jeff Erickson)
Algorithms, by Jeff Erickson
伊利诺伊大学 Jeff Erickson 教授的算法课教材,免费在线开放。
算法与计算机科学上首页 5 次 · 2018–2022jeffe.cs.illinois.edu编辑精选