Overview of Code Generation
We will take a hierarchical approach to code generation:
- genc(code) generates code for a statement. There are only
a few kinds of statements. genc is easy to do given genarith.
- genarith(expr) generates code for an arithmetic expression.
genarith is a classical postorder tree-recursive program, with
a simple basic form (but many special cases). genarith is not
hard given getreg.
- getreg gets a register from a pool of available registers.
It also handles returning unused registers.
- While register management can be complex, a simple implementation
works pretty well. We will discuss some improvements.