PPT: Intermediate 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


Intermediate Code Generation
Page 2


Intermediate Code Generation
Outline
? Variants of Syntax Trees
? Three-address code
? Types and declarations
? Translation of expressions
? Type checking
? Control flow
? Backpatching
Page 3


Intermediate Code Generation
Outline
? Variants of Syntax Trees
? Three-address code
? Types and declarations
? Translation of expressions
? Type checking
? Control flow
? Backpatching
Introduction
? Intermediate code is the interface between front end
and back end in a compiler
? Ideally the details of source language are confined to
the front end and the details of target machines to the
back end (a m*n model)
? In this chapter we study intermediate representations,
static type checking and intermediate code generation
Parser
Static
Checker
Intermediate
Code Generator
Code
Generator
Front end Back end
Page 4


Intermediate Code Generation
Outline
? Variants of Syntax Trees
? Three-address code
? Types and declarations
? Translation of expressions
? Type checking
? Control flow
? Backpatching
Introduction
? Intermediate code is the interface between front end
and back end in a compiler
? Ideally the details of source language are confined to
the front end and the details of target machines to the
back end (a m*n model)
? In this chapter we study intermediate representations,
static type checking and intermediate code generation
Parser
Static
Checker
Intermediate
Code Generator
Code
Generator
Front end Back end
Variants of syntax trees
? It is sometimes beneficial to crate a DAG instead of
tree for Expressions.
? This way we can easily show the common sub-
expressions and then use that knowledge during code
generation
? Example: a+a*(b-c)+(b-c)*d
+
+ *
*
-
b
c
a
d
Page 5


Intermediate Code Generation
Outline
? Variants of Syntax Trees
? Three-address code
? Types and declarations
? Translation of expressions
? Type checking
? Control flow
? Backpatching
Introduction
? Intermediate code is the interface between front end
and back end in a compiler
? Ideally the details of source language are confined to
the front end and the details of target machines to the
back end (a m*n model)
? In this chapter we study intermediate representations,
static type checking and intermediate code generation
Parser
Static
Checker
Intermediate
Code Generator
Code
Generator
Front end Back end
Variants of syntax trees
? It is sometimes beneficial to crate a DAG instead of
tree for Expressions.
? This way we can easily show the common sub-
expressions and then use that knowledge during code
generation
? Example: a+a*(b-c)+(b-c)*d
+
+ *
*
-
b
c
a
d
SDD for creating DAG’s
1) E -> E1+T
2) E -> E1-T
3) E -> T
4) T -> (E)
5) T -> id
6) T -> num
Production Semantic Rules
E.node= new Node(‘+’, E1.node,T.node)
E.node= new Node(‘-’, E1.node,T.node)
E.node = T.node
T.node = E.node
T.node = new Leaf(id, id.entry)
T.node = new Leaf(num, num.val)
Example:
1) p1=Leaf(id, entry-a)
2) P2=Leaf(id, entry-a)=p1
3) p3=Leaf(id, entry-b)
4) p4=Leaf(id, entry-c)
5) p5=Node(‘-’,p3,p4)
6) p6=Node(‘*’,p1,p5)
7) p7=Node(‘+’,p1,p6)
8) p8=Leaf(id,entry-b)=p3
9) p9=Leaf(id,entry-c)=p4
10) p10=Node(‘-’,p3,p4)=p5
11) p11=Leaf(id,entry-d)
12) p12=Node(‘*’,p5,p11)
13) p13=Node(‘+’,p7,p12)
Read More
26 videos|66 docs|30 tests

Top Courses for Computer Science Engineering (CSE)

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

1. What is intermediate code generation in computer science engineering?
Ans. Intermediate code generation is a phase in the compilation process where a source code written in a high-level programming language is translated into an intermediate representation, also known as intermediate code. This intermediate code serves as a bridge between the source code and the target code, making it easier for the compiler to optimize and generate efficient machine code.
2. Why is intermediate code generation important in the compilation process?
Ans. Intermediate code generation plays a vital role in the compilation process for several reasons. Firstly, it helps in separating the concerns of language-specific syntax and machine-specific code generation, making the compiler more modular and portable. Secondly, it allows for easier optimization of code since the intermediate representation is often simpler and more amenable to analysis. Lastly, it enables the compilation process to be divided into multiple stages, making it easier to modify or extend the compiler without starting from scratch.
3. What are the advantages of using intermediate code generation?
Ans. There are several advantages of using intermediate code generation in the compilation process. Firstly, it helps in improving the portability of the compiler by separating the language-specific front-end from the machine-specific back-end. This means that the same front-end can be used to generate intermediate code for different target platforms. Secondly, intermediate code allows for easier optimization of the program since the representation is often simpler and more amenable to analysis. Lastly, it enables incremental compilation, where only the modified portions of the code need to be recompiled, resulting in faster compilation times.
4. What are some commonly used intermediate representations in code generation?
Ans. There are various intermediate representations that can be used in code generation, depending on the compiler design and target platform. Some commonly used representations include: 1. Three-address code: This representation uses three operands per instruction, allowing for more expressive operations. 2. Quadruples: Quadruples represent each operation as a tuple of four elements - operator, argument 1, argument 2, and result. 3. Abstract Syntax Trees (AST): AST represents the hierarchical structure of the program using nodes and edges, making it easier to analyze and transform the code. 4. Control Flow Graphs (CFG): CFG represents the control flow of the program using nodes and edges, helping in optimization and analysis of the program's control flow.
5. How does intermediate code generation contribute to the overall performance of the compiled program?
Ans. Intermediate code generation plays a crucial role in improving the overall performance of the compiled program. It enables various optimization techniques to be applied to the intermediate representation, such as constant folding, common subexpression elimination, and dead code elimination. These optimizations aim to reduce the number of redundant computations, eliminate unnecessary code, and improve the overall efficiency of the program. Additionally, intermediate code generation allows for the introduction of platform-specific optimizations during the translation from intermediate code to target code, further enhancing the performance of the compiled program.
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

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

,

Extra Questions

,

Summary

,

MCQs

,

Semester Notes

,

Sample Paper

,

past year papers

,

Viva Questions

,

Previous Year Questions with Solutions

,

pdf

,

Exam

,

video lectures

,

study material

,

practice quizzes

,

Free

,

shortcuts and tricks

,

Important questions

,

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

,

mock tests for examination

,

Objective type Questions

,

ppt

,

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

;