Three address code generation- Compiler design

ROSHNIPRADHAN2 17 views 10 slides Jul 26, 2024
Slide 1
Slide 1 of 10
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10

About This Presentation

Three address code generation- Compiler design


Slide Content

TAC

Different forms of TAC:

The HLL expressions are converted into the intermediate code using an

of the following TAC forms.

TAC Form Usage

x=yopz For Binary Operation & then assignmer
x =opz For Unary Operation & then assignmen
x=y For simple assignment.

if (x <rel op> y) GOTO L |

Conditional GOTO.

ASS

GOTO L Unconditional GOTO.
Ali] = x
y = All i Used for arrays.
7 HE ‘x is a value pointed by the pointer ‘p’.
y = &x Address of ‘x’ is stored in ‘y.

While Loop:
주 while(E) do S
푸 while(E)

S

While Loop:

AY Way 1: | AY Way 2:
L: if(E==0) GOTO L1 : L: if(E) GOTO L1
5 : GOTO L2
GOTO L 1 Li: 5
Li: 8 GOTO L ’
: L2:

$ Note: After the HLL Loop has been converted to TAC, it is impossible to recognize
it as it's been implemented using conditional and unconditional GOTO TAC
statements.

Conversion to TAC - Example:

Convert the HLL to TAC: L: if(x<y) GOTO L1
while(x<y) GOTO L2
{ 두
ne lee = 19 & E
メオ: a
} 2 al
ES
GOTO L

E2:

For Loop:
1 OR(B dE 8 )
{

S
}

ER Initialization
32 Condition

E,: Increment / Decrement

For Loop:

for (i=0;1<10; i++)

{
}

a=b+c;

LL:

L2:

i=0
: if(ik10) GOTO L1
GOTO L2
t=b+c
a
a= t,
B= 1+ 31
i= tE,
GOTO L

TAC Form

x=yopz

x=opz

x=y

if (x <rel op> y) GOTO L

GOTO L

o nia [al

Ali] = x
y = Ali]

x= *p
y = &

TAC of Switch-Case:

switch(m+n) t=m+n | Trif(t==1) GOTO L1
* の SoTOT 。 iflte=2) GOTO L2
case : a=b+c; Sie Sl a Ee |
a a a GOTO L3
case(2): p=q+r; : GOTO L4 |

break; E L2: t=q+r e

Default: x=y+z; p=

break; : GOT
t,

2D Arrays:

00 | 이 | 02 |
ae) 7017
| 20 | 의 | 22 |

mo (Jalon =
4 6

2x5 HP T

20 Arrays: >

A[10][20] t = y x 20

X = Aly,z] 1,5 E, +2

Size of each cell = 4 units t,=t,x4
t, = base Address of A
x= t[t,]
Tags