Intermediate Language  Compiler Model Front-End− language dependant part Back-End− machine dependant part [1/34]

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

Intermediate Code Generation
1 CS 201 Compiler Construction Machine 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.
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 Representations Saumya Debray Dept. of Computer Science The University of Arizona Tucson, AZ
8 Intermediate code generation
1 Compiler Construction Intermediate Code Generation.
Overview of Previous Lesson(s) Over View  Front end analyzes a source program and creates an intermediate representation from which the back end generates.
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.
CS412/413 Introduction to Compilers Radu Rugina Lecture 16: Efficient Translation to Low IR 25 Feb 02.
Intermediate code generation. Code Generation Create linear representation of program Result can be machine code, assembly code, code for an abstract.
Intermediate Representations Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
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.
1 Intermediate representation Goals: encode knowledge about the program facilitate analysis facilitate retargeting facilitate optimization scanning parsing.
CSC 8505 Compiler Construction Intermediate Representations.
Compiler Construction A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University Second Semester 2008/2009.
1 CS Programming Languages Random Access Machines Jeremy R. Johnson.
CS412/413 Introduction to Compilers Radu Rugina Lecture 15: Translating High IR to Low IR 22 Feb 02.
10/1/2015© Hal Perkins & UW CSEG-1 CSE P 501 – Compilers Intermediate Representations Hal Perkins Autumn 2009.
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.
PL&C Lab, DongGuk University Compiler Lecture Note, Intermediate LanguagePage 1 제 9 장 중 간 언어 컴파일러 입문.
LANGUAGE TRANSLATORS: WEEK 24 TRANSLATION TO ‘INTERMEDIATE’ CODE (overview) Labs this week: Tutorial Exercises on Code Generation.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 10, 10/30/2003 Prof. Roy Levow.
Runtime Environments Compiler Construction Chapter 7.
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.
Joey Paquet, 2000, Lecture 10 Introduction to Code Generation and Intermediate Representations.
Intermediate Representation I High-Level to Low-Level IR Translation.
Introduction to Code Generation and Intermediate Representations
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.
Winter Compilers Software Eng. Dept. – Ort Braude Compiling Assignments and Expressions Lecturer: Esti Stein brd4.ort.org.il/~esti2.
Intermediate Code Representations
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
Code Generation CPSC 388 Ellen Walker Hiram College.
Intermediate code generation. Code Generation Create linear representation of program Result can be machine code, assembly code, code for an abstract.
Code Generation How to produce intermediate or target code.
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.
Issues in Code Generation CPSC 388 Ellen Walker Hiram College.
Road Map Regular Exprs, Context-Free Grammars Regular Exprs, Context-Free Grammars LR parsing algorithm LR parsing algorithm Building LR parse tables Building.
Code Generation Part I Chapter 8 (1st ed. Ch.9)
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
COMPILER CONSTRUCTION
Intermediate code Jakub Yaghob
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Compiler Chapter 9. Intermediate Languages
Compilers.
Programming Languages (CS 550) Mini Language Compiler
Code Generation.
Intermediate Representations
Chapter 6 Intermediate-Code Generation
Intermediate Representations
Compiler Design 21. Intermediate Code Generation
Compiler Design 21. Intermediate Code Generation
Review: What is an activation record?
Intermediate Code Generating machine-independent intermediate form.
Programming Languages (CS 360) Mini Language Compiler
Code Optimization.
Presentation transcript:

Intermediate Language  Compiler Model Front-End− language dependant part Back-End− machine dependant part [1/34]

 IL 의 필요성  Modular Construction  Automatic Construction  Easy Translation  Portability  Optimization  Bootstrapping  IL 의 분류  Polish Notation --- Postfix, IR  Three Address Code --- Quadruple, Triple, Indirect triple  Tree Structured Code --- PT, AST, TCOL  Abstract Machine Code --- P-code, EM-code, U-code, Byte-code Intermediate Language [2/34]

Intermediate Language  Two level Code Generation  IL S  소스로부터 자동화에 의해 얻을 수 있는 형태  소스 언어에 의존적이며 high level 이다.  IL T  후단부의 자동화에 의해 목적기계로의 번역이 매우 쉬운 형태  목적기계에 의존적이며 low level 이다.  IL S to IL T  IL S 에서 IL T 로의 번역이 주된 작업임. [3/34]

 Polish mathematician Lucasiewiez invented the parenthesis-free notation.  Postfix(Suffix) Polish Notation  earliest IL  popular for interpreted language - SNOBOL, BASIC  general form : e 1 e 2... e k OP (k ≥ 1) where, OP: k_ary operator e i : any postfix expression (1 ≤ i ≤ k) Intermediate Language [4/34]

