Code Generation and Code Generator Generators

A code generator inputs an intermediate representation of a program and outputs object code. In this course, we will output assembly language. A code generator generator inputs a description of the machine and intermediate representation and ou tputs a code generator.

There are other steps which are taken towards automating the code generation process that are something less than a full-fledged code generator generator.

A first step toward automating the code generation process, and good programming style as well, is to separate the code generation algorithm from the machine code itself. This allows tables of (IR,code) ordered pairs to be created and used and perhaps cha nged to be ported to another machine.

The code generation algorithm then consists of a driver inputting the intermediate code and consulting the table, just as in Figure 2. The difference is that the table is created by hand, rather than generated from a descript ion of the machine.

Example 7 shows such a code generator that might be termed retargetable. Input to the code generator is a set of ordered pairs. The first element of the ordered pair is a description of a subtree of the intermedia te representation to be matched; the second element is the code to be output on such a match.

Send questions and comment to: Karen Lemone