SlideShare a Scribd company logo
1 of 18
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 generationRamchandraRegmi
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generationVipul Naik
 
Intermediate code representations
Intermediate code representationsIntermediate code representations
Intermediate code representationsahmed51236
 
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 Keyappasami
 
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 DesignKuppusamy P
 
Chapter Eight(1)
Chapter Eight(1)Chapter Eight(1)
Chapter Eight(1)bolovv
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1Shashwat Shriparv
 
1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdf1588147798Begining_ABUAD1.pdf
1588147798Begining_ABUAD1.pdfSemsemSameer1
 
Intermediate code generator.pptx
Intermediate code generator.pptxIntermediate code generator.pptx
Intermediate code generator.pptxgaurav728089
 
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 computerShankar Gangaju
 

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

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.pptxgadisaAdamu
 
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.pptxgadisaAdamu
 
Chapter 4 Software Project Planning.pptx
Chapter 4 Software Project Planning.pptxChapter 4 Software Project Planning.pptx
Chapter 4 Software Project Planning.pptxgadisaAdamu
 
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.pptxgadisaAdamu
 
Chapter 7 - Resource Monitoring & Management.ppt
Chapter 7 - Resource Monitoring & Management.pptChapter 7 - Resource Monitoring & Management.ppt
Chapter 7 - Resource Monitoring & Management.pptgadisaAdamu
 
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.pptxgadisaAdamu
 
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.pptgadisaAdamu
 
Derartu Habtamu research Presentation.pptx
Derartu Habtamu  research Presentation.pptxDerartu Habtamu  research Presentation.pptx
Derartu Habtamu research Presentation.pptxgadisaAdamu
 
Chapter five software Software Design.pptx
Chapter five software  Software Design.pptxChapter five software  Software Design.pptx
Chapter five software Software Design.pptxgadisaAdamu
 
OSI open system interconnection LAYERS.pdf
OSI open system interconnection LAYERS.pdfOSI open system interconnection LAYERS.pdf
OSI open system interconnection LAYERS.pdfgadisaAdamu
 
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.pptxgadisaAdamu
 
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.pptgadisaAdamu
 
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.pptxgadisaAdamu
 
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. pptxgadisaAdamu
 
Computer application lecture note-Chapter-5.pptx
Computer application lecture note-Chapter-5.pptxComputer application lecture note-Chapter-5.pptx
Computer application lecture note-Chapter-5.pptxgadisaAdamu
 
Chapter 03-Number System-Computer Application.pptx
Chapter 03-Number System-Computer Application.pptxChapter 03-Number System-Computer Application.pptx
Chapter 03-Number System-Computer Application.pptxgadisaAdamu
 
Chapter one-Introduction to Computer.pptx
Chapter one-Introduction to Computer.pptxChapter one-Introduction to Computer.pptx
Chapter one-Introduction to Computer.pptxgadisaAdamu
 
Chapter Three, four, five and six.ppt ITEtx
Chapter Three, four, five and six.ppt ITEtxChapter Three, four, five and six.ppt ITEtx
Chapter Three, four, five and six.ppt ITEtxgadisaAdamu
 
Chapter One & Two.pptx introduction to emerging Technology
Chapter One & Two.pptx introduction to emerging TechnologyChapter One & Two.pptx introduction to emerging Technology
Chapter One & Two.pptx introduction to emerging TechnologygadisaAdamu
 

More from gadisaAdamu (20)

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
 
Computer application lecture note-Chapter-5.pptx
Computer application lecture note-Chapter-5.pptxComputer application lecture note-Chapter-5.pptx
Computer application lecture note-Chapter-5.pptx
 
Chapter 03-Number System-Computer Application.pptx
Chapter 03-Number System-Computer Application.pptxChapter 03-Number System-Computer Application.pptx
Chapter 03-Number System-Computer Application.pptx
 
Chapter one-Introduction to Computer.pptx
Chapter one-Introduction to Computer.pptxChapter one-Introduction to Computer.pptx
Chapter one-Introduction to Computer.pptx
 
