SlideShare a Scribd company logo
1 of 22
3 Address Code Generation
ShinerajArathil
B.Tech (CSE) 6th Sem
Presented By:
PREPARED BY SHINE 2
Intermediate Code
▪ An language b/w source and target language
▪ Provides an intermediate level of abstraction
▪ More details than the source
▪ Fewer details than the target
PREPARED BY SHINE 3
SOURCE LANGUAGE TARGET LANGUAGE
Intermediate Code
Benefits of intermediate code generation
▪ A compiler for different machines can be created by attaching
different backend to the existing front ends of each machine
▪ A compiler for different source languages (on the same
machine) can be created by proving different front ends for
corresponding source language to existing back end.
▪ A machine independent code optimizer can be applied to
intermediate code in order to optimize the code generation
PREPARED BY SHINE 4
Three Address Code
▪ Is an intermediate code used by optimizing compilers to aid in the implementation of
code-improving transformations.
▪ EachTAC instruction has at most three operands and is typically a combination of
assignment and a binary operator
▪ InTAC, there is at most one operator on the right side of an instruction.That is no built-
up arithmetic expressions are permitted
Example : x + y * z
t1 = y * z
t2 = x + t1
t1 and t2 are compiler-generated temporary names
PREPARED BY SHINE 5
▪ Statements in this language are of the form:
x:=y op z
▪ where x, y and z are names, constants or compiler-generated
temporary variables, and ‘op’ stands for any operator
PREPARED BY SHINE 6
▪ Three Address Code is a linearized representation of a syntax trees or a
DAG
PREPARED BY SHINE 7
T1 = b – c
T2 = a * t1
T3 = a + t2
T4 = t1 * d
T5 = t3 + t4
Data structures for three address codes
 Quadruples
 Has four fields: op, arg1, arg2 and result
 Triples
 Temporaries are not used and instead references to instructions are
made
 Indirect triples
 In addition to triples we use a list of pointers to triples
PREPARED BY SHINE 8
Example
▪ b * minus c + b * minus c t1 = minus c
t2 = b * t1
t3 = minus c
t4 = b * t3
t5 = t2 + t4
a = t5
Three address code
minus
*
minus c t3
*
+
=
c t1
b t2t1
b t4t3
t2 t5t4
t5 a
arg1 resultarg2op
Quadruples
minus
*
minus c
*
+
=
c
b (0)
b (2)
(1) (3)
a
arg1 arg2op
Triples
(4)
0
1
2
3
4
5
minus
*
minus c
*
+
=
c
b (0)
b (2)
(1) (3)
a
arg1 arg2op
Indirect Triples
(4)
0
1
2
3
4
5
(0)
(1)
(2)
(3)
(4)
(5)
op
35
36
37
38
39
40
Disadvantage Of quadruples
▪ Temporary names must be entered into the symbol table as they are
created.
▪ This increases the time and size of the symbol table.
PREPARED BY SHINE 10
Pro: easy to rearrange code for global optimization
Cons: lots of temporaries
Disadvantage OfTRIPLES
▪ Moving a statement that define a temporary value
requires us to change all references to that statement
in arg1 and arg2 arrays.This problem makes triple
difficult to use in an optimizing compiler.
PREPARED BY SHINE 11
Types ofThree-Address Code
▪ Assignment statement x := y op z
▪ Assignment statement x := op y
▪ Copy statement x := y
▪ Unconditional jump goto L
▪ Conditional jump if x relop y goto L
▪ Procedural call param x call p
return y
Assignment Statement
▪ Assignment statements can be in the following two forms
1. x:=op y
2. x:=y op z
First statement op is a unary operation. Essential unary operations
are unary minus, logical negation, shift operators and conversion
operators.
Second statement op is a binary arithmetic or logical operator.
5/14/2014 14
Three-Address Statements
A popular form of intermediate code used in optimizing
compilers is three-address statements.
Source statement:
x = a + b c + d
Three address statements with temporaries t1 and t2:
t1 = b c
t2 = a + t1
x = t2 + d
Jump Statements
source statement like if-then-else and while-do cause jump in
the control flow through three address code so any statement in
three address code can be given label to make it the target of a
jump.
The statement
goto L
Cause an unconditional jump to the statement with label L. the
statement
if x relop y goto L
Causes a jump to L condition if and only if
Boolean condition is true.
This instruction applies relational operator relop (>,=,<, etc.)
to x and y, and executes statement L next of x statement x relop y. If
not, the three address statement following if x relop y goto L is
executed next, as in the usual sequence.
Procedure Call / Return
A procedure call like P(A1,A2, A3,……….An) may have to many
addresses for one statement in three-address code so it is shown
as a sequence of n +1 statements’
Param A1
Param A2
M
Param An
Call p,n
Where P is the name of the procedure and and n is
a integer indicating the number of actual
parameters in the call.
This information is redundant, as n can be
computed by counting the number of par am
statements.
It is a convenience to have n available with the call
statement.
Indexed Assignment
Indexed assignment of the form A:=B[I] and A[I]:=B.
the first statement sets A to the value in the location I
memory units beyond location B.
In the later statement A [I]:=B, sets the location I units
beyondA to the value of B.
In Both instructions ,A, B, and I are assumed to refer data
objects and will represented by pointers to the symbol
table.
Address and Pointer Assignment
Address and pointer assignment
x := &y
x := *y
*x := y
First statement, sets the value of x to be the location of y.
In x := *y, here y is a pointer or temporary whose r-value is a
location. The r-value of x is made equal to the contents of that
location.
*x := y sets the r-value of the object pointed to by a to the r-value of
y.
Summary
▪ Intermediate Code
▪ 3 Address Code
▪ Data Structures Of 3Address Code
▪ Types ofThree-Address Code
PREPARED BY SHINE 21
ThankYou
PREPARED BY SHINE 22

