What is Three Address Code? A statement of the form x = y op z is a three address statement. x, y and z here are the three operands and op is any logical.

Slides:



Advertisements
Similar presentations
Chapter 6 Intermediate Code Generation
Advertisements

ANALYSIS OF PROG. LANG. PROGRAM ANALYSIS Instructors: Crista Lopes Copyright © Instructors. 1.
Intermediate Code Generation
Intermediate Code Generation. 2 Intermediate languages Declarations Expressions Statements.
Intermediate Representations Saumya Debray Dept. of Computer Science The University of Arizona Tucson, AZ
Backpatching: The syntax directed definition we discussed before can be implemented in two or more passes (we have both synthesized attributes and inheritent.
Short circuit code for boolean expressions: Boolean expressions are typically used in the flow of control statements, such as if, while and for statements,
8 Intermediate code generation
Chapter 8 Intermediate Code Generation. Intermediate languages: Syntax trees, three-address code, quadruples. Types of Three – Address Statements: x :=
1 Compiler Construction Intermediate Code Generation.
PSUCS322 HM 1 Languages and Compiler Design II IR Code Generation I Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU.
Intermediate Representation I High-Level to Low-Level IR Translation EECS 483 – Lecture 17 University of Michigan Monday, November 6, 2006.
Intermediate Code Generation Professor Yihjia Tsai Tamkang University.
1 CS 201 Compiler Construction Lecture 1 Introduction.
CSC 8505 Compiler Construction Intermediate Representations.
Compiler Construction A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University Second Semester 2008/2009.
ECE355 Fall 2004Software Reliability1 ECE-355 Tutorial Jie Lian.
CSc 453 Intermediate Code Generation Saumya Debray The University of Arizona Tucson.
CS412/413 Introduction to Compilers Radu Rugina Lecture 15: Translating High IR to Low IR 22 Feb 02.
CSc 453 Intermediate Code Generation Saumya Debray The University of Arizona Tucson.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
1 Structure of a Compiler Front end of a compiler is efficient and can be automated Back end is generally hard to automate and finding the optimum solution.
Chapter 8 Intermediate Code Zhang Jing, Wang HaiLing College of Computer Science & Technology Harbin Engineering University.
Compiler Chapter# 5 Intermediate code generation.
Chapter 8: Intermediate Code Generation
Review: –What is an activation record? –What are the typical fields in an activation record? –What are the storage allocation strategies? Which program.
Intermediate Code Generation
1 Branches and Procedure Calls Lecture 14 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
1 June 3, June 3, 2016June 3, 2016June 3, 2016 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa Pacific University,
1 CS 201 Compiler Construction Introduction. 2 Instructor Information Rajiv Gupta Office: WCH Room Tel: (951) Office.
Topic #7: Intermediate Code EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
1 Control Flow Analysis Topic today Representation and Analysis Paper (Sections 1, 2) For next class: Read Representation and Analysis Paper (Section 3)
Code Generation CPSC 388 Ellen Walker Hiram College.
1 Structure of a Compiler Source Language Target Language Semantic Analyzer Syntax Analyzer Lexical Analyzer Front End Code Optimizer Target Code Generator.
Three Address Code Generation of Control Statements continued..
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 10 Ahmed Ezzat.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Road Map Regular Exprs, Context-Free Grammars Regular Exprs, Context-Free Grammars LR parsing algorithm LR parsing algorithm Building LR parse tables Building.
CS 404 Introduction to Compiler Design
Intermediate code Jakub Yaghob
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Lecture 4: MIPS Instruction Set
Compiler Construction
Compiler Construction
Intermediate Code Generation
Subject Name:COMPILER DESIGN Subject Code:10CS63
Compiler Optimization and Code Generation
Intermediate Code Generation Part I
Intermediate Code Generation
Three Address Code Generations for Boolean Functions
Three-Address Implementation
Chapter 6 Intermediate-Code Generation
Three Address Code Generation - Control Statements
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises UTPA – Fall 2012 This set of slides is revised from lecture.
CS 201 Compiler Construction
Intermediate Code Generation Part I
Intermediate code generation
Three-address code A more common representation is THREE-ADDRESS CODE . Three address code is close to assembly language, making machine code generation.
Compiler Design 21. Intermediate Code Generation
Intermediate Code Generation Part I
Three Address Code Generation – Backpatching
Intermediate Code Generation
MIPS assembly.
Intermediate Code Generation Part I
Compiler Construction
Compiler Design 21. Intermediate Code Generation
Review: What is an activation record?
Intermediate Code Generating machine-independent intermediate form.
CS 201 Compiler Construction
Presentation transcript:

What is Three Address Code? A statement of the form x = y op z is a three address statement. x, y and z here are the three operands and op is any logical or arithmetic operator. A statement of the form x = y op z is a three address statement. x, y and z here are the three operands and op is any logical or arithmetic operator. Here three address refers to the three addresses in the statement viz addresses of x, y and z. Here three address refers to the three addresses in the statement viz addresses of x, y and z.

Say for example we have a statement Say for example we have a statement a = b + c * d a = b + c * d Then three address code for this statement is :- Then three address code for this statement is :- t1 = c * d t1 = c * d a = b + t1 a = b + t1

Types :- There are different types of three address statements. Some of them are There are different types of three address statements. Some of them are Assignment statements. They are of the form x := y op z where op is a binary arithmetic or logical operation. Assignment statements. They are of the form x := y op z where op is a binary arithmetic or logical operation. Assignment Instructions. They are of the form x := op y where op is an unary operation like unary plus, unary minus shift etc Assignment Instructions. They are of the form x := op y where op is an unary operation like unary plus, unary minus shift etc

Copy statements. They are of the form x := y where the value of y is assigned to x. Copy statements. They are of the form x := y where the value of y is assigned to x. Unconditional Jump goto L. The three address statement with label L is the next to be executed. Unconditional Jump goto L. The three address statement with label L is the next to be executed. Conditional Jumps such as if x relop y goto L. This instruction applies a relational operator (, =) to x and y and executes the statement with label L if the conditional statement is satisfied. Else the statement following if x relop y goto L is executed Conditional Jumps such as if x relop y goto L. This instruction applies a relational operator (, =) to x and y and executes the statement with label L if the conditional statement is satisfied. Else the statement following if x relop y goto L is executed

param x and call p,n for procedure calls and return y where y representing a returned value (optional).Three Address statements for it are as follows. param x and call p,n for procedure calls and return y where y representing a returned value (optional).Three Address statements for it are as follows. param x1 param x1 param x2 param x2 param x3 param x3. param xn param xn call p,n call p,n generated as a part of the three address code for call of the procedure p(x1,x2,x3,....xn) where n are the number of variables being sent to the procedure generated as a part of the three address code for call of the procedure p(x1,x2,x3,....xn) where n are the number of variables being sent to the procedure

Structure for Three Address Code It is a quadruple of an operator, arg1, arg2 and a result or it is a triple of an operator, arg1 and arg2. In triple form arg2 is generally a pointer to the triple structure. It is a quadruple of an operator, arg1, arg2 and a result or it is a triple of an operator, arg1 and arg2. In triple form arg2 is generally a pointer to the triple structure.

Three Address Code Generation Suppose we have the grammar Suppose we have the grammar S ->id := E E -> E+E E -> E*E E -> - E E -> (E) E -> id

Then the three address code for this grammar can be written as:-

E1 refers to the first E that comes in the production. E2 refers to the second E that comes in the production. Here E.code stands for the three address code generated by E and E.place stands for the variable name