codeShape - Code Shape More on Three-address Code...

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

View Full Document Right Arrow Icon
cs5363 1 Code Shape More on Three-address Code Generation
Background image of page 1

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

View Full DocumentRight Arrow Icon
cs5363 2 Machine Code Translation A single language construct can have many implementations many-to-many mappings from high-level source language to low-level target machine language Different implementations have different efficiency Speed, memory space, register, power consumption Source code x + y + z Low-level three-address code r1 := rx + ry r2 := r1 + rz r1 := rx + rz r2 := r1 + ry r1 := ry + rz r2 := r1 + rx + x y z + + z x y + + y x z + + x y z
Background image of page 2
cs5363 3 Generating Three-Address Code No more support for structured control-flow Function calls=>explicit memory management and goto jumps Every three-address instr=>several machine instructions The original evaluation order is maintained Memory management Every variable must have a location to store its value Register, stack, heap, static storage Memory allocation convention Scalar/atomic values and addresses => registers, runtime stack Arrays => heap Global/static variables => static storage void fee() { int a, *b, c; a = 0; b = &a; *b = 1; c = a + *b; }
Background image of page 3

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

View Full DocumentRight Arrow Icon
cs5363 4 From Expressions To 3-Address For every non-terminal expression E E.place: temporary variable used to store result Synthesized attributes for E Bottom up traversal ensures E.place assigned before used Symbol table has value types and storage for variables What about the value types of expressions? E ::= id ‘=’ E1 { E.place=E1.place; gen_var_store(id.entry, E1.place); } E ::= E1 ‘+’ E2 {E.place=new_tmp(); gen_code(ADD,E1.place,E2.place,E.place);} E ::= (E1) { E.place = E1.place; } E ::= id { E.place=gen_varLoad(id.entry); } E ::= num { E.place=new_tmp(); gen_code(LOADI, num.val, 0, E.place; } Example input: a = b*c+b+2 Should we reuse register for variable b?
Background image of page 4
cs5363 5 Storing And Accessing Arrays Single-dimensional array Accessing ith element: base + (i-low) * w Low: lower bound of dimension; w : element size Multi-dimensional arrays need to locate base addr of each dimension Row-major, column-major, Indirection vector Extend translation scheme to support array access
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/29/2012 for the course CS 5363 taught by Professor Staff during the Spring '08 term at The University of Texas at San Antonio- San Antonio.

Page1 / 16

codeShape - Code Shape More on Three-address Code...

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

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