Chapter Three, four, five and six.ppt ITEtx
Chapter Three, four, five and six.ppt ITEtxChapter Three, four, five and six.ppt ITEtx
Chapter Three, four, five and six.ppt ITEtx
 
Chapter One & Two.pptx introduction to emerging Technology
Chapter One & Two.pptx introduction to emerging TechnologyChapter One & Two.pptx introduction to emerging Technology
Chapter One & Two.pptx introduction to emerging Technology
 

Recently uploaded

Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk GurgaonCheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk GurgaonDelhi Call girls
 
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Narsimha murthy
 
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制didi bibo
 
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130Suhani Kapoor
 
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...Suhani Kapoor
 
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...Amil baba
 
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 nightCheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 nightDelhi Call girls
 
3D Printing And Designing Final Report.pdf
3D Printing And Designing Final Report.pdf3D Printing And Designing Final Report.pdf
3D Printing And Designing Final Report.pdfSwaraliBorhade
 
Kieran Salaria Graphic Design PDF Portfolio
Kieran Salaria Graphic Design PDF PortfolioKieran Salaria Graphic Design PDF Portfolio
Kieran Salaria Graphic Design PDF Portfolioktksalaria
 
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...ankitnayak356677
 
SCRIP Lua HTTP PROGRACMACION PLC WECON CA
SCRIP Lua HTTP PROGRACMACION PLC  WECON CASCRIP Lua HTTP PROGRACMACION PLC  WECON CA
SCRIP Lua HTTP PROGRACMACION PLC WECON CANestorGamez6
 
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...babafaisel
 
NATA 2024 SYLLABUS, full syllabus explained in detail
NATA 2024 SYLLABUS, full syllabus explained in detailNATA 2024 SYLLABUS, full syllabus explained in detail
NATA 2024 SYLLABUS, full syllabus explained in detailDesigntroIntroducing
 
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...Pooja Nehwal
 
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiVIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...Suhani Kapoor
 
WAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsWAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsCharles Obaleagbon
 
Fashion trends before and after covid.pptx
Fashion trends before and after covid.pptxFashion trends before and after covid.pptx
Fashion trends before and after covid.pptxVanshNarang19
 
ARt app | UX Case Study
ARt app | UX Case StudyARt app | UX Case Study
ARt app | UX Case StudySophia Viganò
 

Recently uploaded (20)

Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk GurgaonCheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk Gurgaon
 
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
 
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
如何办理(UVa毕业证书)弗吉尼亚大学毕业证毕业证(文凭)成绩单原版一比一定制
 
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
 
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
 
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
 
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 nightCheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
Cheap Rate Call girls Malviya Nagar 9205541914 shot 1500 night
 
young call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Service
young call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Service
young call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Service
 
3D Printing And Designing Final Report.pdf
3D Printing And Designing Final Report.pdf3D Printing And Designing Final Report.pdf
3D Printing And Designing Final Report.pdf
 
Kieran Salaria Graphic Design PDF Portfolio
Kieran Salaria Graphic Design PDF PortfolioKieran Salaria Graphic Design PDF Portfolio
Kieran Salaria Graphic Design PDF Portfolio
 
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...
Raj Nagar Extension Call Girls 9711199012 WhatsApp No, Delhi Escorts in Raj N...
 
SCRIP Lua HTTP PROGRACMACION PLC WECON CA
SCRIP Lua HTTP PROGRACMACION PLC  WECON CASCRIP Lua HTTP PROGRACMACION PLC  WECON CA
SCRIP Lua HTTP PROGRACMACION PLC WECON CA
 
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
 
NATA 2024 SYLLABUS, full syllabus explained in detail
NATA 2024 SYLLABUS, full syllabus explained in detailNATA 2024 SYLLABUS, full syllabus explained in detail
NATA 2024 SYLLABUS, full syllabus explained in detail
 
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...
 
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiVIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
 
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
 
WAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsWAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past Questions
 
Fashion trends before and after covid.pptx
Fashion trends before and after covid.pptxFashion trends before and after covid.pptx
Fashion trends before and after covid.pptx
 
ARt app | UX Case Study
ARt app | UX Case StudyARt app | UX Case Study
ARt app | UX Case Study
 

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