SlideShare a Scribd company logo
1 of 19
Presented by,
M.Selva Vinitha
B.E/CSE
M.Kumarasamy college of engineering
Karur.
Code generator
 Final phase of compiler design
 Optimized intermediate code is provided as input
 It generates target code
9/15/2015 2Issues in design of code generator
Code generation and Instruction Selection
4
Symbol
table
input output
Front
end
Intermediate
Code
generator
Code
generator
9/15/2015 Issues in design of code generator
Contd…
 output code must be correct
 output code must be of high quality
 code generator should run efficiently
9/15/2015 4Issues in design of code generator
Pre-requisites
 Instruction set of target machine.
 Instruction addressing modes.
 No. of registers.
 Configuration of ALU
9/15/2015 5Issues in design of code generator
Issues in the design of a code
generator
 Input to the code generator
 Memory management
 Target programs
 Instruction selection
 Register allocation
 Evaluation order
 Approaches to code generation
9/15/2015 6Issues in design of code generator
Input to the code generator
 The intermediate representation of the source program
produced by the front end
 Several choices for the intermediate language
 Linear - postfix nottion
 3 address - quadruples
 Virtual machie - stack machine code
 Graphical - syntax tree &dags
9/15/2015 7Issues in design of code generator
Memory management
 Mapping names in the source program to addresses of data
objects in run-time memory
 Done by the front end and the code generator.
 A name in a three- address statement refers to a symbol-
table entry for the name.
 A relative address can be determined
9/15/2015 8Issues in design of code generator
Target programs
 Absolute machine language
Relocatable machine language
 Assembly language
9/15/2015 9Issues in design of code generator
Contd..
Absolute machine language:
 Produce an absolute machine language program
 can be placed in a fixed location in memory and
immediately executed.
9/15/2015 10Issues in design of code generator
Contd..
Relocatable machine language:
Producing a relocatable machine language program
subprograms to be compiled separately.
relocatable object modules can be linked together and loaded
for execution by a linking loader.
must provide explicit relocation information to the loader, to
link the separately compiled program segments.
9/15/2015 11Issues in design of code generator
Contd…
Assembly language:
Producing an assembly language program
makes the process of code generation easier
9/15/2015 12Issues in design of code generator
Instruction selection
The factors to be considered during instruction selection are:
 The uniformity and completeness of the instruction set.
 Instruction speed and machine idioms.
 Size of the instruction set.
9/15/2015 13Issues in design of code generator
Contd…
Eg., for the following address code is:
a := b + c
d := a + e
inefficient assembly code is:
MOV b, R0 R0 ← b
ADD c, R0 R0 ← c + R0
MOV R0, a a ← R0
MOV a, R0 R0 ← a
ADD e, R0 R0 ← e + R0
MOV R0 , d d ← R0
Here the fourth statement is redundant, and so is the third
statement if ,
'a' is not subsequently used.
9/15/2015 14Issues in design of code generator
Register allocation
• Instructions with register operands are usually shorter and
faster
• Efficient utilization of registers is important in
generating good code.
9/15/2015 15Issues in design of code generator
Contd..
Register allocation phase:
• Select the set of variables that will reside in registers
Register assignment phase:
• Pick the specific register that a variable will reside in.
9/15/2015 16Issues in design of code generator
Evaluation order
 The order in which computations are performed
 Affect the efficiency of the target code.
 Some computation orders require fewer registers to hold
intermediate results
9/15/2015 17Issues in design of code generator
Approaches to code generation
 Most important criteria for code generator is that it
produces correct code
 Correctness takes on special signification
 It contains a straightforward code generation algorithm
 The output of such code generator can be improved by
peephole optimization technique
9/15/2015 18Issues in design of code generator
Conclusion
Output of code generator phase is dependent on:
 Target language
 Operating system
 Memory management system
 Instruction selection
 Register allocation
 Evaluation order
9/15/2015 19Issues in design of code generator

More Related Content

What's hot (20)

Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Toy compiler
Toy compilerToy compiler
Toy compiler
 
Basic of compiler
Basic of compiler Basic of compiler
Basic of compiler
 
Lec 1 intro
Lec 1 introLec 1 intro
Lec 1 intro
 
Compiler
CompilerCompiler
Compiler
 
Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation
 
Compiler
Compiler Compiler
Compiler
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
Compiler
Compiler Compiler
Compiler
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
 
Toy complier
Toy complierToy complier
Toy complier
 
Assembler
AssemblerAssembler
Assembler
 
Embedded c lab and keil c manual
Embedded  c  lab  and keil c  manualEmbedded  c  lab  and keil c  manual
Embedded c lab and keil c manual
 
Compiler design
Compiler designCompiler design
Compiler design
 
Compilation of c
Compilation of cCompilation of c
Compilation of c
 
C_Programming_Notes_ICE
C_Programming_Notes_ICEC_Programming_Notes_ICE
C_Programming_Notes_ICE
 
