SlideShare a Scribd company logo
Chapter six
Intermediate Code Generation
Rift valley University
Harar Campus
Overview
 Intermediate code is the interface between
front end and back end in a compiler.
 Ideally the details of source language are
confined to the front end and the details of
target machines to the back end (a machine
model)
 This intermediate code serves as a bridge
between the high-level source code and
the final machine code or another target
language.
3
Overview
 In a compiler, the front end translates source
program into an intermediate representation,
 and the back end generates the target code from
this intermediate representation.
 The use of a machine independent intermediate
code (IC) is:
 retargeting to another machine is facilitated
 the optimization can be done on the machine independent
code
4
Overview
 Intermediate representations span the gap between
the source and target languages:
 closer to target language;
 (more or less) machine independent;
 allows many optimizations to be done in a machine-independent way.
 Implementable via syntax directed translation, so
can be folded into the parsing process.
Intermediate Representations
 Decisions in IR design affect the speed and
efficiency of the compiler
 Some important IR properties
 Ease of generation
 Ease of manipulation
 Procedure size
 Level of abstraction
 The importance of different properties varies
between compilers
 Selecting an appropriate IR for a compiler is
critical
5
6
Types of Intermediate Languages
 High Level Representations (e.g., syntax trees):
 closer to the source language
 easy to generate from an input program
 code optimizations may not be straightforward.
 Low Level Representations (e.g., 3-address
code)
 closer to the target machine;
 easier for optimizations, final code generation;
Intermediate Code Generation
 Intermediate language can be many different languages, and the
designer of the compiler decides this intermediate language.
 Syntax tree can be used as an intermediate language.
 Postfix notation can be used as an intermediate language.
 Three-address code (Quadraples) can be used as an
intermediate language
 We will use three address to discuss intermediate code
generation.
 Three address are close to machine instructions, but they
are not actual machine instructions.
 Some programming languages have well defined intermediate
languages.
7
8
Syntax Trees
A syntax tree shows the structure of a program by abstracting
away irrelevant details from a parse tree.
 Each node represents a computation to be performed;
 The children of the node represents what that computation is
performed on.
 Syntax trees decouple parsing from subsequent
processing.
9
Syntax Trees: Example
Grammar :
E  E + T | T
T  T * F | F
F  ( E ) | id
Input: id + id * id
Parse tree:
Syntax tree:
10
Syntax Trees: Structure
 Expressions:
 leaves: identifiers or constants;
 internal nodes are labeled with operators;
 the children of a node are its operands.
 Statements:
 a node’s label indicates what kind of
statement it is;
 the children correspond to the components
of the statement.
Syntax Tree
 While parsing the input, a syntax tree can be constructed.
 A syntax tree (abstract tree) is a condensed form of parse tree
useful for representing language constructs.
 For example, for the string a + b, the parse tree in (a) below can
be represented by the syntax tree shown in (b);
 the keywords (syntactic sugar) that existed in the parse tree will
no longer exist in the syntax tree.
11
E
E
E
+
a b
Parse
tree
+
a b
Abstract
tree
Three-Address Code
 A three address code is: x := y op z
where x, y and z are names, constants or compiler-
generated temporaries; op is any operator.
 But we may also use the following notation for three
address code (much better notation because it looks like
a machine code instruction)
 op y, z, x apply operator op to y and z, and store the
result in x.
 We use the term “three-address code” because each
statement usually contains three addresses (two for
operands, one for the result).
12
Three-Address Code
13
a:= b * -c + b * -c
t1 := - c
t2 := b * t1
t3 := - c
t4 := b * t3
t5 := t2 + t4
a := t5
t1 := - c
t2 := b * t1
t5 := t2 + t2
a := t5
Postfix Notation
 Postfix notation is a linear representation of a syntax tree.
 In the postfix notation, any expression can be written
unambiguously without parentheses
 In postfix notation, the operator appears after the operands,
i.e., the operator between operands is taken out & is attached
after operands.
 Example : Translate a ∗ d − (b + c) into Postfix form.
Solution
ad ∗ bc + −
Three-Address Code…
 In three-address code:
 Only one operator at the right side of the
