Compiler Chapter 9. Intermediate Languages

Slides:



Advertisements
Similar presentations
1 Lecture 10 Intermediate Representations. 2 front end »produces an intermediate representation (IR) for the program. optimizer »transforms the code in.
Advertisements

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 Representation I High-Level to Low-Level IR Translation EECS 483 – Lecture 17 University of Michigan Monday, November 6, 2006.
Chapter 14: Building a Runnable Program Chapter 14: Building a runnable program 14.1 Back-End Compiler Structure 14.2 Intermediate Forms 14.3 Code.
Lecture 01 - Introduction Eran Yahav 1. 2 Who? Eran Yahav Taub 734 Tel: Monday 13:30-14:30
The Analytical Engine Module 6 Program Translation.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
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.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Chapter 1. Introduction.
10/1/2015© Hal Perkins & UW CSEG-1 CSE P 501 – Compilers Intermediate Representations Hal Perkins Autumn 2009.
1 October 1, October 1, 2015October 1, 2015October 1, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa.
PL&C Lab, DongGuk University Compiler Lecture Note, Intermediate LanguagePage 1 제 9 장 중 간 언어 컴파일러 입문.
CS412/413 Introduction to Compilers and Translators May 3, 1999 Lecture 34: Compiler-like Systems JIT bytecode interpreter src-to-src translator bytecode.
Chapter 8 Intermediate Code Zhang Jing, Wang HaiLing College of Computer Science & Technology Harbin Engineering University.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Compiler Chapter# 5 Intermediate code generation.
Computer Architecture Instruction Set Architecture Lynn Choi Korea University.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
Introduction to Code Generation and Intermediate Representations
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
Programming Languages
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
Winter Compilers Software Eng. Dept. – Ort Braude Compiling Assignments and Expressions Lecturer: Esti Stein brd4.ort.org.il/~esti2.
Intermediate Code Representations
Compiler Introduction 1 Kavita Patel. Outlines 2  1.1 What Do Compilers Do?  1.2 The Structure of a Compiler  1.3 Compilation Process  1.4 Phases.
Intermediate Language  Compiler Model Front-End− language dependant part Back-End− machine dependant part [1/34]
Introduction to Language Programming Hierarchy of programming lang. Based on machine independences: 1. Machine language 2. Assembly language 3. Higher.
1 Structure of a Compiler Source Language Target Language Semantic Analyzer Syntax Analyzer Lexical Analyzer Front End Code Optimizer Target Code Generator.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 10 Ahmed Ezzat.
Presented by : A best website designer company. Chapter 1 Introduction Prof Chung. 1.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Lecture 12 Intermediate Code Generation Translating Expressions
1 Chapter10: Code generator. 2 Code Generator Source Program Target Program Semantic Analyzer Intermediate Code Generator Code Optimizer Code Generator.
Chapter 1 Introduction Samuel College of Computer Science & Technology Harbin Engineering University.
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.
CHAPTER 1 INTRODUCTION TO COMPILER SUNG-DONG KIM, DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
Chapter 1. Introduction.
CS 404 Introduction to Compiler Design
Advanced Computer Systems
Compiler Design (40-414) Main Text Book:
Chapter 1 Introduction.
Introduction to Compiler Construction
Computer Architecture Instruction Set Architecture
Intermediate code Jakub Yaghob
A Simple Syntax-Directed Translator
Compiler Construction (CS-636)
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Computer Architecture Instruction Set Architecture
Compilers.
Chapter 1 Introduction.
课程名 编译原理 Compiling Techniques
Compiler Construction
An Overview to Compiler Design
Intermediate Representations Hal Perkins Autumn 2011
Intermediate Representations
Intermediate Code Generation
CSc 453 Interpreters & Interpretation
COP4020 Programming Languages
Intermediate Representations
Programming Languages 2nd edition Tucker and Noonan
Intermediate Representations Hal Perkins Autumn 2005
CSc 453 Interpreters & Interpretation
Presentation transcript:

Compiler Chapter 9. Intermediate Languages Sung-Dong Kim Dept. of Computer Engineering, Hansung University

1. Introduction (1) Compiler model Source Program Back-End IL Lexical Analyzer Source Program tokens Syntax Analyzer AST Back-End Semantic Analyzer Intermediate Code Generator IL Code Optimizer Object Program Target Code Generator Front-End Front-End - language dependant part Back-End - machine dependant part (2011-1) Compiler

