Compiler Design and Construction - Old Questions

9.  What is operation of simple code generator? Explain.

6 marks | Asked in 2068

The final phase in compiler model is the code generator. It takes as input an intermediate representation of the source program and produces as output an equivalent target program.

        Fig: Position of code generator

A simple code generator generates target code for a sequence of three- address statements and effectively uses registers to store operands of the statements. For example: consider the three-address statement a := b+c It can have the following sequence of codes:

ADD Rj, Ri     Cost = 1    // if Ri contains b and Rj contains c

(or)

ADD c, Ri     Cost = 2    // if c is in a memory location

(or)

MOV c, Rj     Cost = 3    // move c from memory to Rj and add

ADD Rj, Ri