assignment is possible, i.e. x + y * z is not
possible.
 Similar to postfix notation, the three address
code is a linear representation of a syntax tree.
 It has been given the name three-address code
because such an instruction usually contains
three addresses (the two operands and the result)
t1 = y * z
t2 = x + t1 15
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
Example-1
 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 t2
t1
b t4
t3
t2 t5
t4
t5 a
arg1 result
arg2
op
Quadruples
minus
*
minus c
*
+
=
c
b (0)
b (2)
(1) (3)
a
arg1 arg2
op
Triples
(4)
0
1
2
3
4
5
minus
*
minus c
*
+
=
c
b (0)
b (2)
(1) (3)
a
arg1 arg2
op
Indirect Triples
(4)
0
1
2
3
4
5
(0)
(1)
(2)
(3)
(4)
(5)
op
35
36
37
38
39
40
Example continued…
 Construct quadruple and triple for the following
equation:(a+b) * ( c+ d) - ( a+ b+ c) three Address code:
 a. Quadruple
b. triples
op arg1 arg2 result
+ a b t1
+ c d t2
* t1 t2 t3
+ t1 c t4
- t3 t4 t5 op arg1 arg2
+ a b
+ c d
* (0) (1)
+ (0) c
- (2) (3)

More Related Content

Similar to Compiler chapter six .ppt course material

Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
RamchandraRegmi
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
Vipul Naik
 
Intermediate code representations
Intermediate code representationsIntermediate code representations
Intermediate code representations
ahmed51236
 
Chapter 6 Intermediate Code Generation
Chapter 6   Intermediate Code GenerationChapter 6   Intermediate Code Generation
Chapter 6 Intermediate Code Generation
Radhakrishnan Chinnusamy
 
Cs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer KeyCs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer Key
appasami
 
Compiler notes--unit-iii
Compiler notes--unit-iiiCompiler notes--unit-iii
Compiler notes--unit-iii
Sumathi Gnanasekaran
 
Lecture 21 22
Lecture 21 22Lecture 21 22
Lecture 21 22
Najmul Hassan
 
Assignment12
Assignment12Assignment12
Assignment12
Sunita Milind Dol
 
Presentation(intermediate code generation)
Presentation(intermediate code generation)Presentation(intermediate code generation)
Presentation(intermediate code generation)
Sourov Kumar Ron
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
Kuppusamy P
 
Chapter Eight(1)
Chapter Eight(1)Chapter Eight(1)
Chapter Eight(1)
bolovv
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
Shashwat Shriparv
 
1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf
SemsemSameer1
 
3.5
3.53.5
CC Week 11.ppt
CC Week 11.pptCC Week 11.ppt
CC Week 11.ppt
KamranAli649587
 
Compilers Design
Compilers DesignCompilers Design
Compilers Design
Akshaya Arunan
 
Intermediate code generator.pptx
Intermediate code generator.pptxIntermediate code generator.pptx
Intermediate code generator.pptx
gaurav728089
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)
bolovv
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computer
Shankar Gangaju
 
gayathri.p.pptx
gayathri.p.pptxgayathri.p.pptx
gayathri.p.pptx
GayathriP95
 

Similar to Compiler chapter six .ppt course material (20)

Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
Intermediate code representations
Intermediate code representationsIntermediate code representations
Intermediate code representations
 
Chapter 6 Intermediate Code Generation
Chapter 6   Intermediate Code GenerationChapter 6   Intermediate Code Generation
Chapter 6 Intermediate Code Generation
 
Cs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer KeyCs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer Key
 
Compiler notes--unit-iii
Compiler notes--unit-iiiCompiler notes--unit-iii
Compiler notes--unit-iii
 
Lecture 21 22
Lecture 21 22Lecture 21 22
Lecture 21 22
 
Assignment12
Assignment12Assignment12
Assignment12
 
Presentation(intermediate code generation)
Presentation(intermediate code generation)Presentation(intermediate code generation)
Presentation(intermediate code generation)
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
 
Chapter Eight(1)
Chapter Eight(1)Chapter Eight(1)
Chapter Eight(1)
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
 
