Docsity

Representing Linear Codes - Compiler Construction - Lecture Slides, Slides of Compiler Construction

Partial preview of the text

Download Representing Linear Codes - Compiler Construction - Lecture Slides and more Slides Compiler Construction in PDF only on Docsity!

Compiler

Construction

Lecture 37

2

a = b-c + b-c

Parser action attribute code id=id ∗ –id + id ∗ –id id=E 1 ∗ –id + id ∗ –id E 1 .place = b id=E 1

∗ –E

2

  • id ∗ –id E 2 .place = c id=E 1
∗ E

2

  • id ∗ –id E 2 .place = t1 t1 = – c id=E 1
  • id ∗ –id E 1 .place = t2 t2 = b∗t

4

t1 = –c

t2 = b ∗ t

t3 = –c

t4 = b ∗ t

t5 = t2 + t

a = t

a = b-c + b-c**

5 Representing Linear Codes

 Three-address codes are often

implemented as a set of

quadruples

 Each quadruple has four fields

  • an operator
  • two operands (or sources)
  • a destination

7 Simple Array of Quadruples

Target Op Arg1 Arg

t

1

t

2

← y

t

3

× t

1

t

2

t

4

← x

t

5

  • t 4

t

3

8 Array of Pointers to quads

t

1

  • ← 2

t

2

  • ← y

t

3

× t

1

t

2

t

4

  • ← x

t

5

  • t 4
  • t

10 Flow-of-Control Statements S → if E then S

| if E then S

else S

| while E do S

where E is a boolean expression

11 Flow-of-Control Statements  Consider the statement if c < d then x = y + z else x = y – z  One possible 3-address code could be

13 Flow-of-Control Statements  we will assume that a three- address statement can be symbolically labeled  the function newlabel() returns a new symbolic label each time it is called

14 Flow-of-Control Statements  we will assume that a three- address statement can be symbolically labeled  the function newlabel() returns a new symbolic label each time it is called