11.1 Preparation for Code Generation

11.2 Generation of Directives

11.3 Simple Code Generation from AST's

11.4 Standard Code Generation Strategies

11.5 Code Generator Generators

11.6 Register Allocation

11.7 A Better Code Generation Algorithm from AST's

11.8 Code Generation from DAG's

11.9 Retargetable Code Generation

11.10 Peephole Optimization

11.11 Summary

Web References

Exercises

11.11 Summary

Code generation translates the intermediate representation of a program to executable code, while symbol table information is often translated to the storage allocation directives of a machine. The resulting instructions should be spaced and time efficient. Since resources such as registers are limited, choices are made when there is more than one way to perform the same computation.

A statement by statement code generator tends to produce poor code, where by "good" code we mean code that executes fast or takes up less space. To produce better code, code generation avoids extra computation, reusing computed values (common subexpressions) if reuse is less expensive than recomputing.

Further efficiency can be achieved by avoiding extra loads, unnecessary stores, avoidable register-to-register moves, and special instructions.

A good code generator design, like all software, is easier to implement, easier to test, and easier to maintain.