1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf
 
3.5
3.53.5
3.5
 
CC Week 11.ppt
CC Week 11.pptCC Week 11.ppt
CC Week 11.ppt
 
Compilers Design
Compilers DesignCompilers Design
Compilers Design
 
Intermediate code generator.pptx
Intermediate code generator.pptxIntermediate code generator.pptx
Intermediate code generator.pptx
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computer
 
gayathri.p.pptx
gayathri.p.pptxgayathri.p.pptx
gayathri.p.pptx
 

More from gadisaAdamu

Computer Organization and architecturech5.pptx
Computer Organization and architecturech5.pptxComputer Organization and architecturech5.pptx
Computer Organization and architecturech5.pptx
gadisaAdamu
 
Computer organization and aChapter 2.pptx
Computer organization and aChapter 2.pptxComputer organization and aChapter 2.pptx
Computer organization and aChapter 2.pptx
gadisaAdamu
 
Intoduction to Computer Appl 1st_coa.pptx
Intoduction to Computer  Appl 1st_coa.pptxIntoduction to Computer  Appl 1st_coa.pptx
Intoduction to Computer Appl 1st_coa.pptx
gadisaAdamu
 
Computer Organization and archi. Chapter 1.pptx
Computer Organization and archi. Chapter 1.pptxComputer Organization and archi. Chapter 1.pptx
Computer Organization and archi. Chapter 1.pptx
gadisaAdamu
 
Computer Organization and ArchitectureCh 4 MARIE(PPT).pdf
Computer Organization and ArchitectureCh 4 MARIE(PPT).pdfComputer Organization and ArchitectureCh 4 MARIE(PPT).pdf
Computer Organization and ArchitectureCh 4 MARIE(PPT).pdf
gadisaAdamu
 
Chapter 1. Introduction to Software Engineering.pptx
Chapter 1. Introduction to Software Engineering.pptxChapter 1. Introduction to Software Engineering.pptx
Chapter 1. Introduction to Software Engineering.pptx
gadisaAdamu
 
Chapter_2_Software_Development_Life_Cycle_and_Process_Models.pptx
Chapter_2_Software_Development_Life_Cycle_and_Process_Models.pptxChapter_2_Software_Development_Life_Cycle_and_Process_Models.pptx
Chapter_2_Software_Development_Life_Cycle_and_Process_Models.pptx
gadisaAdamu
 
Chapter 4 Software Project Planning.pptx
Chapter 4 Software Project Planning.pptxChapter 4 Software Project Planning.pptx
Chapter 4 Software Project Planning.pptx
gadisaAdamu
 
Chapter 5 Software Design of software engineering.pptx
Chapter 5 Software Design of software engineering.pptxChapter 5 Software Design of software engineering.pptx
Chapter 5 Software Design of software engineering.pptx
gadisaAdamu
 
Chapter 7 - Resource Monitoring & Management.ppt
Chapter 7 - Resource Monitoring & Management.pptChapter 7 - Resource Monitoring & Management.ppt
Chapter 7 - Resource Monitoring & Management.ppt
gadisaAdamu
 
Chapter_2_Network_Operating_System_NOS_and_Windows_Network_Concepts.pptx
Chapter_2_Network_Operating_System_NOS_and_Windows_Network_Concepts.pptxChapter_2_Network_Operating_System_NOS_and_Windows_Network_Concepts.pptx
Chapter_2_Network_Operating_System_NOS_and_Windows_Network_Concepts.pptx
gadisaAdamu
 
Chapter 8 - nsa Introduction to Linux.ppt
Chapter 8 -  nsa Introduction to Linux.pptChapter 8 -  nsa Introduction to Linux.ppt
Chapter 8 - nsa Introduction to Linux.ppt
gadisaAdamu
 
Derartu Habtamu research Presentation.pptx
Derartu Habtamu  research Presentation.pptxDerartu Habtamu  research Presentation.pptx
Derartu Habtamu research Presentation.pptx
gadisaAdamu
 
Chapter five software Software Design.pptx
Chapter five software  Software Design.pptxChapter five software  Software Design.pptx
Chapter five software Software Design.pptx
gadisaAdamu
 