COMPILER DESIGN- Introduction & Lexical Analysis:
COMPILER DESIGN- Introduction & Lexical Analysis: COMPILER DESIGN- Introduction & Lexical Analysis:
COMPILER DESIGN- Introduction & Lexical Analysis:
 
Phases of-compiler
Phases of-compilerPhases of-compiler
Phases of-compiler
 
Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 

Similar to issuesindesignofcodegenerator-150227091230-conversion-gate01

Reversing and Patching Machine Code
Reversing and Patching Machine CodeReversing and Patching Machine Code
Reversing and Patching Machine CodeTeodoro Cipresso
 
Leveraging REST APIs for Infrastructure Management using FME
Leveraging REST APIs for Infrastructure Management using FMELeveraging REST APIs for Infrastructure Management using FME
Leveraging REST APIs for Infrastructure Management using FMESafe Software
 
SAPTechED 2015 UX114 -Building custom SAP Fiori Apps Using SAP Web IDE
SAPTechED 2015 UX114 -Building custom SAP Fiori Apps Using SAP Web IDESAPTechED 2015 UX114 -Building custom SAP Fiori Apps Using SAP Web IDE
SAPTechED 2015 UX114 -Building custom SAP Fiori Apps Using SAP Web IDEMarkus Van Kempen
 
IRJET- Build a Secure Web based Code Editor for C Programming Language
IRJET-  	  Build a Secure Web based Code Editor for C Programming LanguageIRJET-  	  Build a Secure Web based Code Editor for C Programming Language
IRJET- Build a Secure Web based Code Editor for C Programming LanguageIRJET Journal
 
Review Paper on Online Java Compiler
Review Paper on Online Java CompilerReview Paper on Online Java Compiler
Review Paper on Online Java CompilerIRJET Journal
 
How NBCUniversal Adopted DevOps
How NBCUniversal Adopted DevOpsHow NBCUniversal Adopted DevOps
How NBCUniversal Adopted DevOpsSanjeev Sharma
 
UrbanCode Deploy course and product overview slides
UrbanCode Deploy course and product overview slidesUrbanCode Deploy course and product overview slides
UrbanCode Deploy course and product overview slidesIBM Rational software
 
Indy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleIndy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleikram_ahamed
 
Auto conversion of serial C code to CUDA code
Auto conversion of serial C code to CUDA codeAuto conversion of serial C code to CUDA code
Auto conversion of serial C code to CUDA codeIRJET Journal
 
Rhapsody Software
Rhapsody SoftwareRhapsody Software
Rhapsody SoftwareBill Duncan
 
AngularJS: Service, factory & provider
AngularJS: Service, factory & providerAngularJS: Service, factory & provider
AngularJS: Service, factory & providerCorley S.r.l.
 
The process of programming
 The process of programming The process of programming
The process of programmingKopi Maheswaran
 
chapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdfchapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdfBernardVelasco1
 
GPCE16: Automatic Non-functional Testing of Code Generators Families
GPCE16: Automatic Non-functional Testing of Code Generators FamiliesGPCE16: Automatic Non-functional Testing of Code Generators Families
GPCE16: Automatic Non-functional Testing of Code Generators FamiliesMohamed BOUSSAA
 

Similar to issuesindesignofcodegenerator-150227091230-conversion-gate01 (20)

Reversing and Patching Machine Code
Reversing and Patching Machine CodeReversing and Patching Machine Code
Reversing and Patching Machine Code
 
Leveraging REST APIs for Infrastructure Management using FME
Leveraging REST APIs for Infrastructure Management using FMELeveraging REST APIs for Infrastructure Management using FME
Leveraging REST APIs for Infrastructure Management using FME
 
SAPTechED 2015 UX114 -Building custom SAP Fiori Apps Using SAP Web IDE
SAPTechED 2015 UX114 -Building custom SAP Fiori Apps Using SAP Web IDESAPTechED 2015 UX114 -Building custom SAP Fiori Apps Using SAP Web IDE
SAPTechED 2015 UX114 -Building custom SAP Fiori Apps Using SAP Web IDE
 
IRJET- Build a Secure Web based Code Editor for C Programming Language
IRJET-  	  Build a Secure Web based Code Editor for C Programming LanguageIRJET-  	  Build a Secure Web based Code Editor for C Programming Language
IRJET- Build a Secure Web based Code Editor for C Programming Language
 
Compiler design
Compiler designCompiler design
Compiler design
 
Review Paper on Online Java Compiler
Review Paper on Online Java CompilerReview Paper on Online Java Compiler
Review Paper on Online Java Compiler
 
SW_Cost_Estimation.ppt
SW_Cost_Estimation.pptSW_Cost_Estimation.ppt
SW_Cost_Estimation.ppt
 
How NBCUniversal Adopted DevOps
How NBCUniversal Adopted DevOpsHow NBCUniversal Adopted DevOps
How NBCUniversal Adopted DevOps
 
Overview
OverviewOverview
Overview
 
UrbanCode Deploy course and product overview slides
UrbanCode Deploy course and product overview slidesUrbanCode Deploy course and product overview slides
UrbanCode Deploy course and product overview slides
 