1. Introduction (2) Intermediate language Advantages Link front end and back end of the compiler Advantages Modularity Portability Bridge between semantic gaps Machine-independent code optimization Interpreter can execute on interpretive compiling system (2011-1) Compiler

1. Introduction (3) Disadvantages Compile time Inefficient code  code optimization (2011-1) Compiler

1. Introduction (4) Types of IL Polish notation – postfix representation, IR 3-address code – Triple, Quadruple, Indirect Triple Tree structure code – AST, TCOL, Diana Virtual machine code – P-code, EM-code, U-code, Bytecode (2011-1) Compiler

2. Polish notation (1) Developed by Lucasiewiez Usage Intermediate code for arithmetic expression in Fortran compiler Intermediate code for interpreter like BASIC (2011-1) Compiler

2. Polish notation (2) Postfix notation Operand precedes operator No parenthesis Operator stack Easy to change and fast Appropriate for interpreter Not appropriate for optimization (2011-1) Compiler

3. 3-address code (1) 구성 예 4: a = b * (c + d) 가장 널리 이용 최적화 컴파일러 1개의 연산자 2개의 피연산자 예 4: a = b * (c + d) 가장 널리 이용 최적화 컴파일러 A := B op C (t1 := c + d) (t2 := b * t1) (a := t2 ) (2011-1) Compiler

3. 3-address code (2) Implementation Triple Indirect triple Quadruple (operator, operand1, operand2) Not appropriate for optimization Indirect triple Table for triple’s execution order Quadruple (operator, operand1, operand2, result) Appropriate for optimization (2011-1) Compiler

3. 3-address code (3) RTL (Register Transfer Language) IL for GNU’s C, C++ compiler All operations use register Based on list concept of LISP Ex 7: (set (reg:SI 69) (mem:SI (plus:SI (reg:SI 65) (const_int –4)))) (set (reg:SI 70) (mem:SI (plus:SI (reg:SI 65) (const_int –8)))) (set (reg:SI 68) (plus:SI (reg:SI 69) (reg:SI 70))) (set (mem:SF (plus:SI (reg:SI 65) (const_int –12))) (float:SF (reg:SI 68))) (2011-1) Compiler

4. Tree structure code (1) Advantages Parse tree Represent program’s meaning (semantics) Easy to construct Most appropriate for optimized compiler Parse tree Syntax-directed Many useless information (2011-1) Compiler

4. Tree structure code (2) Abstract syntax tree (AST) Very effective Specify terminal/non-terminal nodes Compile-compiler project (2011-1) Compiler

5. Virtual machine code (1) Portable compiler Virtual machine connects front- and back-end  instruction set Abstract machine No general register Stack machine Virtual machine code (2011-1) Compiler

5. Virtual machine code (1) P-code Intermediate output of Pascal-P compiler P machine Stack machine 4 registers: PC, SP, MP, NP Memory: CODE, STORE stack heap constant area CODE STORE PC MP SP NP (2011-1) Compiler

5. Virtual machine code (2) U-code Intermediate code for portable Pascal compiler developed by Stanford Based on virtual stack machine All operations are performed on stack (2011-1) Compiler

5. Virtual machine code (3) Types of operations Unary instruction: notop, neg Binary instruction : add, sub, … Stack instruction : lod, str, ldc, ldr Constrol instruction : ujp, tjp, fjp Range check instruction : chkh, chkl Indirect-address instruction : ixa, sta Procedure instruction : cal, ret, … Other instruction: bgn, sym (2011-1) Compiler

5. Virtual machine code (4) Bytecode Intermediate language for Java Instructions for Java Virtual Machine (JVM) Portability Interpreter, JIT (Just-In-Time) compiler (2011-1) Compiler

5. Virtual machine code (5) Features Small, simple: transferred on the network Instructions for array, class, exception, thread, … Instructions for data types (iadd, fadd, …) Instructions with composite function (pop2) (2011-1) Compiler

6. Selection of IL (1) Recent approach: several ILs ILS: Automatically acquired from source Source language dependent and high level Source Front-End ILS ILS-ILT ILT Back-End Target (2011-1) Compiler

6. Selection of IL (2) ILT: ILS to ILT : Easy to translate into target machine Target machine dependent and low level ILS to ILT : Translate from ILS into ILT (2011-1) Compiler