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

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.
Lecture 01 - Introduction Eran Yahav 1. 2 Who? Eran Yahav Taub 734 Tel: Monday 13:30-14:30
Intermediate code generation. Code Generation Create linear representation of program Result can be machine code, assembly code, code for an abstract.
1 Intermediate representation Goals: –encode knowledge about the program –facilitate analysis –facilitate retargeting –facilitate optimization scanning.
The Analytical Engine Module 6 Program Translation.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 31: Building a Runnable Program COMP 144 Programming Language Concepts Spring 2002.
Intermediate Code CS 471 October 29, CS 471 – Fall Intermediate Code Generation Source code Lexical Analysis Syntactic Analysis Semantic.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
Topic 6 -Code Generation Dr. William A. Maniatty Assistant Prof. Dept. of Computer Science University At Albany CSI 511 Programming Languages and Systems.
Compiler Construction1 A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University First Semester 2009/2010.
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.
CS412/413 Introduction to Compilers Radu Rugina Lecture 15: Translating High IR to Low IR 22 Feb 02.
COP4020 Programming Languages
Chapter 1. Introduction.
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 장 중 간 언어 컴파일러 입문.
1 Introduction to JVM Based on material produced by Bill Venners.
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
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 1, 08/28/03 Prof. Roy Levow.
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.
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
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.
CSC 4181 Compiler Construction
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.
COP4020 Programming Languages Introduction Prof. Robert van Engelen (modified by Prof. Em. Chris Lacher)
Presented by : A best website designer company. Chapter 1 Introduction Prof Chung. 1.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Prologue Sung-Dong Kim, Dept. of Computer Engineering, Hansung University.
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.
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
Chapter 1 Introduction.
Introduction to Compiler Construction
Computer Architecture Instruction Set Architecture
Intermediate code Jakub Yaghob
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Computer Architecture Instruction Set Architecture
Compiler Chapter 9. Intermediate Languages
Chapter 1 Introduction.
课程名 编译原理 Compiling Techniques
Compiler Construction
An Overview to Compiler Design
Intermediate Representations
Intermediate Code Generation
CSc 453 Interpreters & Interpretation
COP4020 Programming Languages
Intermediate Representations
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 (2012-1) Compiler 2 Source Program Lexical Analyzer Syntax Analyzer Semantic Analyzer Intermediate Code Generator tokens AST Front-End Code Optimizer Target Code Generator Back-End IL Object Program Front-End - language dependant part Back-End - machine dependant part

1. Introduction (2)  Intermediate language  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 (2012-1) Compiler 3

1. Introduction (3)  Disadvantages  Compile time  Inefficient code  code optimization (2012-1) Compiler 4

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 (2012-1) Compiler 5

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

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 (2012-1) Compiler 7

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

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

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: (2012-1) Compiler 10 (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)))

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

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

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 (2012-1) Compiler 13

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 (2012-1) Compiler 14 stack heap constant area CODE STORE PC MP SP NP

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 (2012-1) Compiler 15

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 (2012-1) Compiler 16

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

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) (2012-1) Compiler 18

6. Selection of IL (1)  Recent approach: several ILs  IL S :  Automatically acquired from source  Source language dependent and high level (2012-1) Compiler 19 Source Front-End IL S IL S -IL T IL T Back-End Target

6. Selection of IL (2)  IL T :  Easy to translate into target machine  Target machine dependent and low level  IL S to IL T :  Translate from IL S into IL T (2012-1) Compiler 20