Compilerconstructie. najaar Rudy van Vliet kamer 124 Snellius, tel rvvliet(at)liacs(dot)nl

Similar documents
Compilerconstructie. najaar Rudy van Vliet kamer 140 Snellius, tel rvvliet(at)liacs(dot)nl. college 7, vrijdag 2 november 2018

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

Intermediate Representa.on

Module 26 Backpatching and Procedures

CSE302: Compiler Design

THEORY OF COMPILATION

Chapter 6 Intermediate Code Generation

Intermediate Code Generation Part II

Theory of Compilation Erez Petrank. Lecture 7: Intermediate Representation Part 2: Backpatching

Intermediate Code Generation

Compilerconstructie. najaar Rudy van Vliet kamer 124 Snellius, tel rvvliet(at)liacs.

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

intermediate-code Generation

Intermediate Code Generation

Intermediate Code Generation

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

Formal Languages and Compilers Lecture X Intermediate Code Generation

Intermediate Code Generation

Boolean Expressions. Lecture 31 Sections 6.6, 6.7. Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

Intermediate Code Generation

Earlier edition Dragon book has been revised. Course Outline Contact Room 124, tel , rvvliet(at)liacs(dot)nl

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

COP5621 Exam 3 - Spring 2005

CSCI565 Compiler Design

Lecture 25 Sections 8.4, 8.6. Fri, Apr 24, 2009

Intermediate Code Generation Part II

Intermediate Code Generation

CSCI565 Compiler Design

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

Principles of Programming Languages

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

Intermediate-Code Generat ion

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

Languages and Compiler Design II IR Code Generation I

Type Checking. Chapter 6, Section 6.3, 6.5

2 Intermediate Representation. HIR (high level IR) preserves loop structure and. More of a wizardry rather than science. in a set of source languages

Compilerconstructie. najaar Rudy van Vliet kamer 140 Snellius, tel rvvliet(at)liacs(dot)nl. college 3, vrijdag 22 september 2017

Concepts Introduced in Chapter 6

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

Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

CS2210: Compiler Construction. Code Generation

CMPSC 160 Translation of Programming Languages. Three-Address Code

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

Concepts Introduced in Chapter 6

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

Code Generation. CS 1622: Code Generation & Register Allocation. Arrays. Why is Code Generation Hard? Multidimensional Arrays. Array Element Address

Control Structures. Boolean Expressions. CSc 453. Compilers and Systems Software. 16 : Intermediate Code IV

LECTURE 17. Expressions and Assignment

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

Compilers. Compiler Construction Tutorial The Front-end

CSE302: Compiler Design

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

Problem Score Max Score 1 Syntax directed translation & type

CSCI Compiler Design

Undergraduate Compilers in a Day

UNIT IV INTERMEDIATE CODE GENERATION

Implementing Algorithms in MIPS Assembly

Syntax-Directed Translation Part II

Compiler Code Generation COMP360

Module 25 Control Flow statements and Boolean Expressions

Data-Flow Analysis Foundations

Intermediate Representations

Intermediate Code Generation

Semantic Analysis and Intermediate Code Generation

Syntax-Directed Translation Part I

Lesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Intermediate Representations

Intermediate Code Generation

Oberon2 Compiler CS335: Compiler Project

Syntax-Directed Translation

Fall Compiler Principles Lecture 6: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev

PRINCIPLES OF COMPILER DESIGN UNIT IV SYNTAX DIRECTED TRANSLATION AND TYPE CHECKING

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

Usually, target code is semantically equivalent to source code, but not always!

Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.

Final Exam Review Questions

General issues. Section 9.1. Compiler Construction: Code Generation p. 1/18

Semantic Actions and 3-Address Code Generation

Control Flow Analysis

Fall Compiler Principles Lecture 5: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev

Dixita Kagathara Page 1

Intermediate Code Generation

Intermediate representation

Static Checking and Intermediate Code Generation Pat Morin COMP 3002

Introduction: From Nand to Tetris

Programming Language Processor Theory

Time : 1 Hour Max Marks : 30

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

CSc 453. Code Generation I Christian Collberg. Compiler Phases. Code Generation Issues. Slide Compilers and Systems Software.

CS 432 Fall Mike Lam, Professor. Code Generation

ELEC 876: Software Reengineering

x = 3 * y + 1; // x becomes 3 * y + 1 a = b = 0; // multiple assignment: a and b both get the value 0

