Intermediate Code
Intermediate Code
Generation
From: To:
Sushma B C Dr.Maheshwari L Patil
4GM20CS110 Dept.of Cse
Table of contents
1.Introduction
• 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
• 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
• 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
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