Chapter 9: Code generation

Issues in the design of code generator

. Input: Intermediate representation with symbol table assume that input has been validated by the front end

. target programs :

- absolute machine language fast for small programs

- relocatable machine code requires linker and loader

- assembly code requires assembler, linker, and loader

Let us examine the generic issues in the design of code generators.

1. Input to the code generator: The input to the code generator consists of the intermediate representation of the source program produced by the front end, together with the information in the symbol table that is used to determine the runtime addresses of the data objects denoted by the names in the intermediate representation. We assume that prior to code generation the input has been validated by the front end i.e., type checking, syntax, semantics etc. have been taken care of. The code generation phase can therefore proceed on the assumption that the input is free of errors.

2. Target programs: The output of the code generator is the target program. This output may take a variety of forms; absolute machine language, relocatable machine language, or assembly language.

. Producing an absolute machine language as output has the advantage that it can be placed in a fixed location in memory and immediately executed. A small program can be thus compiled and executed quickly.

. Producing a relocatable machine code as output allows subprograms to be compiled separately. Although we must pay the added expense of linking and loading if we produce relocatable object modules, we gain a great deal of flexibility in being able to compile subroutines separately and to call other previously compiled programs from an object module.

. Producing an assembly code as output makes the process of code generation easier as we can generate symbolic instructions. The price paid is the assembling, linking and loading steps after code generation.