Flow Control. CSC215 Lecture

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Compilers. Intermediate representations and code generation. Yannis Smaragdakis, U. Athens (original slides by Sam

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών

CSE431 Translation of Computer Languages

CS577 Modern Language Processors. Spring 2018 Lecture Optimization

Page No 1 (Please look at the next page )

CSE 340 Fall 2014 Project 4

Transcription:

Compilerconstructie najaar 2013 http://www.liacs.nl/home/rvvliet/coco/ Rudy van Vliet kamer 124 Snellius, tel. 071-527 5777 rvvliet(at)liacs(dot)nl werkcollege 6, dinsdag 22 oktober 2013 Intermediate Code Generation 1

Translation of Array References S id = E; { gen(top.get(id.lexeme) = E.addr);} S L = E; { gen(l.array.base [ L.addr ] = E.addr);} E E 1 +E 2 { E.addr = new Temp(); gen(e.addr = E 1.addr + E 2.addr);} E id { E.addr = top.get(id.lexeme);} E L { E.addr = new Temp(); gen(e.addr = L.array.base [ L.addr ] );} L id [E] { L.array = top.get(id.lexeme); L.type = L.array.type.elem; L.addr = new Temp(); gen(l.addr = E.addr L.type.width);} L L 1 [E] { L.array = L 1.array; L.type = L 1.type.elem; t = new Temp(); L.addr = new Temp(); gen(t = E.addr L.type.width); gen(l.addr = L 1.addr + t);} 2

Exercise 6.4.3 Use the translation of Fig. 6.22 (also in previous slide) to translate the following assignments: a) x = a[i] + b[j] Assume: int[5] a; int[7] b; Syntax tree for types of a and b Parse tree for assignment Annotate 3

Translation Scheme for Backpatching (Boolean Expressions) B B 1 MB 2 { backpatch(b 1.falselist,M.instr); B.truelist = merge(b 1.truelist,B 2.truelist); B.falselist = B 2.falselist;} B B 1 &&MB 2 { backpatch(b 1.truelist,M.instr); B.truelist = B 2.truelist; B.falselist = merge(b 1.falselist,B 2.falselist);} B ( B 1 ) { B.truelist = B 1.truelist; B.falselist = B 1.falselist;} B E 1 rel E 2 { B.truelist = makelist(nextinstr); B.falselist = makelist(nextinstr + 1); gen( if E 1.addr rel.op E 2.addr goto ); gen( goto );} M ǫ { M.instr = nextinstr;} 4

Exercise (Derived from problem 6.7.1(a) from second edition book) Construct the parse tree for the following boolean expression: a==b && (c==d e==f) Using the translation scheme of Fig. 6.43, translate the above expression. Show the true and false lists for each subexpression. You may assume the address of the first instruction generated is 100. The semantic actions needed from Fig. 6.43 are listed in the previous slide. They are also listed in the next slide, with a different numbering of the variables. This numbering may be more useful for the exercise. 5

Translation Scheme for Backpatching (Boolean Expressions) B 3 B 4 M 2 B 5 { backpatch(b 4.falselist,M 2.instr); B 3.truelist = merge(b 4.truelist,B 5.truelist); B 3.falselist = B 5.falselist;} B B 1 &&M 1 B 2 { backpatch(b 1.truelist,M 1.instr); B.truelist = B 2.truelist; B.falselist = merge(b 1.falselist,B 2.falselist);} B 2 ( B 3 ) { B 2.truelist = B 3.truelist; B 2.falselist = B 3.falselist;} B E 1 rel E 2 { B.truelist = makelist(nextinstr); B.falselist = makelist(nextinstr + 1); gen( if E 1.addr rel.op E 2.addr goto ); gen( goto );} M ǫ { M.instr = nextinstr;} 6

Translation Scheme for Backpatching (Flow-of-Control Statements) S if (B) MS 1 { backpatch(b.truelist,m.instr); S.nextlist = merge(b.falselist,s 1.nextlist);} S {L} { S.nextlist = L.nextlist;} S A; { S.nextlist = null;} M ǫ { M.instr = nextinstr;} L L 1 MS { backpatch(l 1.nextlist,M.instr); L.nextlist = S.nextlist;} L S { L.nextlist = S.nextlist;} 7

Exercise (Extension of problem 6.7.1(a) from second edition book) Construct the parse tree for the following program : { if (a==b && (c==d e==f)) x=1; y=x+1 } Using the translation scheme of Fig. 6.43 and Fig. 6.46, translate the above program. Show the next list for each statement or statement list. You may assume the address of the first instruction generated is 100. The semantic actions needed from Fig. 6.46 are listed in the previous slide. They are also listed in the next slide, with a different numbering of the variables. This numbering may be more useful for the exercise. 8

Translation Scheme for Backpatching (Flow-of-Control Statements) S 2 if (B) M 4 S 3 { backpatch(b.truelist,m 4.instr); S 2.nextlist = merge(b.falselist,s 3.nextlist);} S {L} { S.nextlist = L.nextlist;} S 3 A 1 ; { S.nextlist = null;} M ǫ { M.instr = nextinstr;} L L 1 M 3 S 1 { backpatch(l 1.nextlist,M 3.instr); L.nextlist = S 1.nextlist;} L 1 S 2 { L 1.nextlist = S 2.nextlist;} 9