OSI open system interconnection LAYERS.pdf
OSI open system interconnection LAYERS.pdfOSI open system interconnection LAYERS.pdf
OSI open system interconnection LAYERS.pdf
gadisaAdamu
 
computer network and chapter 7 OSI layers.pptx
computer network and chapter 7 OSI layers.pptxcomputer network and chapter 7 OSI layers.pptx
computer network and chapter 7 OSI layers.pptx
gadisaAdamu
 
IP Address in data communication and computer notework.ppt
IP Address in data communication and computer notework.pptIP Address in data communication and computer notework.ppt
IP Address in data communication and computer notework.ppt
gadisaAdamu
 
ERROR DETECTION data communication and computer network.pptx
ERROR DETECTION data communication and computer network.pptxERROR DETECTION data communication and computer network.pptx
ERROR DETECTION data communication and computer network.pptx
gadisaAdamu
 
Ch1Intro.pdf Computer organization and org.
Ch1Intro.pdf Computer organization and org.Ch1Intro.pdf Computer organization and org.
Ch1Intro.pdf Computer organization and org.
gadisaAdamu
 
Computer application-chapter four lecture note. pptx
Computer application-chapter four lecture note. pptxComputer application-chapter four lecture note. pptx
Computer application-chapter four lecture note. pptx
gadisaAdamu
 

More from gadisaAdamu (20)

Computer Organization and architecturech5.pptx
Computer Organization and architecturech5.pptxComputer Organization and architecturech5.pptx
Computer Organization and architecturech5.pptx
 
Computer organization and aChapter 2.pptx
Computer organization and aChapter 2.pptxComputer organization and aChapter 2.pptx
Computer organization and aChapter 2.pptx
 
Intoduction to Computer Appl 1st_coa.pptx
Intoduction to Computer  Appl 1st_coa.pptxIntoduction to Computer  Appl 1st_coa.pptx
Intoduction to Computer Appl 1st_coa.pptx
 
Computer Organization and archi. Chapter 1.pptx
Computer Organization and archi. Chapter 1.pptxComputer Organization and archi. Chapter 1.pptx
Computer Organization and archi. Chapter 1.pptx
 
Computer Organization and ArchitectureCh 4 MARIE(PPT).pdf
Computer Organization and ArchitectureCh 4 MARIE(PPT).pdfComputer Organization and ArchitectureCh 4 MARIE(PPT).pdf
Computer Organization and ArchitectureCh 4 MARIE(PPT).pdf
 
Chapter 1. Introduction to Software Engineering.pptx
Chapter 1. Introduction to Software Engineering.pptxChapter 1. Introduction to Software Engineering.pptx
Chapter 1. Introduction to Software Engineering.pptx
 
Chapter_2_Software_Development_Life_Cycle_and_Process_Models.pptx
Chapter_2_Software_Development_Life_Cycle_and_Process_Models.pptxChapter_2_Software_Development_Life_Cycle_and_Process_Models.pptx
Chapter_2_Software_Development_Life_Cycle_and_Process_Models.pptx
 
Chapter 4 Software Project Planning.pptx
Chapter 4 Software Project Planning.pptxChapter 4 Software Project Planning.pptx
Chapter 4 Software Project Planning.pptx
 
Chapter 5 Software Design of software engineering.pptx
Chapter 5 Software Design of software engineering.pptxChapter 5 Software Design of software engineering.pptx
Chapter 5 Software Design of software engineering.pptx
 
Chapter 7 - Resource Monitoring & Management.ppt
Chapter 7 - Resource Monitoring & Management.pptChapter 7 - Resource Monitoring & Management.ppt
Chapter 7 - Resource Monitoring & Management.ppt
 
Chapter_2_Network_Operating_System_NOS_and_Windows_Network_Concepts.pptx
Chapter_2_Network_Operating_System_NOS_and_Windows_Network_Concepts.pptxChapter_2_Network_Operating_System_NOS_and_Windows_Network_Concepts.pptx
Chapter_2_Network_Operating_System_NOS_and_Windows_Network_Concepts.pptx
 
