PPT: Code Generation | Compiler Design - Computer Science Engineering (CSE) PDF Download

Download, print and study this document offline
Please wait while the PDF view is loading
 Page 1


Code Generation
Page 2


Code Generation
Outline
? Code Generation Issues
? Target language Issues
? Addresses in Target Code
? Basic Blocks and Flow Graphs
? Optimizations of Basic Blocks
? A Simple Code Generator
? Peephole optimization
? Register allocation and assignment
? Instruction selection by tree rewriting
Page 3


Code Generation
Outline
? Code Generation Issues
? Target language Issues
? Addresses in Target Code
? Basic Blocks and Flow Graphs
? Optimizations of Basic Blocks
? A Simple Code Generator
? Peephole optimization
? Register allocation and assignment
? Instruction selection by tree rewriting
Introduction
? The final phase of a compiler is code generator
? It receives an intermediate representation (IR) with
supplementary information in symbol table
? Produces a semantically equivalent target program
? Code generator main tasks:
? Instruction selection
? Register allocation and assignment
? Insrtuction ordering
Front
end
Code optimizer
Code
Generator
Page 4


Code Generation
Outline
? Code Generation Issues
? Target language Issues
? Addresses in Target Code
? Basic Blocks and Flow Graphs
? Optimizations of Basic Blocks
? A Simple Code Generator
? Peephole optimization
? Register allocation and assignment
? Instruction selection by tree rewriting
Introduction
? The final phase of a compiler is code generator
? It receives an intermediate representation (IR) with
supplementary information in symbol table
? Produces a semantically equivalent target program
? Code generator main tasks:
? Instruction selection
? Register allocation and assignment
? Insrtuction ordering
Front
end
Code optimizer
Code
Generator
Issues in the Design of Code
Generator
? The most important criterion is that it produces correct
code
? Input to the code generator
? IR + Symbol table
? We assume front end produces low-level IR, i.e. values of
names in it can be directly manipulated by the machine
instructions.
? Syntactic and semantic errors have been already detected
? The target program
? Common target architectures are: RISC, CISC and Stack
based machines
? In this chapter we use a very simple RISC-like computer with
addition of some CISC-like addressing modes
Page 5


Code Generation
Outline
? Code Generation Issues
? Target language Issues
? Addresses in Target Code
? Basic Blocks and Flow Graphs
? Optimizations of Basic Blocks
? A Simple Code Generator
? Peephole optimization
? Register allocation and assignment
? Instruction selection by tree rewriting
Introduction
? The final phase of a compiler is code generator
? It receives an intermediate representation (IR) with
supplementary information in symbol table
? Produces a semantically equivalent target program
? Code generator main tasks:
? Instruction selection
? Register allocation and assignment
? Insrtuction ordering
Front
end
Code optimizer
Code
Generator
Issues in the Design of Code
Generator
? The most important criterion is that it produces correct
code
? Input to the code generator
? IR + Symbol table
? We assume front end produces low-level IR, i.e. values of
names in it can be directly manipulated by the machine
instructions.
? Syntactic and semantic errors have been already detected
? The target program
? Common target architectures are: RISC, CISC and Stack
based machines
? In this chapter we use a very simple RISC-like computer with
addition of some CISC-like addressing modes
complexity of mapping
? the level of the IR
? the nature of the instruction-set architecture
? the desired quality of the generated code.
x=y+z
LD R0, y
ADD R0, R0, z
ST x, R0
a=b+c
d=a+e
LD R0, b
ADD R0, R0, c
ST a, R0
LD R0, a
ADD R0, R0, e
ST d, R0
Read More
26 videos|66 docs|30 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on PPT: Code Generation - Compiler Design - Computer Science Engineering (CSE)

1. What is code generation in computer science engineering?
Ans. Code generation in computer science engineering refers to the process of automatically generating source code or machine code from a higher-level representation, such as a programming language or a graphical user interface. It is often used in compiler design and development tools to translate high-level code into executable code.
2. Why is code generation important in computer science engineering?
Ans. Code generation is important in computer science engineering as it reduces the manual effort required for writing complex code. It allows programmers to focus on high-level design and logic, while the code generation tools take care of the low-level details. It also helps in achieving code reusability, improving productivity, and ensuring consistency in code quality.
3. How does code generation work in compiler design?
Ans. In compiler design, code generation involves transforming the intermediate representation of a program into target machine code. This process typically includes various optimizations to improve the efficiency and performance of the generated code. The compiler analyzes the program's control flow, variables, and expressions to generate optimized code that closely matches the intended behavior of the program.
4. What are the advantages of using code generation tools in software development?
Ans. There are several advantages of using code generation tools in software development. Firstly, it saves time and effort by automating the repetitive and error-prone task of writing boilerplate code. It also promotes code consistency and reduces the chances of introducing bugs. Additionally, code generation tools can help in generating code for multiple platforms or languages, enabling developers to target different environments without rewriting the code from scratch.
5. Are there any limitations or challenges associated with code generation in computer science engineering?
Ans. Yes, there can be limitations and challenges with code generation. One challenge is the complexity of generating optimal code for all possible scenarios, as code generators may struggle with certain corner cases or specific programming constructs. Another challenge is the maintainability of generated code, as changes made to the high-level representation may require manual modifications to the generated code. Additionally, code generation tools may have a learning curve and require expertise to use effectively.
26 videos|66 docs|30 tests
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

Viva Questions

,

practice quizzes

,

mock tests for examination

,

Extra Questions

,

Sample Paper

,

Important questions

,

pdf

,

MCQs

,

Summary

,

Objective type Questions

,

PPT: Code Generation | Compiler Design - Computer Science Engineering (CSE)

,

PPT: Code Generation | Compiler Design - Computer Science Engineering (CSE)

,

Free

,

study material

,

past year papers

,

Exam

,

PPT: Code Generation | Compiler Design - Computer Science Engineering (CSE)

,

shortcuts and tricks

,

ppt

,

Semester Notes

,

video lectures

,

Previous Year Questions with Solutions

;