0% found this document useful (0 votes)
20 views14 pages

Intermediate Code

This document discusses intermediate code generation in compilers. It begins by explaining that compilers build intermediate representations between parsing the source code and generating target code. These representations allow compilers to be modular and support multiple source/target combinations. The document then discusses different variants of syntax trees that can represent code, including directed acyclic graphs (DAGs). It describes how DAGs are constructed for expressions using value numbering, where each node is assigned a unique number based on its operator and children. The value numbering approach allows duplicate subexpressions to share the same node in the DAG rather than being recreated.

Uploaded by

Shashti D B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views14 pages

Intermediate Code

This document discusses intermediate code generation in compilers. It begins by explaining that compilers build intermediate representations between parsing the source code and generating target code. These representations allow compilers to be modular and support multiple source/target combinations. The document then discusses different variants of syntax trees that can represent code, including directed acyclic graphs (DAGs). It describes how DAGs are constructed for expressions using value numbering, where each node is assigned a unique number based on its operator and children. The value numbering approach allows duplicate subexpressions to share the same node in the DAG rather than being recreated.

Uploaded by

Shashti D B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Intermediate-Code

Generation
From: To:
Sushma B C Dr.Maheshwari L Patil
4GM20CS110 Dept.of Cse
Table of contents
1.Introduction

2.Variants of Syntax Trees

3.Directed Acyclic Graphs for Expressions

4.The Value-Number method for DAG’s


Introduction to Intemediate code generation

• In the analysis-synthesis model of a compiler, the front end analyzes a source program and
creates an intermediate representation, from which the back end generates target code.

• A compiler for language i and machine j can then be built by combining the front end for
language i with the back end for machine j.

• m x n compilers can be built by writing just m front ends and n back ends.

• Static checking includes type checking, which ensures that operators are applied to compatible
operands.
Logical structure of complier
A sequence of intermediate representations

• In the process of translating a program in a given source language into code for a
given target machine, a compiler may construct a sequence of intermediate
representations

• High-level representations are close to the source language and low-level


representations are close to the target machine
Variants of Syntax Trees

1.Directed Acyclic Graphs for Expression

2.The Value-Number Method for Constructing DAG’s


1.Directed Acyclic Graphs for Expression

• Like the syntax tree for an expression, a DAG has leaves corresponding to atomic operands
and interior codes corresponding to operators.

• Example: a + a * (b - c) + (b - c) * d

Dag for the expression a + a * (b - c) + (b - c) * d


SDD to produce syntax trees or DAG's

Syntax-directed definition to produce syntax trees or DAG's


Steps for constructing the DAG
2.The Value-Number method for DAG’s

• Nodes of a syntax tree or DAG are stored in an array of records. The integer index of the record for
a node in the array is known as the value number of that node.

• signature of an interior node be the triple (op, l,r) , where op is the label, 1 its left child's value
number, and r its right child's value number. A unary operator may be assumed to have r = O.

• The value-number method for constructing the nodes of a DAG uses the signature of a node to
check if a node with the same signature already exists in the array. If yes, returns the value number.
Otherwise, creates a new node with the given signature.
The Value-Number method for DAG’s

Nodes of a DAG for i = i + 10 allocated in an array


Algorithm : The value-number method for constructing the
nodes of a DAG.

INPUT: Label op, node 1, and node r.

OUTPUT: The value number of a node in the array with signature (op, 1, r)

METHOD:

• Search the array for a node M with label op, left child l, and right child r.
• If there is such a node, return the value number of M.
• If not, create in the array a new node N with label op, left child 1, and right child r, and return its
value number.
Data structure for searching buckets
Thank you

You might also like