Indy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleIndy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-mule
 
Auto conversion of serial C code to CUDA code
Auto conversion of serial C code to CUDA codeAuto conversion of serial C code to CUDA code
Auto conversion of serial C code to CUDA code
 
Unit-2.pptx
Unit-2.pptxUnit-2.pptx
Unit-2.pptx
 
resume
resumeresume
resume
 
Rhapsody Software
Rhapsody SoftwareRhapsody Software
Rhapsody Software
 
AngularJS: Service, factory & provider
AngularJS: Service, factory & providerAngularJS: Service, factory & provider
AngularJS: Service, factory & provider
 
The process of programming
 The process of programming The process of programming
The process of programming
 
chapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdfchapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdf
 
GPCE16: Automatic Non-functional Testing of Code Generators Families
GPCE16: Automatic Non-functional Testing of Code Generators FamiliesGPCE16: Automatic Non-functional Testing of Code Generators Families
GPCE16: Automatic Non-functional Testing of Code Generators Families
 
Active Server Pages .NET
Active Server Pages .NETActive Server Pages .NET
Active Server Pages .NET
 

issuesindesignofcodegenerator-150227091230-conversion-gate01

  • 2. Code generator  Final phase of compiler design  Optimized intermediate code is provided as input  It generates target code 9/15/2015 2Issues in design of code generator
  • 3. Code generation and Instruction Selection 4 Symbol table input output Front end Intermediate Code generator Code generator 9/15/2015 Issues in design of code generator
  • 4. Contd…  output code must be correct  output code must be of high quality  code generator should run efficiently 9/15/2015 4Issues in design of code generator
  • 5. Pre-requisites  Instruction set of target machine.  Instruction addressing modes.  No. of registers.  Configuration of ALU 9/15/2015 5Issues in design of code generator
  • 6. Issues in the design of a code generator  Input to the code generator  Memory management  Target programs  Instruction selection  Register allocation  Evaluation order  Approaches to code generation 9/15/2015 6Issues in design of code generator
  • 7. Input to the code generator  The intermediate representation of the source program produced by the front end  Several choices for the intermediate language  Linear - postfix nottion  3 address - quadruples  Virtual machie - stack machine code  Graphical - syntax tree &dags 9/15/2015 7Issues in design of code generator
  • 8. Memory management  Mapping names in the source program to addresses of data objects in run-time memory  Done by the front end and the code generator.  A name in a three- address statement refers to a symbol- table entry for the name.  A relative address can be determined 9/15/2015 8Issues in design of code generator
  • 9. Target programs  Absolute machine language Relocatable machine language  Assembly language 9/15/2015 9Issues in design of code generator
  • 10. Contd.. Absolute machine language:  Produce an absolute machine language program  can be placed in a fixed location in memory and immediately executed. 9/15/2015 10Issues in design of code generator
  • 11. Contd.. Relocatable machine language: Producing a relocatable machine language program subprograms to be compiled separately. relocatable object modules can be linked together and loaded for execution by a linking loader. must provide explicit relocation information to the loader, to link the separately compiled program segments. 9/15/2015 11Issues in design of code generator
  • 12. Contd… Assembly language: Producing an assembly language program makes the process of code generation easier 9/15/2015 12Issues in design of code generator
  • 13. Instruction selection The factors to be considered during instruction selection are:  The uniformity and completeness of the instruction set.  Instruction speed and machine idioms.  Size of the instruction set. 9/15/2015 13Issues in design of code generator
  • 14. Contd… Eg., for the following address code is: a := b + c d := a + e inefficient assembly code is: MOV b, R0 R0 ← b ADD c, R0 R0 ← c + R0 MOV R0, a a ← R0 MOV a, R0 R0 ← a ADD e, R0 R0 ← e + R0 MOV R0 , d d ← R0 Here the fourth statement is redundant, and so is the third statement if , 'a' is not subsequently used. 9/15/2015 14Issues in design of code generator
  • 15. Register allocation • Instructions with register operands are usually shorter and faster • Efficient utilization of registers is important in generating good code. 9/15/2015 15Issues in design of code generator
  • 16. Contd.. Register allocation phase: • Select the set of variables that will reside in registers Register assignment phase: • Pick the specific register that a variable will reside in. 9/15/2015 16Issues in design of code generator
  • 17. Evaluation order  The order in which computations are performed  Affect the efficiency of the target code.  Some computation orders require fewer registers to hold intermediate results 9/15/2015 17Issues in design of code generator
  • 18. Approaches to code generation  Most important criteria for code generator is that it produces correct code  Correctness takes on special signification  It contains a straightforward code generation algorithm  The output of such code generator can be improved by peephole optimization technique 9/15/2015 18Issues in design of code generator
  • 19. Conclusion Output of code generator phase is dependent on:  Target language  Operating system  Memory management system  Instruction selection  Register allocation  Evaluation order 9/15/2015 19Issues in design of code generator