SlideShare a Scribd company logo
Submitted by: Momina Idrees
Roll # 1430303
CODE GENERATION, ERRORS &
RECOVERY
Assignment (Finals) of Compiler Construction
1 | P a g e
CODE GENERATOR
The final phase of our compiler model is code generator. It takes input from
the intermediate representation with supplementary information in symbol
table of the source program and produces as output an equivalent target
program.
Issues in the design of a code generator
 Input to the code generator:
The intermediate representation of the source program produced by the
front end is input to code generator.
 Memory management:
Mapping names in the source program to addresses of data objects in
run-time memory. A name in a three- address statement refers to a
symbol table entry for the name. A relative address can be determined.
 Target programs:
 Absolute machine language
 Relocatable machine language
 Assembly language
 Selection of instruction:
The code generator takes Intermediate Representation as input and
converts (maps) it into target machine’s instruction set. One
representation can have many ways (instructions) to convert it, so it
2 | P a g e
becomes the responsibility of the code generator to choose the appropriate
instructions wisely.
 Register allocation:
A program has a number of values to be maintained during the execution.
The target machine’s architecture may not allow all of the values to be
kept in the CPU memory or registers. Code generator decides what values
to keep in the registers. Also, it decides the registers to be used to keep
these values. The code generator has to track both the registers (for
availability) and addresses (location of values) while generating the code.
For both of them, the following two descriptors are used:
 Register descriptor: Register descriptor is used to inform the
code generator about the availability of registers. Register
descriptor keeps track of values stored in each register.
Whenever a new register is required during code generation, this
descriptor is consulted for register availability.
 Address descriptor: Values of the names (identifiers) used in
the program might be stored at different locations while in
execution. Address descriptors are used to keep track of memory
locations where the values of identifiers are stored. These
locations may include CPU registers, heaps, stacks, memory or a
combination of the mentioned locations.
Code generator keeps both the descriptor updated in real-time. For a load
statement, LD R1, x, the code generator:
 Updates the Register Descriptor R1 that has value of x and
 Updates the Address Descriptor (x) to show that one instance of
x is in R1.
 Ordering of instructions:
At last, the code generator decides the order in which the instruction
will be executed. It creates schedules for instructions to execute them.
Issues a “Code Generator” tackles:
The Code generation module has to tackle a number of issues.
3 | P a g e
 Memory management: Mapping names to data objects in the run-time
system.
 Instruction selection: The assembly language instructions to choose to
encode intermediate code statements.
 Instruction scheduling: Instruction chosen must utilize the CPU
resources effectively. Hardware stalls must be avoided.
 Register allocation: Operands are placed in registers before executing
machine operation such as ADD, MULTIPLY etc. Most processors have a
limited set of registers available. The code generator has to make
efficient use of this limited resource.
Common Errors
Program submitted to a compiler often have errors of various kinds. So, good
compiler should be able to detect as many errors as possible in various ways
and also recover from them. Even in the presence of errors, the compiler
should scan the program and try to compile all of it (error recovery). Errors
may be encountered at various stages of the compilation process. A program
may have the following kinds of errors at various stages:
 Lexical: Name of some identifier typed incorrectly.
 Syntactical: Missing semicolon or unbalanced parenthesis.
 Semantical: Incompatible value assignment.
 Logical: Code not reachable, infinite loop.
Error-recovery strategies
 Panic mode
When a parser encounters an error anywhere in the statement, it
ignores the rest of the statement by not processing input from
erroneous input to delimiter, such as semi-colon. This is the easiest way
of error-recovery and also, it prevents the parser from developing
infinite loops.
 Statement mode
When a parser encounters an error, it tries to take corrective measures
so that the rest of inputs of statement allow the parser to parse ahead.
4 | P a g e
For example, inserting a missing semicolon, replacing comma with a
semicolon etc. Parser designers have to be careful here because one
wrong correction may lead to an infinite loop.
 Error productions
Some common errors are known to the compiler designers that may
occur in the code. In addition, the designers can create augmented
grammar to be used, as productions that generate erroneous constructs
when these errors are encountered.
 Global correction
