Presentation is loading. Please wait.

Presentation is loading. Please wait.

INTERMEDIATE LANGUAGES SUNG-DONG KIM DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.

Similar presentations


Presentation on theme: "INTERMEDIATE LANGUAGES SUNG-DONG KIM DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY."— Presentation transcript:

1 INTERMEDIATE LANGUAGES SUNG-DONG KIM DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY

2 1. INTRODUCTION (1)  Compiler model (2014-1) Compiler 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 2

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

4 1. INTRODUCTION (3)  Disadvantages Compile time Inefficient code  code optimization (2014-1) Compiler 4

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

6 2. POLISH NOTATION (1)  Developed by Lucasiewiez  Usage Intermediate code for arithmetic expression in Fortran compiler Intermediate code for interpreter like BASIC (2014-1) Compiler 6

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

8 3. 3-ADDRESS CODE (1)  Composition 1 operator 2 operands  EX: a = b * (c + d)  Most widely used  Optimized compiler (2014-1) Compiler A := B op C (t1 := c + d) (t2 := b * t1) (a := t2 ) 8

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

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

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

12 4. TREE STRUCTURE CODE (2)  Abstract syntax tree (AST) Very effective Specify terminal/non-terminal nodes Compile-compiler project (2014-1) Compiler 12

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

14 5. VIRTUAL MACHINE CODE (2)  P-code Intermediate output of Pascal-P compiler P machine Stack machine 4 registers: PC, SP, MP, NP Memory: CODE, STORE (2014-1) Compiler stack heap constant area CODE STORE PC MP SP NP 14

15 5. VIRTUAL MACHINE CODE (3)  U-code Intermediate code for portable Pascal compiler developed by Stanford Based on virtual stack machine All operations are performed on stack (2014-1) Compiler 15

16 5. VIRTUAL MACHINE CODE (4) 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 (2014-1) Compiler 16

17 5. VIRTUAL MACHINE CODE (5)  Bytecode Intermediate language for Java Instructions for Java Virtual Machine (JVM) Portability Interpreter, JIT (Just-In-Time) compiler (2014-1) Compiler 17

18 5. VIRTUAL MACHINE CODE (6) Features Small, simple: transferred on the network Instructions for array, class, exception, thread, … Instructions for data types (iadd, fadd, …) Instructions with composite function (pop2) (2014-1) Compiler 18

19 6. SELECTION OF IL (1)  Recent approach: several ILs IL S : Automatically acquired from source Source language dependent and high level (2014-1) Compiler Source Front-End IL S IL S -IL T IL T Back-End Target 19

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


Download ppt "INTERMEDIATE LANGUAGES SUNG-DONG KIM DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY."

Similar presentations


Ads by Google