Chapter 8 - nsa Introduction to Linux.ppt
Chapter 8 -  nsa Introduction to Linux.pptChapter 8 -  nsa Introduction to Linux.ppt
Chapter 8 - nsa Introduction to Linux.ppt
 
Derartu Habtamu research Presentation.pptx
Derartu Habtamu  research Presentation.pptxDerartu Habtamu  research Presentation.pptx
Derartu Habtamu research Presentation.pptx
 
Chapter five software Software Design.pptx
Chapter five software  Software Design.pptxChapter five software  Software Design.pptx
Chapter five software Software Design.pptx
 
OSI open system interconnection LAYERS.pdf
OSI open system interconnection LAYERS.pdfOSI open system interconnection LAYERS.pdf
OSI open system interconnection LAYERS.pdf
 
computer network and chapter 7 OSI layers.pptx
computer network and chapter 7 OSI layers.pptxcomputer network and chapter 7 OSI layers.pptx
computer network and chapter 7 OSI layers.pptx
 
IP Address in data communication and computer notework.ppt
IP Address in data communication and computer notework.pptIP Address in data communication and computer notework.ppt
IP Address in data communication and computer notework.ppt
 
ERROR DETECTION data communication and computer network.pptx
ERROR DETECTION data communication and computer network.pptxERROR DETECTION data communication and computer network.pptx
ERROR DETECTION data communication and computer network.pptx
 
Ch1Intro.pdf Computer organization and org.
Ch1Intro.pdf Computer organization and org.Ch1Intro.pdf Computer organization and org.
Ch1Intro.pdf Computer organization and org.
 
Computer application-chapter four lecture note. pptx
Computer application-chapter four lecture note. pptxComputer application-chapter four lecture note. pptx
Computer application-chapter four lecture note. pptx
 

Recently uploaded

Timeless Principles of Good Design
Timeless Principles of Good DesignTimeless Principles of Good Design
Timeless Principles of Good Design
Carolina de Bartolo
 
Impact of Fonts: in Web and Apps Design
Impact of Fonts:  in Web and Apps DesignImpact of Fonts:  in Web and Apps Design
Impact of Fonts: in Web and Apps Design
contactproperweb2014
 
Divertidamente SLIDE.pptxufururururuhrurid8dj
Divertidamente SLIDE.pptxufururururuhrurid8djDivertidamente SLIDE.pptxufururururuhrurid8dj
Divertidamente SLIDE.pptxufururururuhrurid8dj
lunaemel03
 
UNIT V ACTIONS AND COMMANDS, FORMS AND CONTROLS.pptx
UNIT V ACTIONS AND COMMANDS, FORMS AND CONTROLS.pptxUNIT V ACTIONS AND COMMANDS, FORMS AND CONTROLS.pptx
UNIT V ACTIONS AND COMMANDS, FORMS AND CONTROLS.pptx
GOWSIKRAJA PALANISAMY
 
Technoblade The Legacy of a Minecraft Legend.
Technoblade The Legacy of a Minecraft Legend.Technoblade The Legacy of a Minecraft Legend.
Technoblade The Legacy of a Minecraft Legend.
Techno Merch
 
CocaCola_Brand_equity_package_2012__.pdf
CocaCola_Brand_equity_package_2012__.pdfCocaCola_Brand_equity_package_2012__.pdf
CocaCola_Brand_equity_package_2012__.pdf
PabloMartelLpez
 
Top Interior Designers in Bangalore.pdf1
Top Interior Designers in Bangalore.pdf1Top Interior Designers in Bangalore.pdf1
Top Interior Designers in Bangalore.pdf1
Decomart Studio
 
一比一原版(BU毕业证)波士顿大学毕业证如何办理
一比一原版(BU毕业证)波士顿大学毕业证如何办理一比一原版(BU毕业证)波士顿大学毕业证如何办理
一比一原版(BU毕业证)波士顿大学毕业证如何办理
peuce
 
