cse443 compilers
play

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):


  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

  2. Phases of a compiler Intermediate Representation (IR): specification and generation Figure 1.6, page 5 of text

  3. 6.6.4 Control-flow translation of Boolean Expressions B1.false = newlabel() B1.true = B.true B2.true = B.true B -> B1 || B2 B2.false = B.false B.code = B1.code || label(B1.false) || B2.code B1.true B2.true B.true newlabel() B1 B2 B2.false B1.false B.false

  4. 6.6.4 Control-flow translation of Boolean Expressions backpatch(B1.falselist, M.instr) B.truelist = merge(B1.truelist, B2.truelist) B -> B1 || M B2 B.falselist = B2.falselist B1.truelist B2.truelist B.truelist M B1 B2 B.falselist B2.falselist B1.falselist

  5. 6.6.4 Control-flow translation of Boolean Expressions B1.true = newlabel() B1.false = B.false B2.false = B.false B -> B1 && B2 B2.true = B.true B.code = B1.code || label(B1.true) || B2.code B1.false B2.false B.false newlabel() B1 B2 B2.true B1.true B.true

  6. 6.6.4 Control-flow translation of Boolean Expressions backpatch(B1.truelist, M.instr) B.falselist = merge(B1.falselist, B2.falselist) B -> B1 && M B2 B.truelist = B2.truelist B1.falselist B2.falselist B.falselist M B1 B2 B.truelist B2.truelist B1.truelist

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

  8. 6.6.4 Control-flow translation of Boolean Expressions B.true = newlabel() B.false = newlabel() S -> if (B) S1 S1.next = S2.next = S.next else S2 S.code = B.code || label(B.true) || S1.code || gen('goto',S.next) || label(B.false) || S2.code newlabel() B1.true S1 B newlabel() S2 B1.false

  9. 6.6.4 Control-flow translation of Boolean Expressions backpatch(B.truelist, M1.instr) S -> if (B) M1 S1 backpatch(B.falselist, M2.instr) N else M2 S2 temp = merge(S1.nextlist, N.nextlist) S.nextlist = merge(temp, S2.nextlist) M1 B1.truelist S1 N B M2 S2 B1.falselist

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

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

  12. WW example Show the intermediate code that should result from processing the following statement: x = … 100: x1 = … 101: goto 106 while ( x < 25 ) { 102: if x2 < 25 goto 004 x := x + 1; 103: goto 008 } 104: t1 = x2 + 1 105: x3 = t2 105: goto 001 106: x2 = 𝜚 (x1,x3) 107: goto 102 108: "rest of program"

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend