Compiler Construction

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
8. Code Generation. Generate executable code for a target machine that is a faithful representation of the semantics of the source code Depends not only.
Intermediate Code Generation. 2 Intermediate languages Declarations Expressions Statements.
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.
Generation of Intermediate Code Compiler Design Lecture (03/30//98) Computer Science Rensselaer Polytechnic.
Compiler Designs and Constructions
Three Address Code Generation Backpatching-I Prepared By: Siddharth Tiwary 04CS3010.
Theory of Compilation Erez Petrank Lecture 7: Intermediate Representation Part 2: Backpatching 1.
1 CMPSC 160 Translation of Programming Languages Fall 2002 Lecture-Modules 17 and 18 slides derived from Tevfik Bultan, Keith Cooper, and Linda Torczon.
Intermediate Code Generation Professor Yihjia Tsai Tamkang University.
1 Intermediate Code generation. 2 Intermediate Code Generation l Intermediate languages l Declarations l Expressions l Statements l Reference: »Chapter.
Compiler Construction A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University Second Semester 2008/2009.
CH4.1 CSE244 Intermediate Code Generation Aggelos Kiayias Computer Science & Engineering Department The University of Connecticut 371 Fairfield Road, Unit.
Test Yourself #2 Test Yourself #3 Initial code: a := x ** 2 b := 3 c := x d := c * c e := b * 2 f := a + d g := e * f.
CSc 453 Intermediate Code Generation Saumya Debray The University of Arizona Tucson.
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.
CSc 453 Intermediate Code Generation Saumya Debray The University of Arizona Tucson.
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.
Compiler Chapter# 5 Intermediate code generation.
1 Intermediate Code Generation Part I Chapter 8 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007.
Chapter 8: Intermediate Code Generation
Intermediate Code Generation
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,
Topic #7: Intermediate Code EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
1 Intermediate Code Generation Abstraction at the source level identifiers, operators, expressions, statements, conditionals, iteration, functions (user.
Chapter# 6 Code generation.  The final phase in our compiler model is the code generator.  It takes as input the intermediate representation(IR) produced.
Boolean expressions 1 productionsemantic action E  E1 or E2E1.trueLabel = E.trueLabel; E1.falseLabel = freshLabel(); E2.trueLabel = E.trueLabel; E2.falseLabel.
Chap. 4, Intermediate Code Generation
1 Structure of a Compiler Source Language Target Language Semantic Analyzer Syntax Analyzer Lexical Analyzer Front End Code Optimizer Target Code Generator.
Theory of Compilation Erez Petrank Lecture 6: Intermediate Representation and Attribute Grammars 1.
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.
1 Chapter10: Code generator. 2 Code Generator Source Program Target Program Semantic Analyzer Intermediate Code Generator Code Optimizer Code Generator.
Compiler Chapter 9. Intermediate Languages Sung-Dong Kim Dept. of Computer Engineering, Hansung University.
CS 404 Introduction to Compiler Design
Intermediate code Jakub Yaghob
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Compiler Chapter 9. Intermediate Languages
Compiler Construction
Intermediate Code Generation
Compiler Designs and Constructions
Subject Name:COMPILER DESIGN Subject Code:10CS63
Compiler Optimization and Code Generation
Intermediate Code Generation Part I
Intermediate Code Generation
Intermediate Representations
Three Address Code Generation Control Statement
Intermediate Code Generation
Chapter 6 Intermediate-Code Generation
Three Address Code Generation - Control Statements
Intermediate Code Generation Part I
Intermediate Representations
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.
7.4 Boolean Expression and Control Flow Statements
CSc 453 Intermediate Code Generation
Compiler Design 21. Intermediate Code Generation
Intermediate Code Generation Part I
Intermediate Code Generation
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.
Presentation transcript:

Compiler Construction Chapter 8 Compiler Construction Dr K. V. N. Sunitha

Intermediate Code Generation Compiler Construction Dr K. V. N. Sunitha

Intermediate Languages There are three types of intermediate representation: Syntax trees Postfix notation Three address code DAG Compiler Construction Dr K. V. N. Sunitha

Compiler Construction Syntax Tree a = b* − (c − d) + b* − (c − d) Compiler Construction Dr K. V. N. Sunitha

Compiler Construction Postfix Notation a = b* − (c − d) + b* − (c − d) Postfix form is as follows: a b c d – - * b c d – - * + = Compiler Construction Dr K. V. N. Sunitha

Compiler Construction Three-Address Code Three address code for the statement a= b* − (c − d)+b* − c − d) is T1 = c − d T2 = − T1 T3 = b*T2 T4 = c − d T5 = − T4 T6 = b*T5 T7 = T3+T6 a = T7 Compiler Construction Dr K. V. N. Sunitha

Compiler Construction DAG a = b* − (c − d) + b* − (c − d) is = + * b - - c d Compiler Construction Dr K. V. N. Sunitha

Implementing Three-Address Code Quadruple • a record structure with four fields Triple • a record structure with three fields Indirect triples • pointer to triples Compiler Construction Dr K. V. N. Sunitha

Types of Three-Address Statements A := B op C A := op B A :=B goto L. if A relop B goto L A: = B[ i ] A:= &B A:= *B B fun(A1,A2,A3,....An) Compiler Construction Dr K. V. N. Sunitha

Three-Address Statement for the x or y not z t1 = not z t2 = y and t1 t3 = x or t2 Compiler Construction Dr K. V. N. Sunitha

Compiler Construction If x < y Then 1 Else 0 Three address code is if a < y go to 13 t1 = 0 go to 14 t1 = 1 Compiler Construction Dr K. V. N. Sunitha

IR Translation of Conditional Statement S → if E then S1 {E.true = newlabel(); E.false = S.next; S1.next = S.next; S.code = E.code || gen(E.true , “ :”) || S1.code } Compiler Construction Dr K. V. N. Sunitha

IR Translation of While Loop S → while E do S1 {S.begin = newlabel(); E.true = newlabel(); E.false = S.next; S1.next = S.next; S.code = gen(S.begin “:”) || || E.code || gen(E.true , “ :”) || S1.code || gen(“GOTO” , S.begin) } Compiler Construction Dr K. V. N. Sunitha