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
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):
alphonce@buffalo.edu 343 Davis Hall
http:/ /www.cse.buffalo.edu/faculty/alphonce/SP17 /CSE443/index.php https:/ /piazza.com/class/iybn4ndqa1s3ei
Figure 1.6, page 5 of text
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
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
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
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
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)
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()
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
Show the intermediate code that should result from processing the following statement: while ( x < 25 ) { x := x + 1; }
Show the intermediate code that should result from processing the following statement: x = … while ( x < 25 ) { x := x + 1; }
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"