9.1 Introduction [1/3] - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

9.1 Introduction [1/3]

Description:

... SNOBOL, BASIC general form : e1 e2 ... ek OP (k 1) where, OP : k_ary operator ei : any postfix expression (1 i k) ... – PowerPoint PPT presentation

Number of Views:103
Avg rating:3.0/5.0
Slides: 21
Provided by: 9064
Category:

less

Transcript and Presenter's Notes

Title: 9.1 Introduction [1/3]


1
9.1 Introduction 1/3
  • Compiler Model
  • Front-End - language dependant part
  • Back-End - machine dependant part

2
Introduction 2/3
  • 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

3
Introduction 3/3
  • Two level Code Generation
  • ILS
  • ????? ???? ?? ?? ? ?? ??
  • ?? ??? ????? high level??.
  • ILT
  • ???? ???? ?? ?????? ??? ?? ?? ??
  • ????? ????? low level??.
  • ILS to ILT
  • ILS?? ILT?? ??? ?? ???.

4
9.2 Polish Notation 1/2
  • Polish mathematician Lucasiewiez invented the
    parenthesis-free notation.
  • Postfix(Suffix) Polish Notation
  • earliest IL
  • popular for interpreted language - SNOBOL, BASIC
  • general form
  • e1 e2 ... ek OP (k 1)
  • where, OP k_ary operator
  • ei any postfix expression (1 i k)

5
Polish Notation 2/2
  • example
  • if a then if c-d then ac else ac else ab
  • ?gta 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? ??

6
9.3 Three Address Code 1/3
  • most popular IL, optimizing compiler
  • General form
  • where, A result address
  • B, C operand addresses
  • op operator
  • (1) Quadruple - 4-tuple notation
  • ltoperatorgt,ltoperand1gt,ltoperand2gt,ltresultgt
  • (2) Triple - 3-tuple notation
  • ltoperatorgt,ltoperand1gt,ltoperand2gt
  • (3) Indirect triple - execution order table
    triples

A B op C
7
Three Address Code 2/3
  • example
  • a b c d / e
  • f c d

8
Three Address Code 3/3
  • 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

9
9.4 Tree Structured Code 1/4
  • Abstract Syntax Tree
  • parse tree?? redundant? information ??.
  • Leaf node -- variable name, constant
  • Internal node -- operator
  • ?? 9.8
  • x 0
  • y z 2 y
  • while ((xltn) (vx ! z)) x x1
  • return x

10
Tree Structured Code 2/4
  • 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

11
Tree Structured Code 3/4
  • Example) int a float b
  • ...
  • b a 1
  • Representation ---- graph orientation
  • internal notation ----- efficient
  • external notation ---- debug, interface
  • linear graph notation

12
Pascal-P Code 1/2
  • 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)

13
Pascal-P Code 2/2
14
Ucode 1/8
  • 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 gt 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.

15
Ucode 2/8
  • 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)

16
Ucode 3/8
  • 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

17
Ucode 4/8
  • Example
  • x a b c
  • lod 1 1 / a /
  • lod 1 2 / b /
  • lod 1 3 / c /
  • mult
  • add
  • str 1 4 / x /
  • if (agtb) a a b
  • lod 1 1 / a /
  • lod 1 2 / b /
  • gt
  • fjp next
  • lod 1 1 / a /
  • lod 1 2 / b /
  • add
  • str 1 1 / a /
  • next ...

18
Ucode 5/8
  • 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 Ai
  • lod i // actually (Bi, Oi))
  • lda A // also (block number,
    offset)
  • add // effective address
  • ldi // indirect load gets contents
    of Ai

19
Ucode 6/8
  • sti --- indirect store
  • sti stores stacktop into the address at
    stackstacktop-1,
  • both items are popped.
  • Ai j
  • lod i
  • lda A
  • add
  • lod j
  • Sti

20
Ucode 7/8
  • 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
Write a Comment
User Comments (0)
About PowerShow.com