Intermediate code Jakub Yaghob

Slides:



Advertisements
Similar presentations
ANALYSIS OF PROG. LANG. PROGRAM ANALYSIS Instructors: Crista Lopes Copyright © Instructors. 1.
Advertisements

Intermediate Code Generation
1 Chapter 8: Code Generation. 2 Generating Instructions from Three-address Code Example: D = (A*B)+C =* A B T1 =+ T1 C T2 = T2 D.
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.
Chapter 8 ICS 412. Code Generation Final phase of a compiler construction. It generates executable code for a target machine. A compiler may instead generate.
Intermediate Code Generation. 2 Intermediate languages Declarations Expressions Statements.
8 Intermediate code generation
1 Compiler Construction Intermediate Code Generation.
Semantic analysis Parsing only verifies that the program consists of tokens arranged in a syntactically-valid combination, we now move on to semantic analysis,
Intermediate Representation I High-Level to Low-Level IR Translation EECS 483 – Lecture 17 University of Michigan Monday, November 6, 2006.
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.
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.
Assemblers.
ISBN Chapter 7 Expressions and Assignment Statements.
Chapter 8 Intermediate Code Zhang Jing, Wang HaiLing College of Computer Science & Technology Harbin Engineering University.
Compiler Chapter# 5 Intermediate code generation.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
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,
Introduction to Code Generation and Intermediate Representations
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.
Intermediate Code Representations
Prepared By: Abhisekh Biswas - 04CS3002 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.
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.
1 Chapter10: Code generator. 2 Code Generator Source Program Target Program Semantic Analyzer Intermediate Code Generator Code Optimizer Code Generator.
INTERMEDIATE LANGUAGES SUNG-DONG KIM DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
Compiler Chapter 9. Intermediate Languages Sung-Dong Kim Dept. of Computer Engineering, Hansung University.
CS 404 Introduction to Compiler Design
MIPS Instruction Set Advantages
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Compiler design Introduction to code generation
Intermediate code generation Jakub Yaghob
Review: Chapter 5: Syntax directed translation
Compiler Construction
Compiler Chapter 9. Intermediate Languages
课程名 编译原理 Compiling Techniques
Compiler Construction
Compiler Construction
Subject Name:COMPILER DESIGN Subject Code:10CS63
Compiler Optimization and Code Generation
Intermediate Code Generation Part I
Intermediate Code Generation
Instructions - Type and Format
Computer Programming Machine and Assembly.
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
Languages and Compilers (SProg og Oversættere)
Intermediate Code Generation
Chapter 6 Programming the basic computer
Intermediate Code Generation Part I
Compiler Construction
Target Code Generation
Compiler Design 21. Intermediate Code Generation
Review: What is an activation record?
Intermediate Code Generating machine-independent intermediate form.
Faculty of Computer Science and Information System
Presentation transcript:

Intermediate code Jakub Yaghob Compiler principles Intermediate code Jakub Yaghob

Intermediate code Intermediate representation of the source code Separates front end from back end Advantages Different back ends for the same input language – support for different CPU architectures gcc Different front ends for the same output language – support more programming languages for the same CPU architecture .NET A machine-independent optimizations – HLO

Intermediate languages Syntax tree Can be even DAG Postfix notation Linearized representation of a syntax tree Tree edges not in notation, can be reconstructed from the order and number of operands of an operator Three-address code Linearized representation of a syntax tree as well A sequence of statements in form x := y op z

Examples – syntax tree and DAG a := b*-c+b*-c assign assign a + a + * * * b uminus b uminus b uminus c c c

Examples – postfix notation and three-address code a b c uminus * b c uminus * + assign t1 := -c t2 := b * t1 t3 := -c t4 := b * t3 t5 := t2 + t4 a := t5 t1 := -c t2 := b * t1 t5 := t2 + t2 a := t5

Three-address code operands A name A variable A type Other names A constant Different literals (UINT, string, …) Temporary variable Generated by a compiler Easily they can be thought of as a CPU registers

Types of three-address statements Binary arithmetic and logical operation Unary operations Assignment/copy Unconditional jump Conditional jump Procedure/function call mechanism Parameters, call, return Array indexation Address operators Address of an object, dereference Declaration

Implementation of three-address code – quadruples A record with four fields op, arg1, arg2, res Some statements don’t use an arg or even res Operands are references to symbol tables op arg1 arg2 res (0) uminus c t1 (1) * b t2 (2) t3 (3) t4 (4) + t5 (5) := a

Implementation of three-address code – triples Avoid generating temporary variables A record with three fields op, arg1, arg2 Operands are references to the symbol tables (constants or variables) or a position of the statement that compute a value op arg1 arg2 (0) uminus c (1) * b (2) (3) (4) + (5) := a

Implementation of three-address code – indirect triples One array with triples One array with references op arg1 arg2 (0) uminus c (1) * b [0] (2) (3) [2] (4) + [1] [3] (5) := a [4] stmt [0] (0) [1] (1) [2] (2) [3] (3) [4] (4) [5] (5)

Implementation comparison Quadruples Better for intermediate code optimization They can be easily moved, names remain the same Triples Tighter Poor handling while optimizing – renumbering in the whole intermediate code Indirect triples Good handling while optimizing – the change is only in the reference array About the same memory size as quadruples