SlideShare uma empresa Scribd logo
1 de 13
Code Generation
- Principles of Compiler Design
Presenter:
PRABU.R
BP150504, II MSC CS,
PG Department of Computer Science,
Sacred Heart College, Tirupattur.
AGENDA
• Introduction
• Issues in the Design of a Code Generation.
Introduction
• It is the final phase in the compiler model.
• Input as a Intermediate representation of the
source program and output as equivalent
target program.
Int. code Int. codeSrc
Progm
Front
end
Code
Optimizer
Code
Generator
Symbol
Table
Target
Progm
Issues in Design of Code Gen.
1. Input to the Code Generator
2. Target Program
3. Memory Management
4. Instruction Section
5. Register Allocation
6. Choices of Evaluation Order
7. Approaches to Code Generation
1. Input to the Code Generator
• The input to the code gen. consists of intermediate
representation of the source program
• Which is produced by the front end, together with info in the
symbol table, used to determine the run time address of
objects denoted by the names in intermediate representation.
• Three several choices for the IL :
– Linear representation such as postfix notation
– Three-address code such as quadruples.
– Graphical representation such as syntax tree and dags.
2. Target Program
• Output of code gen is Target Program.
• Like Intermediate Code, this output also takes many forms:
– Absolute Machine Language
– Relocatable Machine Language
– Assembly Language.
• Producing an absolute ML has the advantage that it can be
placed in a fixed location in memory and immediately
executed.
• Compilers such as WATFIV and PL/C, produces Absolute code.
2. Cont..
• On the other hand while producing relocatable ML, we gain
flexibility that we can call other programs from an object
module.
• Where as while producing assembly language program,
process of code generation is easier.
• We can generate symbolic instructions and use the macro
facilities of the assembler to help generate code.
3. Memory Management
• Mapping names in the source program to addresses of data
objects in run time memory is done cooperatively by the front
end and the code generator.
• We assumed names in a Three address statement refers to
the names in symbol table entry for the name.
• If Machine code is being generated, labels in three address
statement have to be converted to addresses of instruction.
• This process is analogous in Back patching.
4. Instruction Selection
• The nature of instruction set of the target ML determines the
difficulty of instruction selection.
X:=y+z
MOV y,R0
ADD z,R0
MOV R0,x
5. Register Allocation
• The use of register allocation is often subdivided into two sub
problems:
– During register allocation
– During a subsequent register assignment phase.
• Certain machines register pairs
Multiplication: M x,y
Division: D x,y
t:=a+b
t:=t*b
t:=a/b
6. Choices of Evaluation Order
• The order in which computations are performed can affect
the efficiency of the target code.
• Some computation orders requires fewer registers to hold
intermediate results than others.
• Picking a best order is another difficult, NP-complete problem.
7. Approaches to Code Generation
• The most important criterion for a code generator is that it
produce correct code.
• Correctness takes on significance because of the no of special
cases that a code generator might face.
• Given the premium on correctness, designing a code gen so it
can be easily implemented, tested and maintained is an
important design deal.
THANK YOU

Mais conteúdo relacionado

Mais procurados

Issues in the design of Code Generator
Issues in the design of Code GeneratorIssues in the design of Code Generator
Issues in the design of Code GeneratorDarshan sai Reddy
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generationrawan_z
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design) Tasif Tanzim
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compilerIffat Anjum
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler DesignShine Raj
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 
Techniques & applications of Compiler
Techniques & applications of CompilerTechniques & applications of Compiler
Techniques & applications of CompilerPreethi AKNR
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design MAHASREEM
 
Recursive Descent Parsing
Recursive Descent Parsing  Recursive Descent Parsing
Recursive Descent Parsing Md Tajul Islam
 
Three Address code
Three Address code Three Address code
Three Address code Pooja Dixit
 
Loaders ( system programming )
Loaders ( system programming ) Loaders ( system programming )
Loaders ( system programming ) Adarsh Patel
 

Mais procurados (20)

Intermediate code
Intermediate codeIntermediate code
Intermediate code
 
Issues in the design of Code Generator
Issues in the design of Code GeneratorIssues in the design of Code Generator
Issues in the design of Code Generator
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
 
Assembler
AssemblerAssembler
Assembler
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Techniques & applications of Compiler
Techniques & applications of CompilerTechniques & applications of Compiler
Techniques & applications of Compiler
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Compiler design
Compiler designCompiler design
Compiler design
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
 
Recursive Descent Parsing
Recursive Descent Parsing  Recursive Descent Parsing
Recursive Descent Parsing
 
Three Address code
Three Address code Three Address code
Three Address code
 
Loaders ( system programming )
Loaders ( system programming ) Loaders ( system programming )
Loaders ( system programming )
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Instruction format
Instruction formatInstruction format
Instruction format
 

Destaque

Code generator
Code generatorCode generator
Code generatorTech_MX
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generationAkshaya Arunan
 
Mca ii-dbms-u-v-transaction management
Mca ii-dbms-u-v-transaction managementMca ii-dbms-u-v-transaction management
Mca ii-dbms-u-v-transaction managementRai University
 
