6Id2xa-Ch8b

# 6Id2xa-Ch8b - 1 Intermediate Code Generation Part II...

This preview shows pages 1–8. Sign up to view the full content.

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Intermediate Code Generation Part II Chapter 6 (1 st ed Chapter 8) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2011 2 Advanced Intermediate Code Generation Techniques Reusing temporary names Addressing array elements Translating logical and relational expressions Translating short-circuit Boolean expressions and fow-oF-control statements with backpatching lists Translating procedure calls 3 Reusing Temporary Names Evaluate E 1 into t1 Evaluate E 2 into t2 t3 := t1 + t2 E 1 + E 2 Modify newtemp () to use a stack: Keep a counter c , initialized to 0 Decrement counter on each use of a \$ i in a three-address statement newtemp () returns temporary \$ c++ (that is, c is post incremented ) If t1 no longer used, can reuse t1 instead of using new temp t3 generate 4 Reusing Temporary Names (contd) x := a * b + c * d - e * f \$ := a * b \$ 1 := c * d \$ := \$0 + \$1 \$ 1 := e * f \$ := \$0- \$1 x := \$0 0 1 1 1 2 2 1 1 1 2 2 1 1 c c decr c incr Statement 5 Addressing Array Elements: One-Dimensional Arrays = base A + ( i- low ) * w = i * w + c where c = base A- low * w with low = 10; w = 4 A : array [10..20] of integer; := A[i] t1 := c // c = base A - 10 * 4 t2 := i * 4 t3 := t1[t2] := t3 6 Addressing Array Elements: Multi-Dimensional Arrays A : array [1..2,1..3] of integer; low 1 = 1, low 2 = 1, n 1 = 2 , n 2 = 3 , w = 4 A[1,1] A[1,2] A[1,3] A[2,1] A[2,2] A[2,3] Row-major A[1,1] A[2,1] A[1,2] A[2,2] A[1,3] A[2,3] Column-major base A base A 7 Addressing Array Elements: Multi-Dimensional Arrays = base A + (( i 1- low 1 ) * n 2 + i 2 - low 2 ) * w = (( i 1 * n 2 ) + i 2 ) * w + c where c = base A- (( low 1 * n 2 ) + low 2 ) *...
View Full 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 / 21

6Id2xa-Ch8b - 1 Intermediate Code Generation Part II...

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

View Full Document
Ask a homework question - tutors are online