could you please explain three address code generation with

could you please explain three address code generation with a example.

Solution

Three address code generation is an intermediate representation used in our Decaf compiler. It is very essentially a generic assembly language that falls in the lowerend of the midlevel IRs. Some variant of 2, 3 or 4 address code is fairly commonly used as an IR, since it maps well to most assembly languages. A Three address code instruction can have at most three operands. The operands could be two operands to a binary arithmetic operator and the third the result location, or an operand to compare to zero and a second location to branch to, and so on.

Example:

Three address code branching instructions used to translate an ifstatement:

if (a < b + c)                                                                _t1 = b + c;

a = a - c;                                                                      _t2 = a < _t1;

                                                                                    IfZ _t2 Goto _L0;

c = b * c;                                                                     _t3 = a - c;

                                                                                    a = _t3;

                                                                                    _L0: _t4 = b * c;

                                                                                    c = _t4;

And here is an example of the Three address code translation for a function call and array access:

n = ReadInteger();                                                               _t0 = LCall _ReadInteger;

Binky(arr[n]);                                                                         n = _t0;

_t1 = 4;

_t2 = _t1 * n;

_t3 = arr + _t2;

_t4 = *(_t3);

_t4;

LCall _Binky;

PopParams 4;

could you please explain three address code generation with a example.SolutionThree address code generation is an intermediate representation used in our Decaf

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site