Directed Acyclic Graph
Directed Acyclic Graph Directed Acyclic Graph
Directed Acyclic Graph AJAL A J
 
SQL Server Transaction Management
SQL Server Transaction ManagementSQL Server Transaction Management
SQL Server Transaction ManagementMark Ginnebaugh
 
Mca ii-dbms- u-i-introductory concepts of dbms
Mca ii-dbms- u-i-introductory concepts of dbmsMca ii-dbms- u-i-introductory concepts of dbms
Mca ii-dbms- u-i-introductory concepts of dbmsRai University
 
The dag representation of basic blocks
The dag representation of basic blocksThe dag representation of basic blocks
The dag representation of basic blocksShabeen Taj
 
Lecture 16 17 code-generation
Lecture 16 17 code-generationLecture 16 17 code-generation
Lecture 16 17 code-generationIffat Anjum
 
Open and closed thermodynamic system
Open and closed thermodynamic systemOpen and closed thermodynamic system
Open and closed thermodynamic systemphysics101
 
Hybrid Cloud Computing (IBM System z)
Hybrid Cloud Computing (IBM System z)Hybrid Cloud Computing (IBM System z)
Hybrid Cloud Computing (IBM System z)IBM Danmark
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)bolovv
 
System software and operating system
System software and operating systemSystem software and operating system
System software and operating systemdhruv bhandari
 
Design And Implementation Of A Bangla Compiler
Design And Implementation Of A Bangla CompilerDesign And Implementation Of A Bangla Compiler
Design And Implementation Of A Bangla CompilerMJ Ferdous
 
code optimization
code optimization code optimization
code optimization Sanjeev Raaz
 
Gcse Forces And Motion
Gcse Forces And MotionGcse Forces And Motion
Gcse Forces And MotionTauseef Khan
 

Destaque (20)

Code generator
Code generatorCode generator
Code generator
 
Normalization
NormalizationNormalization
Normalization
 
Ch8
Ch8Ch8
Ch8
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Mca ii-dbms-u-v-transaction management
Mca ii-dbms-u-v-transaction managementMca ii-dbms-u-v-transaction management
Mca ii-dbms-u-v-transaction management
 
Normalization
NormalizationNormalization
Normalization
 
Directed Acyclic Graph
Directed Acyclic Graph Directed Acyclic Graph
Directed Acyclic Graph
 
SQL Server Transaction Management
SQL Server Transaction ManagementSQL Server Transaction Management
SQL Server Transaction Management
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Mca ii-dbms- u-i-introductory concepts of dbms
Mca ii-dbms- u-i-introductory concepts of dbmsMca ii-dbms- u-i-introductory concepts of dbms
Mca ii-dbms- u-i-introductory concepts of dbms
 
The dag representation of basic blocks
The dag representation of basic blocksThe dag representation of basic blocks
The dag representation of basic blocks
 
Lecture 16 17 code-generation
Lecture 16 17 code-generationLecture 16 17 code-generation
Lecture 16 17 code-generation
 
Open and closed thermodynamic system
Open and closed thermodynamic systemOpen and closed thermodynamic system
Open and closed thermodynamic system
 
Hybrid Cloud Computing (IBM System z)
Hybrid Cloud Computing (IBM System z)Hybrid Cloud Computing (IBM System z)
Hybrid Cloud Computing (IBM System z)
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)
 
System software and operating system
System software and operating systemSystem software and operating system
System software and operating system
 
Design And Implementation Of A Bangla Compiler
Design And Implementation Of A Bangla CompilerDesign And Implementation Of A Bangla Compiler
Design And Implementation Of A Bangla Compiler
 
Crytography
CrytographyCrytography
Crytography
 
code optimization
code optimization code optimization
code optimization
 
Gcse Forces And Motion
Gcse Forces And MotionGcse Forces And Motion
Gcse Forces And Motion
 

Semelhante a Code Generation

Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionSarmad Ali
 
System software module 4 presentation file
System software module 4 presentation fileSystem software module 4 presentation file
System software module 4 presentation filejithujithin657
 
what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compileradilmehmood93
 
Assemblers: Ch03
Assemblers: Ch03Assemblers: Ch03
Assemblers: Ch03desta_gebre
 
Chapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course MaterialChapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course MaterialgadisaAdamu
 
1-Phases of compiler-26-04-2023.pptx
1-Phases of compiler-26-04-2023.pptx1-Phases of compiler-26-04-2023.pptx
1-Phases of compiler-26-04-2023.pptxvenkatapranaykumarGa
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler languageAshok Raj
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionAhmed Raza
 
Unit iii-111206004501-phpapp02
Unit iii-111206004501-phpapp02Unit iii-111206004501-phpapp02
Unit iii-111206004501-phpapp02riddhi viradiya
 
Valuable Information on Lexical Analysis in Compiler Design
Valuable Information on Lexical Analysis in Compiler DesignValuable Information on Lexical Analysis in Compiler Design
Valuable Information on Lexical Analysis in Compiler DesignLesa Cote
 