一比一原版(LSBU毕业证书)伦敦南岸大学毕业证如何办理
一比一原版(LSBU毕业证书)伦敦南岸大学毕业证如何办理一比一原版(LSBU毕业证书)伦敦南岸大学毕业证如何办理
一比一原版(LSBU毕业证书)伦敦南岸大学毕业证如何办理
k7nm6tk
 
Virtual Tour Application Powerpoint for museum of edinburgh
Virtual Tour Application Powerpoint for museum of edinburghVirtual Tour Application Powerpoint for museum of edinburgh
Virtual Tour Application Powerpoint for museum of edinburgh
millarj46
 
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
pmgdscunsri
 
Heuristics Evaluation - How to Guide.pdf
Heuristics Evaluation - How to Guide.pdfHeuristics Evaluation - How to Guide.pdf
Heuristics Evaluation - How to Guide.pdf
Jaime Brown
 
Practical eLearning Makeovers for Everyone
Practical eLearning Makeovers for EveryonePractical eLearning Makeovers for Everyone
Practical eLearning Makeovers for Everyone
Bianca Woods
 
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
kecekev
 
Graphic Design Tools and Software .pptx
Graphic Design Tools and Software   .pptxGraphic Design Tools and Software   .pptx
Graphic Design Tools and Software .pptx
Virtual Real Design
 
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdfAHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
talaatahm
 
Connect Conference 2022: Passive House - Economic and Environmental Solution...
Connect Conference 2022: Passive House -  Economic and Environmental Solution...Connect Conference 2022: Passive House -  Economic and Environmental Solution...
Connect Conference 2022: Passive House - Economic and Environmental Solution...
TE Studio
 
EASY TUTORIAL OF HOW TO USE CAPCUT BY: FEBLESS HERNANE
EASY TUTORIAL OF HOW TO USE CAPCUT BY: FEBLESS HERNANEEASY TUTORIAL OF HOW TO USE CAPCUT BY: FEBLESS HERNANE
EASY TUTORIAL OF HOW TO USE CAPCUT BY: FEBLESS HERNANE
Febless Hernane
 
哪里办理美国中央华盛顿大学毕业证双学位证书原版一模一样
哪里办理美国中央华盛顿大学毕业证双学位证书原版一模一样哪里办理美国中央华盛顿大学毕业证双学位证书原版一模一样
哪里办理美国中央华盛顿大学毕业证双学位证书原版一模一样
qo1as76n
 
Revolutionizing the Digital Landscape: Web Development Companies in India
Revolutionizing the Digital Landscape: Web Development Companies in IndiaRevolutionizing the Digital Landscape: Web Development Companies in India
Revolutionizing the Digital Landscape: Web Development Companies in India
amrsoftec1
 

Recently uploaded (20)

Timeless Principles of Good Design
Timeless Principles of Good DesignTimeless Principles of Good Design
Timeless Principles of Good Design
 
Impact of Fonts: in Web and Apps Design
Impact of Fonts:  in Web and Apps DesignImpact of Fonts:  in Web and Apps Design
Impact of Fonts: in Web and Apps Design
 
Divertidamente SLIDE.pptxufururururuhrurid8dj
Divertidamente SLIDE.pptxufururururuhrurid8djDivertidamente SLIDE.pptxufururururuhrurid8dj
Divertidamente SLIDE.pptxufururururuhrurid8dj
 
UNIT V ACTIONS AND COMMANDS, FORMS AND CONTROLS.pptx
UNIT V ACTIONS AND COMMANDS, FORMS AND CONTROLS.pptxUNIT V ACTIONS AND COMMANDS, FORMS AND CONTROLS.pptx
UNIT V ACTIONS AND COMMANDS, FORMS AND CONTROLS.pptx
 
Technoblade The Legacy of a Minecraft Legend.
Technoblade The Legacy of a Minecraft Legend.Technoblade The Legacy of a Minecraft Legend.
Technoblade The Legacy of a Minecraft Legend.
 
CocaCola_Brand_equity_package_2012__.pdf
CocaCola_Brand_equity_package_2012__.pdfCocaCola_Brand_equity_package_2012__.pdf
CocaCola_Brand_equity_package_2012__.pdf
 
