COMPILER CONSTRUCTION (Intermediate Code: three address, control flow)

Similar documents
Intermediate Code Generation

Compiler Theory. (Intermediate Code Generation Abstract S yntax + 3 Address Code)

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

TACi: Three-Address Code Interpreter (version 1.0)

Chapter 6 Intermediate Code Generation

Principle of Compilers Lecture VIII: Intermediate Code Generation. Alessandro Artale

Concepts Introduced in Chapter 6

COMPILER CONSTRUCTION (Evaluation Orders for SDD s)

Intermediate Representations

intermediate-code Generation

& Simulator. Three-Address Instructions. Three-Address Instructions. Three-Address Instructions. Structure of an Assembly Program.

Principles of Compiler Design

Formal Languages and Compilers Lecture X Intermediate Code Generation

Concepts Introduced in Chapter 6

tokens parser 1. postfix notation, 2. graphical representation (such as syntax tree or dag), 3. three address code

CSc 453. Compilers and Systems Software. 13 : Intermediate Code I. Department of Computer Science University of Arizona

CMPSC 160 Translation of Programming Languages. Three-Address Code

Three-address code (TAC) TDT4205 Lecture 16

Intermediate Code Generation

Intermediate Representations

UNIT IV INTERMEDIATE CODE GENERATION

UNIT-3. (if we were doing an infix to postfix translator) Figure: conceptual view of syntax directed translation.

Intermediate Code Generation

NARESHKUMAR.R, AP\CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY Page 1

Acknowledgement. CS Compiler Design. Intermediate representations. Intermediate representations. Semantic Analysis - IR Generation

Intermediate Representa.on

Intermediate Code Generation

Semantic Analysis computes additional information related to the meaning of the program once the syntactic structure is known.

Comp 204: Computer Systems and Their Implementation. Lecture 22: Code Generation and Optimisation

Intermediate Code Generation

Programming for Engineers Iteration

PSD3A Principles of Compiler Design Unit : I-V. PSD3A- Principles of Compiler Design

Semantic analysis and intermediate representations. Which methods / formalisms are used in the various phases during the analysis?

Intermediate-Code Generat ion

University of Arizona, Department of Computer Science. CSc 453 Assignment 5 Due 23:59, Dec points. Christian Collberg November 19, 2002

UNIT 3 OPERATORS. [Marks- 12]

Page No 1 (Please look at the next page )

State Space Search in AI

Alternatives for semantic processing

CA4003 Compiler Construction Assignment Language Definition

Programming in C++ 6. Floating point data types

Intermediate Code Generation

opt. front end produce an intermediate representation optimizer transforms the code in IR form into an back end transforms the code in IR form into

Decision Making -Branching. Class Incharge: S. Sasirekha

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Computer Programming CS F111

1. Lexical Analysis Phase

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Intermediate Code Generation

Operators & Expressions

Compilers. Compiler Construction Tutorial The Front-end

8 Optimisation. 8.1 Introduction to Optimisation

Operators. Java operators are classified into three categories:

Expressions and Statementst t. Assignment Operator. C Programming Lecture 6 : Operators. Expression

6. Intermediate Representation!

CMPT 379 Compilers. Anoop Sarkar. 11/13/07 1. TAC: Intermediate Representation. Language + Machine Independent TAC

1.3b Type Conversion

LECTURE 17. Expressions and Assignment

Operators in java Operator operands.

Intermediate Representations & Symbol Tables

CSc 453 Intermediate Code Generation

Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit

Writing Program in C Expressions and Control Structures (Selection Statements and Loops)

Part I Part 1 Expressions

Informatics Ingeniería en Electrónica y Automática Industrial

Expressions and Casting. Data Manipulation. Simple Program 11/5/2013

Intermediate Code Generation

Expressions and Assignment Statements

Dixita Kagathara Page 1

Expressions and Casting

G Compiler Construction Lecture 12: Code Generation I. Mohamed Zahran (aka Z)

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

Operators and Type Conversion. By Avani M. Sakhapara Assistant Professor, IT Dept, KJSCE

KU Compilerbau - Programming Assignment

CS2210: Compiler Construction. Code Generation

Operators in C. Staff Incharge: S.Sasirekha

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

CS /534 Compiler Construction University of Massachusetts Lowell. NOTHING: A Language for Practice Implementation

Arithmetic Operators. Portability: Printing Numbers

CSC D70: Compiler Optimization

Group B Assignment 9. Code generation using DAG. Title of Assignment: Problem Definition: Code generation using DAG / labeled tree.

Lecture Notes on Intermediate Representation

Laboratory 3 OPERATORS, EXPRESSIONS, INSTRUCTIONS I. THEORETICAL BACKGROUND