The parser considers the program in hand as a whole and tries to figure
out what the program is intended to do and tries to find out a closest match
for it, which is error-free. When an erroneous input (statement) X is fed,
it creates a parse tree for some closest error-free statement Y. This may
allow the parser to make minimal changes in the source code, but due to
the complexity (time and space) of this strategy, it has not been
implemented in practice yet.
5 | P a g e
Reference
 Scribdcom. (2018). Scribd. Retrieved 15 January, 2018, from
https://www.scribd.com/doc/104543373/Error-Detection-Recovery
 Docsitycom. (2018). Docsitycom. Retrieved 15 January, 2018, from
https://www.docsity.com/en/simple-code-generation-compiler-construction-
lecture-notes/203852/
 Tutorialspointcom. (2018). Wwwtutorialspointcom. Retrieved 15 January,
2018, from
https://www.tutorialspoint.com/compiler_design/compiler_design_code_gene
ration.htm
 Slidesharenet. (2018). Slidesharenet. Retrieved 15 January, 2018, from
https://www.slideshare.net/naparnanayak/code-generation-15188739
 Tutorialspointcom. (2018). Wwwtutorialspointcom. Retrieved 15 January,
2018, from
https://www.tutorialspoint.com/compiler_design/compiler_design_error_reco
very.htm

More Related Content

What's hot

Hashing
HashingHashing
Hashing
Amar Jukuntla
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
MAHASREEM
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
Satyamevjayte Haxor
 
First pass of assembler
First pass of assemblerFirst pass of assembler
First pass of assembler
Hemant Chetwani
 
Three Address code
Three Address code Three Address code
Three Address code
Pooja Dixit
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
Tanzeela_Hussain
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
Dattatray Gandhmal
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
United International University
 
Code Generation
Code GenerationCode Generation
Code Generation
PrabuPappuR
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
Radhakrishnan Chinnusamy
 
Assemblers
AssemblersAssemblers
Assemblers
Dattatray Gandhmal
 
Generating code from dags
Generating code from dagsGenerating code from dags
Generating code from dags
indhu mathi
 
Basic Blocks and Flow Graphs
Basic Blocks and Flow GraphsBasic Blocks and Flow Graphs
Basic Blocks and Flow Graphs
Jenny Galino
 
Issues in design_of_code_generator
Issues in design_of_code_generatorIssues in design_of_code_generator
Issues in design_of_code_generator
vinithapanneer
 
Problem Solving and Python Programming
Problem Solving and Python ProgrammingProblem Solving and Python Programming
Problem Solving and Python Programming
MahaJeya
 
Target language in compiler design
Target language in compiler designTarget language in compiler design
Target language in compiler design
Muhammad Haroon
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
ASHOK KUMAR REDDY
 
LALR Parser Presentation ppt
LALR Parser Presentation pptLALR Parser Presentation ppt
LALR Parser Presentation ppt
WPVKP.COM
 
Type checking in compiler design
Type checking in compiler designType checking in compiler design
Type checking in compiler design
Sudip Singh
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
Richa Sharma
 

What's hot (20)

Hashing
HashingHashing
Hashing
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
 
First pass of assembler
First pass of assemblerFirst pass of assembler
First pass of assembler
 
Three Address code
Three Address code Three Address code
Three Address code
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
Code Generation
Code GenerationCode Generation
Code Generation
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Assemblers
AssemblersAssemblers
Assemblers
 
Generating code from dags
Generating code from dagsGenerating code from dags
Generating code from dags
 
Basic Blocks and Flow Graphs
Basic Blocks and Flow GraphsBasic Blocks and Flow Graphs
Basic Blocks and Flow Graphs
 
Issues in design_of_code_generator
Issues in design_of_code_generatorIssues in design_of_code_generator
Issues in design_of_code_generator
 
Problem Solving and Python Programming
Problem Solving and Python ProgrammingProblem Solving and Python Programming
Problem Solving and Python Programming
 
Target language in compiler design
Target language in compiler designTarget language in compiler design
Target language in compiler design
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
LALR Parser Presentation ppt
LALR Parser Presentation pptLALR Parser Presentation ppt
LALR Parser Presentation ppt
 