More Related Content

What's hot

Error detection recovery
Error detection recoveryError detection recovery
Error detection recoveryTech_MX
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler designRiazul Islam
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler DesignAkhil Kaushik
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler designKuppusamy P
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generationRamchandraRegmi
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignKuppusamy P
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lexAnusuya123
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler designRajkumar R
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler DesignKuppusamy P
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler DesignKuppusamy P
 

What's hot (20)

Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Error detection recovery
Error detection recoveryError detection recovery
Error detection recovery
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler design
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
 
Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Types of Parser
Types of ParserTypes of Parser
Types of Parser
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler design
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
 
Types of Compilers
Types of CompilersTypes of Compilers
Types of Compilers
 
Bottom up parser
Bottom up parserBottom up parser
Bottom up parser
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
COMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed TranslationCOMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed Translation
 

Viewers also liked

Retail Travel Business Strategy - Panorama Tour Indonesia
Retail Travel Business Strategy - Panorama Tour IndonesiaRetail Travel Business Strategy - Panorama Tour Indonesia
Retail Travel Business Strategy - Panorama Tour IndonesiaWidodo Heru Santoso
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocksJothi Lakshmi
 
code optimization
code optimization code optimization
code optimization Sanjeev Raaz
 
Compiler Design
Compiler DesignCompiler Design
Compiler DesignMir Majid
 
Code generator
Code generatorCode generator
Code generatorTech_MX
 
Basic Blocks and Flow Graphs
Basic Blocks and Flow GraphsBasic Blocks and Flow Graphs
Basic Blocks and Flow GraphsJenny Galino
 
[Jennifer vu huong]Zen travel business plan
[Jennifer vu huong]Zen travel  business plan[Jennifer vu huong]Zen travel  business plan
[Jennifer vu huong]Zen travel business planJen Vuhuong
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler designAnul Chaudhary
 
Symbol table design (Compiler Construction)
Symbol table design (Compiler Construction)Symbol table design (Compiler Construction)
Symbol table design (Compiler Construction)Tech_MX
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generationrawan_z
 

Viewers also liked (11)

Retail Travel Business Strategy - Panorama Tour Indonesia
Retail Travel Business Strategy - Panorama Tour IndonesiaRetail Travel Business Strategy - Panorama Tour Indonesia
Retail Travel Business Strategy - Panorama Tour Indonesia
 
Compiler unit 2&3
Compiler unit 2&3Compiler unit 2&3
Compiler unit 2&3
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocks
 
code optimization
code optimization code optimization
code optimization
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Code generator
Code generatorCode generator
Code generator
 
Basic Blocks and Flow Graphs
Basic Blocks and Flow GraphsBasic Blocks and Flow Graphs
Basic Blocks and Flow Graphs
 
[Jennifer vu huong]Zen travel business plan
[Jennifer vu huong]Zen travel  business plan[Jennifer vu huong]Zen travel  business plan
[Jennifer vu huong]Zen travel business plan
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
 