Intermediate Language  example : if a then if c-d then a+c else a*c else a+b 〓〉 a L1 BZ c d - L2 BZ a c + L3 BR L2: a c * L3 BR L1: a b + L3:  note 1) high level:source to IL - fast & easy translation IL to target - difficulty 2) easy evaluation - operand stack 3) optimization 부적당 - 다른 IL 로의 translation 필요 4) parentheses free notation - arithmetic expression  interpretive language 에 적합 [5/34]

 most popular IL, optimizing compiler  General form: where,A : result address B, C : operand addresses op : operator (1) Quadruple - 4-tuple notation,,, (2) Triple - 3-tuple notation,, (3) Indirect triple - execution order table & triples Intermediate Language A := B op C [6/34]

Intermediate Language  example  a = b + c * d / e;  f = c * d; [7/34]

 Note  Quadruple vs. Triple  quadruple - optimization 용이  triple - removal of temporary addresses ⇒ Indirect Triple  extensive code optimization 용이  IL rearrange 가능 (triple 제외 )  easy translation - source to IL  difficult to generate good code  quadruple to two-address machine  triple to three-address machine Intermediate Language [8/34]

Intermediate Language  Abstract Syntax Tree  parse tree 에서 redundant 한 information 제거.  Leaf node-- variable name, constant  Internal node-- operator  [ 예제 9.8] { x = 0; y = z + 2 * y; while ((x<n) && (v[x] != z)) x = x+1; return x; } [9/34]

 Tree Structured Common Language(TCOL)  Variants of AST - containing the result of semantic analysis.  TCOL operator - type & context specific operator  Context ┌ value --- rhs of assignment statement ├ location --- lhs of assignment statement ├ boolean--- conditional control statement └ statement--- statement ex). : operand - location result - value while : operand - boolean, statement result - statement Intermediate Language [10/34]

Example)int a; float b;... b = a + 1;  Representation ---- graph orientation internal notation efficient external notation ---- debug, interface linear graph notation Intermediate Language [11/34]

 Pascal P Compiler --- portable compiler producing P_CODE for an abstract machine(P_Machine).  P_Machine hypothetical stack machine designed for Pascal language. (1) Instruction --- closely related to the PASCAL language. (2) Registers PC --- program counter NP --- new pointer SP --- stack pointer MP --- mark pointer (3) Memory CODE --- instruction part STORE --- data part(constant area, stack, heap) Intermediate Language [12/34]

Intermediate Language [13/34]

 Ucode the intermediate form used by the Stanford Portable Pascal compiler. stack-based and is defined in terms of a hypothetical stack machine. Ucode Interpreter : Appendix B.  Addressing stack addressing ===> a tuple : (B, O) B : the block number containing the address O : the offset in words from the beginning of the block, offsets start at 1. label to label any Ucode instruction with a label field. All targets of jumps and procedures must be labeled. All labels must be unique for the entire program. Intermediate Language [14/34]

 Example :  Consider the following skeleton : int x; void main() { int i; int j; //..... }  block number - 전역변수 : 1 - 함수 내 지역변수 : 2  variable addressing - x : (1,1) - i : (2,1) - j : (2,2) Intermediate Language [15/34]

 Ucode Operations (39 개 )  Unary --- notop, neg, inc, dec, dup  Binary --- add, sub, mult, div, mod, swp and, or, gt, lt, ge, le, eq, ne  Stack Operations --- lod, str, ldc, lda  Control Flow --- ujp, tjp, fjp  Range Checking --- chkh, chkl  Indirect Addressing --- ldi (load indirect), sti (store indirect)  Procedure --- cal, ret, retv, ldp, proc, end  Etc. --- nop, bgn, sym Intermediate Language [16/34]

 Example :  x = a + b * c; lod1 1 /* a */ lod1 2 /* b */ lod1 3 /* c */ mult add str 1 4/* x */  if (a>b) a = a + b; lod1 1/* a */ lod1 2/* b */ gt fjp next lod1 1/* a */ lod1 2/* b */ add str 1 1/* a */ next... Intermediate Language [17/34]

 Indirect Addressing  is used to access the array elements.  ldi --- indirect load  replace stacktop by the value of the item at location stacktop.  to retrieve A[i] : lod i // actually (Bi, Oi)) lda A // also (block number, offset) add // effective address ldi // indirect load gets contents of A[i] Intermediate Language [18/34]

 sti --- indirect store  sti stores stacktop into the address at stack[stacktop-1], both items are popped.  A[i] = j; lod i lda A add lod j Sti Intermediate Language [19/34]

 Procedure Calling Sequence  function definition :  void func(int x, int array[]) { }  function call :  func(a, list);  calling sequence : ldp // load parameter lod a // load the value of actual parameter lda list // load the address of actual parameter call func // call func Intermediate Language [20/34]