Top Interior Designers in Bangalore.pdf1
Top Interior Designers in Bangalore.pdf1Top Interior Designers in Bangalore.pdf1
Top Interior Designers in Bangalore.pdf1
 
一比一原版(BU毕业证)波士顿大学毕业证如何办理
一比一原版(BU毕业证)波士顿大学毕业证如何办理一比一原版(BU毕业证)波士顿大学毕业证如何办理
一比一原版(BU毕业证)波士顿大学毕业证如何办理
 
一比一原版(LSBU毕业证书)伦敦南岸大学毕业证如何办理
一比一原版(LSBU毕业证书)伦敦南岸大学毕业证如何办理一比一原版(LSBU毕业证书)伦敦南岸大学毕业证如何办理
一比一原版(LSBU毕业证书)伦敦南岸大学毕业证如何办理
 
Virtual Tour Application Powerpoint for museum of edinburgh
Virtual Tour Application Powerpoint for museum of edinburghVirtual Tour Application Powerpoint for museum of edinburgh
Virtual Tour Application Powerpoint for museum of edinburgh
 
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
 
Heuristics Evaluation - How to Guide.pdf
Heuristics Evaluation - How to Guide.pdfHeuristics Evaluation - How to Guide.pdf
Heuristics Evaluation - How to Guide.pdf
 
Practical eLearning Makeovers for Everyone
Practical eLearning Makeovers for EveryonePractical eLearning Makeovers for Everyone
Practical eLearning Makeovers for Everyone
 
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
 
Graphic Design Tools and Software .pptx
Graphic Design Tools and Software   .pptxGraphic Design Tools and Software   .pptx
Graphic Design Tools and Software .pptx
 
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdfAHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
 
Connect Conference 2022: Passive House - Economic and Environmental Solution...
Connect Conference 2022: Passive House -  Economic and Environmental Solution...Connect Conference 2022: Passive House -  Economic and Environmental Solution...
Connect Conference 2022: Passive House - Economic and Environmental Solution...
 
EASY TUTORIAL OF HOW TO USE CAPCUT BY: FEBLESS HERNANE
EASY TUTORIAL OF HOW TO USE CAPCUT BY: FEBLESS HERNANEEASY TUTORIAL OF HOW TO USE CAPCUT BY: FEBLESS HERNANE
EASY TUTORIAL OF HOW TO USE CAPCUT BY: FEBLESS HERNANE
 
哪里办理美国中央华盛顿大学毕业证双学位证书原版一模一样
哪里办理美国中央华盛顿大学毕业证双学位证书原版一模一样哪里办理美国中央华盛顿大学毕业证双学位证书原版一模一样
哪里办理美国中央华盛顿大学毕业证双学位证书原版一模一样
 
Revolutionizing the Digital Landscape: Web Development Companies in India
Revolutionizing the Digital Landscape: Web Development Companies in IndiaRevolutionizing the Digital Landscape: Web Development Companies in India
Revolutionizing the Digital Landscape: Web Development Companies in India
 

