Chapter 9:Code generation

Code generation and Instruction Selection

.

. output code must be correct

. output code must be of high quality

. code generator should run efficiently

As we see that the final phase in any compiler is the code generator. It takes as input an intermediate representation of the source program and produces as output an equivalent target program, as shown in the figure. Optimization phase is optional as far as compiler's correct working is considered. In order to have a good compiler following conditions should hold:

1. Output code must be correct: The meaning of the source and the target program must remain the same i.e., given an input, we should get same output both from the target and from the source program. We have no definite way to ensure this condition. What all we can do is to maintain a test suite and check.

2. Output code must be of high quality: The target code should make effective use of the resources of the target machine.

3. Code generator must run efficiently: It is also of no use if code generator itself takes hours or minutes to convert a small piece of code.