看过LLVM源代码的同学应该都知道,LLVM是用C++编写的,而且它主要都是由一个个lib构成的。
那么,为什么呢?为什么要如此侧重于库的设计?
LLVM is an infrastructure, a collection of useful compiler technology that can be brought to bear on specific problems (like building a C compiler, or an optimizer in a special effects pipeline).1
自由化的定制能力
让我们来看一个优化器的例子:
- 读入LLVM IR
- 输出更优的LLVM IR