Module 6 Intermediate Code Generation.pdf

NiramayKolalle 12 views 18 slides Jul 18, 2024
Slide 1
Slide 1 of 18
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
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18

About This Presentation

Pdf of Module 6 part 1
It contains theory about Intermediate Code Generation


Slide Content

Intermediate Code
Generation

Importance of intermediate code

Intermediate code Representation
•Postfix notation
•Syntax Tree
•Directed Acyclic Graph(DAG)
•Three address code

Various statement in TAC
1. Assignment x= y op z
x= op y
x=y
2. Jump
Conditional
eg. If x relop y then goto L ;- relop-?????? relational operator
Unconditional
eg. Goto L
•If the condition “x relop y” gets satisfied, then-
•The control is sent directly to the location specified by label L.
•All the statements in between are skipped.

3. Array Assignment x= y[i]
y[i]=x
4. Pointer address assignment x=&y
x=*y

Example:- (a*b)+(c*d)

Three address code:- t1=a*b
t2=c*d
t3=t1+t2

•Example:- -(a x b) + (c + d) – (a + b + c + d)
•Solution :- (1) T1 = a x b
(2) T2 = uminus T1
(3) T3 = c + d
(4) T4 = T2 + T3
(5) T5 = a + b
(6) T6 = T3 + T5
(7) T7 = T4 – T6
Uminus :- unary minus

•Example:- Write Three Address Code for the following
expression-
•If A < B then 1 else 0
•Solution-
 Three Address Code for the given expression is-
(1) If (A < B) goto (4)
(2) T1 = 0
(3) goto (5)
(4) T1 = 1
(5)

•Write Three Address Code for the following expression-
•If A < B and C < D then t = 1 else t = 0
•Solution-
 
Three Address Code for the given expression is-
(1) If (A < B) goto (3)
(2) goto (4)
(3) If (C < D) goto (6)
(4) t = 0
(5) goto (7)
(6) t = 1
(7)

•Implementation of Three Address Code
•Quadruple
•Triples
1. Quadruple – It is a structure which consists of 4 fields namely op, arg1, arg2 and
result. op denotes the operator and arg1 and arg2 denotes the two operands and result is
used to store the result of the expression.

Advantage –
Easy to rearrange code for global optimization.
One can quickly access value of temporary variables using symbol table.
Disadvantage –
Contain lot of temporaries.
Temporary variable creation increases time and space complexity.
2. Triples-
In triples representation,
•References to the instructions are made.
•Temporary variables are not used.

Example ▪ a = b * minus c + b * minus c
Three address code t1 = minus c
t2 = b * t1
t3 = minus c
t4 = b * t3
t5 = t2 + t4
a = t5

Quadruple Triples
Tags