Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Notes  >  Issues in the design of a code generator - Code Generation, Computer Science and IT Engineering

Issues in the design of a code generator - Code Generation, Computer Science and IT Engineering - Computer Science Engineering (CSE) PDF Download

Issues in the design of a code generator

CODE GENERATION

The final phase in compiler model is the code generator. It takes as input an intermediate representation of the source program and produces as output an equivalent target program. The code generation techniques presented below can be used whether or not an optimizing phase occurs before code generation.

Issues in the design of a code generator - Code Generation, Computer Science and IT Engineering - Computer Science Engineering (CSE)Issues in the design of a code generator - Code Generation, Computer Science and IT Engineering - Computer Science Engineering (CSE)

 

 

ISSUES IN THE DESIGN OF A CODE GENERATOR

The following issues arise during the code generation phase:

1.   Input to code generator

2.   Target program

3.   Memory management

4.   Instruction selection

5.   Register allocation

6.   Evaluation order

 

1. Input to code generator:

  • The input to the code generation consists of the intermediate representation of the source program produced by front end , together with information in the symbol table to determine run-time addresses of the data objects denoted by the names in the intermediate representation.
  • Intermediate representation can be :

a.   Linear representation such as postfix notation

b.   Three address representation such as quadruples

c.   Virtual machine representation such as stack machine code

d.   Graphical representations such as syntax trees and dags.

e.     Prior to code generation, the front end must be scanned, parsed and translated into intermediate representation along with necessary type checking. Therefore, input to code generation is assumed to be error-free.

f.      

2. Target program:

  • The output of the code generator is the target program. The output may be : a. Absolute machine language

-  It can be placed in a fixed memory location and can be executed immediately. b. Relocatable machine language

-  It allows subprograms to be compiled separately.

c. Assembly language

- Code generation is made easier.

 

3. Memory management:

  • Names in the source program are mapped to addresses of data objects in run-time memory by the front end and code generator.
  • It makes use of symbol table, that is, a name in a three-address statement refers to a symbol-table entry for the name.
  • Labels in three-address statements have to be converted to addresses of instructions. For example,

j:gotoigenerates jump instruction as follows:

*  if i < j, a backward jump instruction with target address equal to location of code for quadruple i is generated.

*   if i > j, the jump is forward. We must store on a list for quadruple i the location of the first machine instruction generated for quadruple j. When i is processed, the machine locations for all instructions that forward jumps to i are filled.

 

4. Instruction selection:

  • The instructions of target machine should be complete and uniform.
  • Instruction speeds and machine idioms are important factors when efficiency of target program is considered.
  • The quality of the generated code is determined by its speed and size.
  • The former statement can be translated into the latter statement as shown below:

a:=b+c

d:=a+e (a)

MOV b,R0

ADD c,R0

MOV R0,a (b)

MOV a,R0

ADD e,R0

MOV R0,d

 

5. Register allocation

  • Instructions involving register operands are shorter and faster than those involving operands in memory. The use of registers is subdivided into two subproblems :

1. Register allocation - the set of variables that will reside in registers at a point in the program is selected.

2. Register assignment - the specific register that a value picked•

3. Certain machine requires even-odd register pairs for some operands and results. For example , consider the division instruction of the form :D x, y

where, x - dividend even register in even/odd register pair y-divisor

even register holds the remainder

 odd register holds the quotient

 

6. Evaluation order

  • The order in which the computations are performed can affect the efficiency of the target code.

Some computation orders require fewer registers to hold intermediate results than others.

The document Issues in the design of a code generator - Code Generation, Computer Science and IT Engineering - Computer Science Engineering (CSE) is a part of Computer Science Engineering (CSE) category.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)

Top Courses for Computer Science Engineering (CSE)

FAQs on Issues in the design of a code generator - Code Generation, Computer Science and IT Engineering - Computer Science Engineering (CSE)

