CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 10 Ahmed Ezzat.

Slides:



Advertisements
Similar presentations
Chapter 6 Intermediate Code Generation
Advertisements

1 Lecture 10 Intermediate Representations. 2 front end »produces an intermediate representation (IR) for the program. optimizer »transforms the code in.
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.
Intermediate Representations Saumya Debray Dept. of Computer Science The University of Arizona Tucson, AZ
CS 31003: Compilers Introduction to Phases of Compiler.
8 Intermediate code generation
1 Compiler Construction Intermediate Code Generation.
Intermediate Representation I High-Level to Low-Level IR Translation EECS 483 – Lecture 17 University of Michigan Monday, November 6, 2006.
CS412/413 Introduction to Compilers Radu Rugina Lecture 16: Efficient Translation to Low IR 25 Feb 02.
Intermediate Representations Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
Intermediate Code Generation Professor Yihjia Tsai Tamkang University.
CS 536 Spring Intermediate Code. Local Optimizations. Lecture 22.
1 Intermediate representation Goals: –encode knowledge about the program –facilitate analysis –facilitate retargeting –facilitate optimization scanning.
Intermediate Code CS 471 October 29, CS 471 – Fall Intermediate Code Generation Source code Lexical Analysis Syntactic Analysis Semantic.
CSC 8505 Compiler Construction Intermediate Representations.
Intermediate Code. Local Optimizations
Topic 6 -Code Generation Dr. William A. Maniatty Assistant Prof. Dept. of Computer Science University At Albany CSI 511 Programming Languages and Systems.
Compiler Construction A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University Second Semester 2008/2009.
7/15/2015\course\cpeg621-10F\Topic-1a.ppt1 Intermediate Code Generation Reading List: Aho-Sethi-Ullman: Chapter 2.3 Chapter 6.1 ~ 6.2 Chapter 6.3 ~ 6.10.
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.
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.
Introduction For some compiler, the intermediate code is a pseudo code of a virtual machine. Interpreter of the virtual machine is invoked to execute the.
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.
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,
Joey Paquet, 2000, Lecture 10 Introduction to Code Generation and Intermediate Representations.
Introduction to Code Generation and Intermediate Representations
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
Code Generation Ⅰ CS308 Compiler Theory1. 2 Background The final phase in our compiler model Requirements imposed on a code generator –Preserving the.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Chapter# 6 Code generation.  The final phase in our compiler model is the code generator.  It takes as input the intermediate representation(IR) produced.
Compilers Modern Compiler Design
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.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Lecture 12 Intermediate Code Generation Translating Expressions
CS 404 Introduction to Compiler Design
Intermediate code Jakub Yaghob
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Compiler Construction
Compiler Construction
Compiler Construction
Compiler Optimization and Code Generation
Intermediate Code Generation Part I
Intermediate Code Generation
Intermediate Representations
Intermediate Code Generation
Chapter 6 Intermediate-Code Generation
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.
Compiler Design 21. Intermediate Code Generation
Intermediate Code Generation Part I
Optimization 薛智文 (textbook ch# 9) 薛智文 96 Spring.
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:

CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 10 Ahmed Ezzat

CS 404Ahmed Ezzat 2 Intermediate Representation (IR) What is IR? – Intermediate code used by compiler, between source and target code Why? – Support multiple front and back end, for example, support a new machine architecture – Subdivide and postpone tasks – Allow for machine-independent optimizations (most important)

CS 404Ahmed Ezzat 3 Different IR Forms Low-level IR – Like RISC machine instructions – Use registers, literals, simple operations High-level IR – Syntax tree – Postfix notation – Three address code (TAC)

CS 404Ahmed Ezzat 4 Three-Address Code (TAC) Basic idea: X = Y op Z X, Y, Z are names, constants or compiler- generated temporaries, op is an operator Example – T = x+y*z – T1 = y*z – T2 = x+T1

CS 404Ahmed Ezzat 5 Why use TAC? Makes complex expressions simple Makes complex flow-of-control simple Easy to re-arrange Easy to optimize Syntax trees or dags can be represented by TAX Close to assembly code, so easy to generate target code

CS 404Ahmed Ezzat 6 Common Three Address Statements[1] Assignment: X := Y + Z Assignment: X := 2 + Z Assignment: X := -1 Copy: X := Y Jump: goto L. (L is a symbolic label, execute the statement labeled by L next.)

CS 404Ahmed Ezzat 7 Common Three Address Statements[2] Conditional jump: if X relop Y then goto L Function or procedure call Param x Param y Call f, 2 Indexed assignment: x := a[10] Indexed assignment: a[10] := x

CS 404Ahmed Ezzat 8 Common Three Address Statements[3] Address assignment: x := &y, x gets location of y Pointer assignment: x := *y, x gets the object pointed by y Pointer assignment: *x :=y, the object pointed by x gets the value of y

CS 404Ahmed Ezzat 9 TAC Design Trade-offs IRs need to be rich enough to implement the source language Smaller set of operators – Easier to implement – Long sequence of statements Larger set of operators – More difficult to implement – Short sequence of statements

CS 404Ahmed Ezzat 10 How to Generate TAC Use syntax directed translations Can be folded into parsing if desired For a non-terminal E, define attributes – E.place, the name that will hold the value of E – E.code, the TAC evaluating E – newtemp, a new temporary variable

CS 404Ahmed Ezzat 11 Implementation of TAC Compilers can choose to use quadruples, triples, and indirect triples Quadruples: op, arg1, arg2, result Triples: avoid temporary names by using the location of the statement that computes it Indirect triples: list pointers

CS 404Ahmed Ezzat 12 Differences of TAC Implementations Eventually we will put those TACs in different memory locations and run Space: – Quadruples take the most space, while triples take the least. – Optimizations: Easier to move quadruples and indirect triples around, hard to move triples.