Quadsim Version 2.1 Student Manual


Lecture Set 4: More About Methods and More About Operators

Department of Computer Science

Time : 1 Hour Max Marks : 30

Programming Language Processor Theory

Fundamentals of Programming Session 7

Static Checking and Intermediate Code Generation Pat Morin COMP 3002

Introduction to GNU-Octave

Introduction to Computers & Programming

Intermediate Code & Local Optimizations

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

ECE Digital System Design & Synthesis Exercise 1 - Logic Values, Data Types & Operators - With Answers

Chapter 7. Expressions and Assignment Statements (updated edition 11) ISBN

Transcription:

COMPILER CONSTRUCTION (Intermediate Code: three address, control flow) Prof. K R Chowdhary Email: kr.chowdhary@jietjodhpur.ac.in Campus Director, JIET, Jodhpur Thursday 18 th October, 2018 kr chowdhary Intermediate Code 1/ 9

Three-Address Code In three-address code, there is at most one operator on the right side of an instruction; Thus a source-language expression like x+y z might be translated into the sequence of three-address instructions t 1 =y +z t 2 =x+t 1 t 1 and t 2 are compiler-generated temporary names. This unraveling of multi-operator arithmetic expressions and of nested flow-of-control statements makes three-address code desirable for target-code generation and optimization. kr chowdhary Intermediate Code 2/ 9

Three-Address Code Example Dag for the expression a+a (b c)+(b c) d. a + b + Figure 1: Dag for the expression a+a (b c)+(b c) d. c d t 1 = b c t 2 = a t 1 t 3 = a+t 2 t 4 = t 1 d t 5 = t 3 +t 4 Solution. Three-address code is a linearized representation of a syntax tree or a DAG in which explicit names correspond to the interior nodes of the graph. kr chowdhary Intermediate Code 3/ 9

Addresses and Instructions Three-address code can be implemented using records with fields for the addresses; records called quadruples and triples next section. An address can be one of the following: A name. For convenience, we allow source-program names to appear as addresses in three-address code. A constant. A compiler-generated temporary. It is useful, especially in optimizing compilers, to create a distinct name each time a temporary is needed. variables. kr chowdhary Intermediate Code 4/ 9

Addresses and Instructions We will use three-address instructions. Symbolic labels used by instructions alter the flow of control. 1 Assignment instructions of the form x =yopz, where op is a binary arithmetic or logical operation, and x, y, and z are addresses. 2 Assignments of the form x =op y, where op is a unary operation. Essential unary operations include unary minus, logical negation, shift operators, and conversion operators that, for example, convert an integer to a floating-point number. 3 Copy instructions of the form x =y, where x is assigned the value of y. 4 An unconditional jump goto L. The three-address instruction with label L is the next to be executed. kr chowdhary Intermediate Code 5/ 9

Addresses and Instructions... 1 Conditional jumps of the form if x goto L and if False x goto L. These instructions execute the instruction with label L next if x is true and false, respectively. Otherwise, the following three-address instruction in sequence is executed next, as usual. 2 Conditional jumps such as if x relop y goto L, which apply a relational operator (<,==,>=, etc.) to x and y, and execute the instruction with label L next if x stands in relation relop to y. 3 Procedure calls and returns are implemented using the following instructions: param x for parameters; call p, n and y =call p,n for procedure and function calls, respectively; and return y, where y, representing a returned value, is optional. kr chowdhary Intermediate Code 6/ 9

Addresses and Instructions... 1 Their typical use is as the sequence of three- address instructions param x 1 param x 2... param x n call p,n generated as part of a call of the procedure p(x 1,x 2,...,x n ). The integer n, indicating the number of actual parameters in call p,n, is not redundant because calls can be nested. That is, some of the first param statements could be parameters of a call that comes after p returns its value; that value becomes another parameter of the later call. kr chowdhary Intermediate Code 7/ 9

Addresses and Instructions... Example Find out the translation of the following statement: do i =i+1;while (a[i]<v); Solution. One possible translation of this statement is shown below with symbolic labels. L : t 1 =i+1 i =t 1 t 2 =i 8 t 3 =a[t 2 ] if t 3 <v goto L The other translation with position number is shown below: kr chowdhary Intermediate Code 8/ 9

Addresses and Instructions... 100 t 1 =i+1 101 i =t 1 102 t 2 =i 8 103 t 3 =a[t 2 ] 104 if t 3 <v goto 100 The choice of permissible operators is an important issue in the design of an intermediate code. The operator set must be rich enough to implement the all operations in the source language, and efficiently also. kr chowdhary Intermediate Code 9/ 9