1. What is a code generator?
Ans. A code generator is a software tool or program that automatically generates source code or machine code based on a given input. It is commonly used in software development to automate the process of writing repetitive or boilerplate code.
2. What are some issues that can arise in the design of a code generator?
Ans. Some common issues in the design of a code generator include: - Handling complex or ambiguous input specifications: Code generators need to be able to interpret and understand the input specifications accurately to generate correct code. - Dealing with language-specific nuances: Different programming languages have their own syntax, rules, and requirements. A code generator must account for these nuances when generating code in a specific programming language. - Ensuring maintainability and extensibility: Code generators should be designed in a way that allows easy modification and extension without requiring significant rework or affecting the existing generated code. - Handling error and exception scenarios: Code generators need to handle potential errors or exceptions that may occur during the code generation process, ensuring that appropriate error handling and reporting mechanisms are in place. - Performance and efficiency: Generating code can be a resource-intensive process, especially for large-scale applications. Code generators should be designed to optimize performance and efficiency while generating code.
3. How can code generators handle complex or ambiguous input specifications?
Ans. Code generators can handle complex or ambiguous input specifications through techniques such as: - Using well-defined and unambiguous input formats: By defining a clear and precise specification language, code generators can ensure that the input provided is unambiguous and can be easily interpreted. - Employing parsing and validation algorithms: Code generators can utilize parsing algorithms to analyze and interpret the input specifications. Additionally, validation algorithms can be used to check for any inconsistencies or ambiguities in the input. - Providing user-friendly error messages: When encountering complex or ambiguous input, code generators should provide informative error messages that guide the user in resolving the issues. This can help users understand the problem and make the necessary changes to the input specifications.
4. How can code generators ensure maintainability and extensibility?
Ans. Code generators can ensure maintainability and extensibility through the following practices: - Using modular and well-structured code generation templates: Code generators should be designed with modular templates that separate different code generation tasks. This allows for easy modification and extension of specific code generation components without affecting the entire generator. - Providing clear documentation and guidelines: Code generators should be accompanied by comprehensive documentation and guidelines that explain the generator's architecture, usage, and customization options. This enables developers to understand and modify the generator effectively. - Supporting configuration files or settings: Code generators can provide configuration files or settings that allow developers to customize the generated code according to their specific requirements. This flexibility enhances maintainability and extensibility by allowing easy modifications without changing the code generator itself.
5. How can code generators optimize performance and efficiency?
Ans. Code generators can optimize performance and efficiency by implementing the following approaches: - Employing caching mechanisms: Code generators can cache previously generated code for reuse, reducing the need for regeneration and improving overall performance. - Utilizing code generation optimizations: Techniques like code reuse, code deduplication, and minimizing unnecessary code generation can significantly improve the efficiency of the code generator. - Implementing parallel processing: Code generators can leverage parallel processing to distribute the code generation tasks across multiple threads or processes, effectively utilizing available resources and reducing the overall generation time. - Providing configuration options for performance tuning: Code generators can offer configuration options to allow developers to control various performance-related aspects, such as the level of code optimization or the number of parallel threads used during code generation. This enables customization based on specific performance requirements.
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

ppt

,

Viva Questions

,

Objective type Questions

,

pdf

,

Extra Questions

,

Computer Science and IT Engineering - Computer Science Engineering (CSE)

,

Important questions

,

practice quizzes

,

Issues in the design of a code generator - Code Generation

,

study material

,

Computer Science and IT Engineering - Computer Science Engineering (CSE)

,

video lectures

,

Previous Year Questions with Solutions

,

Semester Notes

,

Issues in the design of a code generator - Code Generation

,

Issues in the design of a code generator - Code Generation

,

past year papers

,

shortcuts and tricks

,

Free

,

Sample Paper

,

Computer Science and IT Engineering - Computer Science Engineering (CSE)

,

MCQs

,

mock tests for examination

,

Summary

,

Exam

;