Symbol table design (Compiler Construction)
Symbol table design (Compiler Construction)Symbol table design (Compiler Construction)
Symbol table design (Compiler Construction)
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
 

Similar to Three address code In Compiler Design

Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generatorsanchi29
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generationVipul Naik
 
Chapter 11 - Intermediate Code Generation.pdf
Chapter 11 - Intermediate Code Generation.pdfChapter 11 - Intermediate Code Generation.pdf
Chapter 11 - Intermediate Code Generation.pdfRAnwarpasha
 
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...venkatapranaykumarGa
 
Presentation(intermediate code generation)
Presentation(intermediate code generation)Presentation(intermediate code generation)
Presentation(intermediate code generation)Sourov Kumar Ron
 
Compiler chapter six .ppt course material
Compiler chapter six .ppt course materialCompiler chapter six .ppt course material
Compiler chapter six .ppt course materialgadisaAdamu
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generationIffat Anjum
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1Shashwat Shriparv
 
Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...
Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...
Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...Saikrishna Tanguturu
 
Three address code generation
Three address code generationThree address code generation
Three address code generationRabin BK
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)bolovv
 
Intermediate code representations
Intermediate code representationsIntermediate code representations
Intermediate code representationsahmed51236
 
Programming basic computer
Programming basic computerProgramming basic computer
Programming basic computerMartial Kouadio
 
Topic 2_revised.pptx
Topic 2_revised.pptxTopic 2_revised.pptx
Topic 2_revised.pptxJAYAPRIYAR7
 

Similar to Three address code In Compiler Design (20)

Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generator
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
Chapter 11 - Intermediate Code Generation.pdf
Chapter 11 - Intermediate Code Generation.pdfChapter 11 - Intermediate Code Generation.pdf
Chapter 11 - Intermediate Code Generation.pdf
 
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
 
Presentation(intermediate code generation)
Presentation(intermediate code generation)Presentation(intermediate code generation)
Presentation(intermediate code generation)
 
Compiler chapter six .ppt course material
Compiler chapter six .ppt course materialCompiler chapter six .ppt course material
Compiler chapter six .ppt course material
 
Assignment12
Assignment12Assignment12
Assignment12
 
Chapter 6 Intermediate Code Generation
Chapter 6   Intermediate Code GenerationChapter 6   Intermediate Code Generation
Chapter 6 Intermediate Code Generation
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
 
Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...
Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...
Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...
 
Compiler notes--unit-iii
Compiler notes--unit-iiiCompiler notes--unit-iii
Compiler notes--unit-iii
 
Three address code generation
Three address code generationThree address code generation
Three address code generation
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)
 
Ch8a
Ch8aCh8a
Ch8a
 
Intermediate code representations
Intermediate code representationsIntermediate code representations
Intermediate code representations
 
Programming basic computer
Programming basic computerProgramming basic computer
Programming basic computer
 
ch08.ppt
ch08.pptch08.ppt
ch08.ppt
 
Intermediate code
Intermediate codeIntermediate code
Intermediate code
 
Topic 2_revised.pptx
Topic 2_revised.pptxTopic 2_revised.pptx
Topic 2_revised.pptx
 

Recently uploaded

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 

Recently uploaded (20)

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 

