Generating code
The back end: compiling to a stack machine with backpatched jumps, running it on a virtual machine, and assigning registers with linear scan.
About 4 hours of study
Learning objectives
- Generate stack-machine code for variables, loops and conditions
- Backpatch forward jumps and run code on a virtual machine
- Compute live ranges and allocate registers with linear scan
Lessons
- 1
Generating code for a stack machine Advanced
Compile variables, loops and conditions to stack-machine instructions, fill in jump addresses with backpatching, and run the result on a small virtual machine, the way the JVM, CPython and WebAssembly work.
- 2
Register allocation Advanced
Decide which values live in the processor's few registers. Compute live ranges, measure register pressure, and assign registers with linear scan, spilling to memory when there are not enough.
Module practice
- Compilers: A virtual machine with jumpsEasy
- Compilers: Compile loops to stack codeMedium
- Compilers: Compile and run, with elseHard
- Compilers: Live rangesEasy
- Compilers: How many registers?Medium
- Compilers: Linear-scan register allocationHard