CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis - - PowerPoint PPT Presentation

cse443 compilers
SMART_READER_LITE
LIVE PREVIEW

CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis - - PowerPoint PPT Presentation

CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis Hall http:/ /www.cse.buffalo.edu/faculty/alphonce/SP17 /CSE443/index.php https:/ /piazza.com/class/iybn4ndqa1s3ei Phases of a compiler Intermediate Representation (IR):


slide-1
SLIDE 1

CSE443 Compilers

  • Dr. Carl Alphonce

alphonce@buffalo.edu 343 Davis Hall

http:/ /www.cse.buffalo.edu/faculty/alphonce/SP17 /CSE443/index.php https:/ /piazza.com/class/iybn4ndqa1s3ei

slide-2
SLIDE 2

Phases of a compiler

Figure 1.6, page 5 of text

Intermediate Representation (IR): specification and generation

slide-3
SLIDE 3

6.6.4 Control-flow translation of Boolean Expressions

B -> B1 || B2 B1.false = newlabel() B1.true = B.true B2.true = B.true B2.false = B.false B.code = B1.code || label(B1.false) || B2.code

B1 B2 newlabel() B1.true B1.false B2.true B2.false B.true B.false

slide-4
SLIDE 4

6.6.4 Control-flow translation of Boolean Expressions

B -> B1 || M B2 backpatch(B1.falselist, M.instr) B.truelist = merge(B1.truelist, B2.truelist) B.falselist = B2.falselist

B1 B2 M B1.truelist B1.falselist B2.truelist B2.falselist B.truelist B.falselist

slide-5
SLIDE 5

6.6.4 Control-flow translation of Boolean Expressions

B -> B1 && B2 B1.true = newlabel() B1.false = B.false B2.false = B.false B2.true = B.true B.code = B1.code || label(B1.true) || B2.code

B1 B2 newlabel() B1.false B1.true B2.false B2.true B.false B.true

slide-6
SLIDE 6

6.6.4 Control-flow translation of Boolean Expressions

B -> B1 && M B2 backpatch(B1.truelist, M.instr) B.falselist = merge(B1.falselist, B2.falselist) B.truelist = B2.truelist

B1 B2 M B1.falselist B1.truelist B2.falselist B2.truelist B.falselist B.truelist

slide-7
SLIDE 7

6.7.3 Backpatching Flow-of-Control statements

S -> if (B) S1 else S2 B.true = newlabel() B.false = newlabel() S1.next = S2.next = S.next S.code = B.code || label(B.true) || S1.code || gen('goto',S.next) || label(B.false) || S2.code S -> if (B) M1 S1 N else M2 S2 backpatch(B.truelist, M1.instr) backpatch(B.falselist, M2.instr) temp = merge(S1.nextlist, N.nextlist) S.nextlist = merge(temp, S2.nextlist)

slide-8
SLIDE 8

6.6.4 Control-flow translation of Boolean Expressions

S -> if (B) S1 else S2 B.true = newlabel() B.false = newlabel() S1.next = S2.next = S.next S.code = B.code || label(B.true) || S1.code || gen('goto',S.next) || label(B.false) || S2.code

B newlabel() B1.true B1.false S1 S2 newlabel()

slide-9
SLIDE 9

6.6.4 Control-flow translation of Boolean Expressions

S -> if (B) M1 S1 N else M2 S2 backpatch(B.truelist, M1.instr) backpatch(B.falselist, M2.instr) temp = merge(S1.nextlist, N.nextlist) S.nextlist = merge(temp, S2.nextlist)

B M1 B1.truelist B1.falselist S1 S2 M2 N

slide-10
SLIDE 10

WW example

Show the intermediate code that should result from processing the following statement: while ( x < 25 ) { x := x + 1; }

slide-11
SLIDE 11

WW example

Show the intermediate code that should result from processing the following statement: x = … while ( x < 25 ) { x := x + 1; }

slide-12
SLIDE 12

WW example

Show the intermediate code that should result from processing the following statement: x = … while ( x < 25 ) { x := x + 1; }

100: x1 = … 101: goto 106 102: if x2 < 25 goto 004 103: goto 008 104: t1 = x2 + 1 105: x3 = t2 105: goto 001 106: x2 = 𝜚(x1,x3) 107: goto 102 108: "rest of program"