Type checking in compiler design
Type checking in compiler designType checking in compiler design
Type checking in compiler design
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
 

Similar to Code generation errors and recovery

unit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfunit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdf
DrIsikoIsaac
 
Chapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfChapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdf
DrIsikoIsaac
 
Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02
Tirumala Rao
 
Compiler
Compiler Compiler
Compiler
Md. Sumon Fakir
 
SSD Mod 2 -18CS61_Notes.pdf
SSD Mod 2 -18CS61_Notes.pdfSSD Mod 2 -18CS61_Notes.pdf
SSD Mod 2 -18CS61_Notes.pdf
JacobDragonette
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
guest5de1a5
 
Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdf
AkarTaher
 
Chapter#01 cc
Chapter#01 ccChapter#01 cc
Chapter#01 cc
abdulbaki3
 
Assignment1
Assignment1Assignment1
Assignment1
Sunita Milind Dol
 
Presentation1
Presentation1Presentation1
Presentation1
Zarin Tasnim
 
Presentation1
Presentation1Presentation1
Presentation1
Zarin Tasnim
 
01. Introduction.ppt
01. Introduction.ppt01. Introduction.ppt
01. Introduction.ppt
ReshmaR57
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
Rana Ehtisham Ul Haq
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
amudha arul
 
Ch 1.pptx
Ch 1.pptxCh 1.pptx
Ch 1.pptx
woldu2
 
01. introduction
01. introduction01. introduction
01. introduction
babaaasingh123
 
Cs6660 compiler design
Cs6660 compiler designCs6660 compiler design
Cs6660 compiler design
hari2010
 

Similar to Code generation errors and recovery (20)

Compiler Design Material
Compiler Design MaterialCompiler Design Material
Compiler Design Material
 
unit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfunit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdf
 
Chapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfChapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdf
 
Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02
 
Compiler
Compiler Compiler
Compiler
 
SSD Mod 2 -18CS61_Notes.pdf
SSD Mod 2 -18CS61_Notes.pdfSSD Mod 2 -18CS61_Notes.pdf
SSD Mod 2 -18CS61_Notes.pdf
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
 
Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdf
 
Chapter#01 cc
Chapter#01 ccChapter#01 cc
Chapter#01 cc
 
Assignment1
Assignment1Assignment1
Assignment1
 
3.2
3.23.2
3.2
 
Presentation1
Presentation1Presentation1
Presentation1
 
Presentation1
Presentation1Presentation1
Presentation1
 
01. Introduction.ppt
01. Introduction.ppt01. Introduction.ppt
01. Introduction.ppt
 
How a Compiler Works ?
How a Compiler Works ?How a Compiler Works ?
How a Compiler Works ?
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
 
Ch 1.pptx
Ch 1.pptxCh 1.pptx
Ch 1.pptx
 
01. introduction
01. introduction01. introduction
01. introduction
 
Cs6660 compiler design
Cs6660 compiler designCs6660 compiler design
Cs6660 compiler design
 

Recently uploaded

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 

Recently uploaded (20)

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 

