Scalar Compilers (pcc/lcc)
In this chapter, we'll implement a simple compiler that translates C89 to RV32I.
First, we'll introduce the standard implementation plan for all compilers
which involves lifting the source code into a tree intermediate representation
(referred to as an abstract syntax tree) with a parser
and lowering the
intermediate representation into target code with a code generator
. Then we'll
implement the compiler incrementally for each language feature starting with a
language capable of arithmetic, then adding control flow and finally memory.
The next chapter builds on this one by
- updating the tree representation to a two-tiered graph (referred to as a control flow graph)
- taking the existing
parser
andgenerator
and adding anoptimizer
in between