Three address code In Compiler Design

  • 1. 3 Address Code Generation ShinerajArathil B.Tech (CSE) 6th Sem Presented By:
  • 3. Intermediate Code ▪ An language b/w source and target language ▪ Provides an intermediate level of abstraction ▪ More details than the source ▪ Fewer details than the target PREPARED BY SHINE 3 SOURCE LANGUAGE TARGET LANGUAGE Intermediate Code
  • 4. Benefits of intermediate code generation ▪ A compiler for different machines can be created by attaching different backend to the existing front ends of each machine ▪ A compiler for different source languages (on the same machine) can be created by proving different front ends for corresponding source language to existing back end. ▪ A machine independent code optimizer can be applied to intermediate code in order to optimize the code generation PREPARED BY SHINE 4
  • 5. Three Address Code ▪ Is an intermediate code used by optimizing compilers to aid in the implementation of code-improving transformations. ▪ EachTAC instruction has at most three operands and is typically a combination of assignment and a binary operator ▪ InTAC, there is at most one operator on the right side of an instruction.That is no built- up arithmetic expressions are permitted Example : x + y * z t1 = y * z t2 = x + t1 t1 and t2 are compiler-generated temporary names PREPARED BY SHINE 5
  • 6. ▪ Statements in this language are of the form: x:=y op z ▪ where x, y and z are names, constants or compiler-generated temporary variables, and ‘op’ stands for any operator PREPARED BY SHINE 6
  • 7. ▪ Three Address Code is a linearized representation of a syntax trees or a DAG PREPARED BY SHINE 7 T1 = b – c T2 = a * t1 T3 = a + t2 T4 = t1 * d T5 = t3 + t4
  • 8. Data structures for three address codes  Quadruples  Has four fields: op, arg1, arg2 and result  Triples  Temporaries are not used and instead references to instructions are made  Indirect triples  In addition to triples we use a list of pointers to triples PREPARED BY SHINE 8
  • 9. Example ▪ b * minus c + b * minus c t1 = minus c t2 = b * t1 t3 = minus c t4 = b * t3 t5 = t2 + t4 a = t5 Three address code minus * minus c t3 * + = c t1 b t2t1 b t4t3 t2 t5t4 t5 a arg1 resultarg2op Quadruples minus * minus c * + = c b (0) b (2) (1) (3) a arg1 arg2op Triples (4) 0 1 2 3 4 5 minus * minus c * + = c b (0) b (2) (1) (3) a arg1 arg2op Indirect Triples (4) 0 1 2 3 4 5 (0) (1) (2) (3) (4) (5) op 35 36 37 38 39 40
  • 10. Disadvantage Of quadruples ▪ Temporary names must be entered into the symbol table as they are created. ▪ This increases the time and size of the symbol table. PREPARED BY SHINE 10 Pro: easy to rearrange code for global optimization Cons: lots of temporaries
  • 11. Disadvantage OfTRIPLES ▪ Moving a statement that define a temporary value requires us to change all references to that statement in arg1 and arg2 arrays.This problem makes triple difficult to use in an optimizing compiler. PREPARED BY SHINE 11
  • 12. Types ofThree-Address Code ▪ Assignment statement x := y op z ▪ Assignment statement x := op y ▪ Copy statement x := y ▪ Unconditional jump goto L ▪ Conditional jump if x relop y goto L ▪ Procedural call param x call p return y
  • 13. Assignment Statement ▪ Assignment statements can be in the following two forms 1. x:=op y 2. x:=y op z First statement op is a unary operation. Essential unary operations are unary minus, logical negation, shift operators and conversion operators. Second statement op is a binary arithmetic or logical operator.
  • 14. 5/14/2014 14 Three-Address Statements A popular form of intermediate code used in optimizing compilers is three-address statements. Source statement: x = a + b c + d Three address statements with temporaries t1 and t2: t1 = b c t2 = a + t1 x = t2 + d
  • 15. Jump Statements source statement like if-then-else and while-do cause jump in the control flow through three address code so any statement in three address code can be given label to make it the target of a jump. The statement goto L Cause an unconditional jump to the statement with label L. the statement
  • 16. if x relop y goto L Causes a jump to L condition if and only if Boolean condition is true. This instruction applies relational operator relop (>,=,<, etc.) to x and y, and executes statement L next of x statement x relop y. If not, the three address statement following if x relop y goto L is executed next, as in the usual sequence.
  • 17. Procedure Call / Return A procedure call like P(A1,A2, A3,……….An) may have to many addresses for one statement in three-address code so it is shown as a sequence of n +1 statements’ Param A1 Param A2 M Param An Call p,n
  • 18. Where P is the name of the procedure and and n is a integer indicating the number of actual parameters in the call. This information is redundant, as n can be computed by counting the number of par am statements. It is a convenience to have n available with the call statement.
  • 19. Indexed Assignment Indexed assignment of the form A:=B[I] and A[I]:=B. the first statement sets A to the value in the location I memory units beyond location B. In the later statement A [I]:=B, sets the location I units beyondA to the value of B. In Both instructions ,A, B, and I are assumed to refer data objects and will represented by pointers to the symbol table.
  • 20. Address and Pointer Assignment Address and pointer assignment x := &y x := *y *x := y First statement, sets the value of x to be the location of y. In x := *y, here y is a pointer or temporary whose r-value is a location. The r-value of x is made equal to the contents of that location. *x := y sets the r-value of the object pointed to by a to the r-value of y.
  • 21. Summary ▪ Intermediate Code ▪ 3 Address Code ▪ Data Structures Of 3Address Code ▪ Types ofThree-Address Code PREPARED BY SHINE 21