Code generation errors and recovery

  • 1. Submitted by: Momina Idrees Roll # 1430303 CODE GENERATION, ERRORS & RECOVERY Assignment (Finals) of Compiler Construction
  • 2. 1 | P a g e CODE GENERATOR The final phase of our compiler model is code generator. It takes input from the intermediate representation with supplementary information in symbol table of the source program and produces as output an equivalent target program. Issues in the design of a code generator  Input to the code generator: The intermediate representation of the source program produced by the front end is input to code generator.  Memory management: Mapping names in the source program to addresses of data objects in run-time memory. A name in a three- address statement refers to a symbol table entry for the name. A relative address can be determined.  Target programs:  Absolute machine language  Relocatable machine language  Assembly language  Selection of instruction: The code generator takes Intermediate Representation as input and converts (maps) it into target machine’s instruction set. One representation can have many ways (instructions) to convert it, so it
  • 3. 2 | P a g e becomes the responsibility of the code generator to choose the appropriate instructions wisely.  Register allocation: A program has a number of values to be maintained during the execution. The target machine’s architecture may not allow all of the values to be kept in the CPU memory or registers. Code generator decides what values to keep in the registers. Also, it decides the registers to be used to keep these values. The code generator has to track both the registers (for availability) and addresses (location of values) while generating the code. For both of them, the following two descriptors are used:  Register descriptor: Register descriptor is used to inform the code generator about the availability of registers. Register descriptor keeps track of values stored in each register. Whenever a new register is required during code generation, this descriptor is consulted for register availability.  Address descriptor: Values of the names (identifiers) used in the program might be stored at different locations while in execution. Address descriptors are used to keep track of memory locations where the values of identifiers are stored. These locations may include CPU registers, heaps, stacks, memory or a combination of the mentioned locations. Code generator keeps both the descriptor updated in real-time. For a load statement, LD R1, x, the code generator:  Updates the Register Descriptor R1 that has value of x and  Updates the Address Descriptor (x) to show that one instance of x is in R1.  Ordering of instructions: At last, the code generator decides the order in which the instruction will be executed. It creates schedules for instructions to execute them. Issues a “Code Generator” tackles: The Code generation module has to tackle a number of issues.
  • 4. 3 | P a g e  Memory management: Mapping names to data objects in the run-time system.  Instruction selection: The assembly language instructions to choose to encode intermediate code statements.  Instruction scheduling: Instruction chosen must utilize the CPU resources effectively. Hardware stalls must be avoided.  Register allocation: Operands are placed in registers before executing machine operation such as ADD, MULTIPLY etc. Most processors have a limited set of registers available. The code generator has to make efficient use of this limited resource. Common Errors Program submitted to a compiler often have errors of various kinds. So, good compiler should be able to detect as many errors as possible in various ways and also recover from them. Even in the presence of errors, the compiler should scan the program and try to compile all of it (error recovery). Errors may be encountered at various stages of the compilation process. A program may have the following kinds of errors at various stages:  Lexical: Name of some identifier typed incorrectly.  Syntactical: Missing semicolon or unbalanced parenthesis.  Semantical: Incompatible value assignment.  Logical: Code not reachable, infinite loop. Error-recovery strategies  Panic mode When a parser encounters an error anywhere in the statement, it ignores the rest of the statement by not processing input from erroneous input to delimiter, such as semi-colon. This is the easiest way of error-recovery and also, it prevents the parser from developing infinite loops.  Statement mode When a parser encounters an error, it tries to take corrective measures so that the rest of inputs of statement allow the parser to parse ahead.
  • 5. 4 | P a g e For example, inserting a missing semicolon, replacing comma with a semicolon etc. Parser designers have to be careful here because one wrong correction may lead to an infinite loop.  Error productions Some common errors are known to the compiler designers that may occur in the code. In addition, the designers can create augmented grammar to be used, as productions that generate erroneous constructs when these errors are encountered.  Global correction The parser considers the program in hand as a whole and tries to figure out what the program is intended to do and tries to find out a closest match for it, which is error-free. When an erroneous input (statement) X is fed, it creates a parse tree for some closest error-free statement Y. This may allow the parser to make minimal changes in the source code, but due to the complexity (time and space) of this strategy, it has not been implemented in practice yet.
  • 6. 5 | P a g e Reference  Scribdcom. (2018). Scribd. Retrieved 15 January, 2018, from https://www.scribd.com/doc/104543373/Error-Detection-Recovery  Docsitycom. (2018). Docsitycom. Retrieved 15 January, 2018, from https://www.docsity.com/en/simple-code-generation-compiler-construction- lecture-notes/203852/  Tutorialspointcom. (2018). Wwwtutorialspointcom. Retrieved 15 January, 2018, from https://www.tutorialspoint.com/compiler_design/compiler_design_code_gene ration.htm  Slidesharenet. (2018). Slidesharenet. Retrieved 15 January, 2018, from https://www.slideshare.net/naparnanayak/code-generation-15188739  Tutorialspointcom. (2018). Wwwtutorialspointcom. Retrieved 15 January, 2018, from https://www.tutorialspoint.com/compiler_design/compiler_design_error_reco very.htm