Contents
Page-10
Prev
Next
Page+10
Index
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(kind) gets a register from a pool of available registers.
It also handles returning unused registers with unused(reg).
- While register management can be complex, a simple implementation
of getreg() works pretty well. We will discuss some improvements.