Compiler chapter six .ppt course material

  • 1. Chapter six Intermediate Code Generation Rift valley University Harar Campus
  • 2. Overview  Intermediate code is the interface between front end and back end in a compiler.  Ideally the details of source language are confined to the front end and the details of target machines to the back end (a machine model)  This intermediate code serves as a bridge between the high-level source code and the final machine code or another target language.
  • 3. 3 Overview  In a compiler, the front end translates source program into an intermediate representation,  and the back end generates the target code from this intermediate representation.  The use of a machine independent intermediate code (IC) is:  retargeting to another machine is facilitated  the optimization can be done on the machine independent code
  • 4. 4 Overview  Intermediate representations span the gap between the source and target languages:  closer to target language;  (more or less) machine independent;  allows many optimizations to be done in a machine-independent way.  Implementable via syntax directed translation, so can be folded into the parsing process.
  • 5. Intermediate Representations  Decisions in IR design affect the speed and efficiency of the compiler  Some important IR properties  Ease of generation  Ease of manipulation  Procedure size  Level of abstraction  The importance of different properties varies between compilers  Selecting an appropriate IR for a compiler is critical 5
  • 6. 6 Types of Intermediate Languages  High Level Representations (e.g., syntax trees):  closer to the source language  easy to generate from an input program  code optimizations may not be straightforward.  Low Level Representations (e.g., 3-address code)  closer to the target machine;  easier for optimizations, final code generation;
  • 7. Intermediate Code Generation  Intermediate language can be many different languages, and the designer of the compiler decides this intermediate language.  Syntax tree can be used as an intermediate language.  Postfix notation can be used as an intermediate language.  Three-address code (Quadraples) can be used as an intermediate language  We will use three address to discuss intermediate code generation.  Three address are close to machine instructions, but they are not actual machine instructions.  Some programming languages have well defined intermediate languages. 7
  • 8. 8 Syntax Trees A syntax tree shows the structure of a program by abstracting away irrelevant details from a parse tree.  Each node represents a computation to be performed;  The children of the node represents what that computation is performed on.  Syntax trees decouple parsing from subsequent processing.
  • 9. 9 Syntax Trees: Example Grammar : E  E + T | T T  T * F | F F  ( E ) | id Input: id + id * id Parse tree: Syntax tree:
  • 10. 10 Syntax Trees: Structure  Expressions:  leaves: identifiers or constants;  internal nodes are labeled with operators;  the children of a node are its operands.  Statements:  a node’s label indicates what kind of statement it is;  the children correspond to the components of the statement.
  • 11. Syntax Tree  While parsing the input, a syntax tree can be constructed.  A syntax tree (abstract tree) is a condensed form of parse tree useful for representing language constructs.  For example, for the string a + b, the parse tree in (a) below can be represented by the syntax tree shown in (b);  the keywords (syntactic sugar) that existed in the parse tree will no longer exist in the syntax tree. 11 E E E + a b Parse tree + a b Abstract tree
  • 12. Three-Address Code  A three address code is: x := y op z where x, y and z are names, constants or compiler- generated temporaries; op is any operator.  But we may also use the following notation for three address code (much better notation because it looks like a machine code instruction)  op y, z, x apply operator op to y and z, and store the result in x.  We use the term “three-address code” because each statement usually contains three addresses (two for operands, one for the result). 12
  • 13. Three-Address Code 13 a:= b * -c + b * -c t1 := - c t2 := b * t1 t3 := - c t4 := b * t3 t5 := t2 + t4 a := t5 t1 := - c t2 := b * t1 t5 := t2 + t2 a := t5
  • 14. Postfix Notation  Postfix notation is a linear representation of a syntax tree.  In the postfix notation, any expression can be written unambiguously without parentheses  In postfix notation, the operator appears after the operands, i.e., the operator between operands is taken out & is attached after operands.  Example : Translate a ∗ d − (b + c) into Postfix form. Solution ad ∗ bc + −
  • 15. Three-Address Code…  In three-address code:  Only one operator at the right side of the assignment is possible, i.e. x + y * z is not possible.  Similar to postfix notation, the three address code is a linear representation of a syntax tree.  It has been given the name three-address code because such an instruction usually contains three addresses (the two operands and the result) t1 = y * z t2 = x + t1 15
  • 16. 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
  • 17. Example-1  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 t2 t1 b t4 t3 t2 t5 t4 t5 a arg1 result arg2 op Quadruples minus * minus c * + = c b (0) b (2) (1) (3) a arg1 arg2 op Triples (4) 0 1 2 3 4 5 minus * minus c * + = c b (0) b (2) (1) (3) a arg1 arg2 op Indirect Triples (4) 0 1 2 3 4 5 (0) (1) (2) (3) (4) (5) op 35 36 37 38 39 40
  • 18. Example continued…  Construct quadruple and triple for the following equation:(a+b) * ( c+ d) - ( a+ b+ c) three Address code:  a. Quadruple b. triples op arg1 arg2 result + a b t1 + c d t2 * t1 t2 t3 + t1 c t4 - t3 t4 t5 op arg1 arg2 + a b + c d * (0) (1) + (0) c - (2) (3)

Editor's Notes

  1. 7