Ch8a - 1 ! Intermediate Code Generation Part I! Chapter...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Intermediate Code Generation Part I Chapter 6 (formerly 1 st ed Chapter 8) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Intermediate Code Generation • Facilitates retargeting : enables attaching a back end for the new machine to an existing front end • Enables machine-independent code optimization Front end Back end Intermediate code Target machine code
Background image of page 2
3 Intermediate Representations Graphical representations (e.g. AST) Postfx notation : operations on values stored on operand stack (similar to JVM bytecode) Three-address code : (e.g. triples and quads ) x := y op z Two-address code : x := op y which is the same as x := x op y
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Syntax-Directed Translation of Abstract Syntax Trees Production S ! id := E E ! E 1 + E 2 E ! E 1 * E 2 E ! - E 1 E ! ( E 1 ) E ! id Semantic Rule S .nptr := mknode (‘:=’, mkleaf ( id , id .entry), E .nptr) E .nptr := mknode (‘+’, E 1 .nptr, E 2 .nptr) E .nptr := mknode (‘*’, E 1 .nptr, E 2 .nptr) E .nptr := mknode (‘uminus’, E 1 .nptr) E .nptr := E 1 .nptr E .nptr := mkleaf ( id , id .entry)
Background image of page 4
5 Abstract Syntax Trees E .nptr * E .nptr E .nptr a b + E .nptr * a + b c E .nptr c E .nptr ( ) a * (b + c) Pro: easy restructuring of code and/or expressions for intermediate code optimization Cons: memory intensive
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Abstract Syntax Trees versus DAGs := a + * uminus b c * uminus b c := a + * uminus b c Tree DAG a := b * -c + b * -c
Background image of page 6
7 Postfx Notation a := b * -c + b * -c a b c uminus * b c uminus * + assign iload 2 // push b iload 3 // push c ineg // uminus imul // * iload 2 // push b iload 3 // push c ineg // uminus imul // * iadd // + istore 1 // store a Bytecode (For example) Postfx notation represents operations on a stack Pro: easy to generate Cons: stack operations are more diFfcult to optimize
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Three-Address Code a := b * -c + b * -c t1 := - c t2 := b * t1 t3 := - c t4 := b * t3 t5 := t2 + t4 a := t5 Linearized representation of a syntax tree t1 := - c t2 := b * t1 t5 := t2 + t2 a := t5 Linearized representation of a syntax DAG
Background image of page 8
9 Three-Address Statements • Assignment statements: x := y op z , x := op y • Indexed assignments: x := y [ i ], x [ i ] := y • Pointer assignments: x := y , x := * y , * x := y • Copy statements: x := y • Unconditional jumps: goto lab • Conditional jumps: if x relop y goto lab • Function calls: param x… call p, n return y
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Syntax-Directed Translation into Three-Address Code Synthesized attributes: S .code three-address code for
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/01/2012 for the course COP 5621 taught by Professor Vanengelen during the Spring '11 term at FSU.

Page1 / 28

Ch8a - 1 ! Intermediate Code Generation Part I! Chapter...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online