Embedded computing platform design
Embedded computing platform designEmbedded computing platform design
Embedded computing platform designRAMPRAKASHT1
 
3 address code ujjwal matoliya.pptx
3 address code ujjwal matoliya.pptx3 address code ujjwal matoliya.pptx
3 address code ujjwal matoliya.pptxujjwalmatoliya
 

Semelhante a Code Generation (20)

Unit 1.pptx
Unit 1.pptxUnit 1.pptx
Unit 1.pptx
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
System software module 4 presentation file
System software module 4 presentation fileSystem software module 4 presentation file
System software module 4 presentation file
 
what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compiler
 
Assemblers: Ch03
Assemblers: Ch03Assemblers: Ch03
Assemblers: Ch03
 
Chapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course MaterialChapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course Material
 
C language unit-1
C language unit-1C language unit-1
C language unit-1
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDYC LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
1-Phases of compiler-26-04-2023.pptx
1-Phases of compiler-26-04-2023.pptx1-Phases of compiler-26-04-2023.pptx
1-Phases of compiler-26-04-2023.pptx
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler language
 
The Phases of a Compiler
The Phases of a CompilerThe Phases of a Compiler
The Phases of a Compiler
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
System software 5th unit
System software 5th unitSystem software 5th unit
System software 5th unit
 
Unit iii-111206004501-phpapp02
Unit iii-111206004501-phpapp02Unit iii-111206004501-phpapp02
Unit iii-111206004501-phpapp02
 
Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Chapter 1.pptx
 
Valuable Information on Lexical Analysis in Compiler Design
Valuable Information on Lexical Analysis in Compiler DesignValuable Information on Lexical Analysis in Compiler Design
Valuable Information on Lexical Analysis in Compiler Design
 
Embedded computing platform design
Embedded computing platform designEmbedded computing platform design
Embedded computing platform design
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
3 address code ujjwal matoliya.pptx
3 address code ujjwal matoliya.pptx3 address code ujjwal matoliya.pptx
3 address code ujjwal matoliya.pptx
 

Último

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Último (20)

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

Code Generation

  • 1. Code Generation - Principles of Compiler Design Presenter: PRABU.R BP150504, II MSC CS, PG Department of Computer Science, Sacred Heart College, Tirupattur.
  • 2. AGENDA • Introduction • Issues in the Design of a Code Generation.
  • 3. Introduction • It is the final phase in the compiler model. • Input as a Intermediate representation of the source program and output as equivalent target program. Int. code Int. codeSrc Progm Front end Code Optimizer Code Generator Symbol Table Target Progm
  • 4. Issues in Design of Code Gen. 1. Input to the Code Generator 2. Target Program 3. Memory Management 4. Instruction Section 5. Register Allocation 6. Choices of Evaluation Order 7. Approaches to Code Generation
  • 5. 1. Input to the Code Generator • The input to the code gen. consists of intermediate representation of the source program • Which is produced by the front end, together with info in the symbol table, used to determine the run time address of objects denoted by the names in intermediate representation. • Three several choices for the IL : – Linear representation such as postfix notation – Three-address code such as quadruples. – Graphical representation such as syntax tree and dags.
  • 6. 2. Target Program • Output of code gen is Target Program. • Like Intermediate Code, this output also takes many forms: – Absolute Machine Language – Relocatable Machine Language – Assembly Language. • Producing an absolute ML has the advantage that it can be placed in a fixed location in memory and immediately executed. • Compilers such as WATFIV and PL/C, produces Absolute code.
  • 7. 2. Cont.. • On the other hand while producing relocatable ML, we gain flexibility that we can call other programs from an object module. • Where as while producing assembly language program, process of code generation is easier. • We can generate symbolic instructions and use the macro facilities of the assembler to help generate code.
  • 8. 3. Memory Management • Mapping names in the source program to addresses of data objects in run time memory is done cooperatively by the front end and the code generator. • We assumed names in a Three address statement refers to the names in symbol table entry for the name. • If Machine code is being generated, labels in three address statement have to be converted to addresses of instruction. • This process is analogous in Back patching.
  • 9. 4. Instruction Selection • The nature of instruction set of the target ML determines the difficulty of instruction selection. X:=y+z MOV y,R0 ADD z,R0 MOV R0,x
  • 10. 5. Register Allocation • The use of register allocation is often subdivided into two sub problems: – During register allocation – During a subsequent register assignment phase. • Certain machines register pairs Multiplication: M x,y Division: D x,y t:=a+b t:=t*b t:=a/b
  • 11. 6. Choices of Evaluation Order • The order in which computations are performed can affect the efficiency of the target code. • Some computation orders requires fewer registers to hold intermediate results than others. • Picking a best order is another difficult, NP-complete problem.
  • 12. 7. Approaches to Code Generation • The most important criterion for a code generator is that it produce correct code. • Correctness takes on significance because of the no of special cases that a code generator might face. • Given the premium on correctness, designing a code gen so it can be easily implemented, tested and maintained is an important design deal.