1 / 25

Code Generation Example -- 1 source text: x:=1; z := y < x Abstract Syntax Tree:

;. :=. :=. x. 1. z. <. x. y. Code Generation Example -- 1 source text: x:=1; z := y < x Abstract Syntax Tree:. stmts = stmts ‘;’ stmt;. assignment = vars ‘:=‘ exprs;. relation = sum ‘<‘ sum;. b logical i integer r real. Code Generation Example -- 2

shea-leon
Download Presentation

Code Generation Example -- 1 source text: x:=1; z := y < x Abstract Syntax Tree:

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ; := := x 1 z < x y Code Generation Example -- 1 source text: x:=1; z := y < x Abstract Syntax Tree: stmts = stmts ‘;’ stmt; assignment = vars ‘:=‘ exprs; relation = sum ‘<‘ sum; b logical i integer r real

  2. Code Generation Example -- 2 source text: x:=1; z := y < x Abbreviate As stmts_stmtsSEMIstmt ; assignment_varsCOLONEQexprs := relation_sumLTsum < tree.getRoot() root() tree.getNode(nd,k) node(k)

  3. ; := := x 1 z < x y Code Generation Example -- 3 source text: x:=1; z := y < x initial state: x86 code y/right/i z/left/b x/leftright/i symbol table

  4. ; := := x 1 z < x y Code Generation Example -- 4 source text: x:=1; z := y < x genWalk(): emit.prolog() 55 89e5 8b7508 60 55: pushR EBP # save x86 frame pointer 89e5: movRR EBP,ESP # new x86 frame 8b7508: movRP ESI,8 # point at X frame 60: pushA # callee save y/right/i z/left/b x/leftright/i symbol table

  5. ; := := x 1 z < x y Code Generation Example -- 5 source text: x:=1; z := y < x genWalk(): stmtWalk(getRoot()) 55 89e5 8b7508 60 x86 code y/right/i z/left/b x/leftright/i symbol table

  6. ; := := x 1 z < x y Code Generation Example -- 6 source text: x:=1; z := y < x stmtWalk(): assignWalk(getKid(1)) 55 89e5 8b7508 60 x86 code y/right/i z/left/b x/leftright/i symbol table

  7. ; := := x 1 z < x y Code Generation Example -- 7 source text: x:=1; z := y < x assignWalk(): lhs=varsWalk(getKid(1)) 55 89e5 8b7508 60 x86 code y/right/i z/left/b x/leftright/i symbol table

  8. ; := := x 1 z < x y Code Generation Example -- 8 source text: x:=1; z := y < x varsWalk(): opd=emit.var(tok) 55 89e5 8b7508 60 x86 code y/right/i z/left/b x/leftright/i symbol table

  9. ; := := x 1 z < x y Code Generation Example -- 9 source text: x:=1; z := y < x assignWalk(): rhs=exprsWalk(getKid(3)) 55 89e5 8b7508 60 x86 code y/right/i z/left/b x/leftright/i lhs x symbol table

  10. ; := := x 1 z < x y Code Generation Example -- 10 source text: x:=1; z := y < x exprsWalk(): t=exprWalk(getKid(1)) 55 89e5 8b7508 60 x86 code y/right/i z/left/b x/leftright/i x lhs symbol table

  11. ; := := x 1 z < x y Code Generation Example -- 11 source text: x:=1; z := y < x exprWalk(): opd=emit.expr0(rule,tok) 55 89e5 8b7508 60 x86 code y/right/i z/left/b x/leftright/i 1 rhs x lhs symbol table

  12. ; := := x 1 z < x y Code Generation Example -- 12 source text: x:=1; z := y < x assignWalk(): emit.store(lhs, rhs) 55 89e5 8b7508 60 b801000000 89860000000 b801000000: movRC EAX,=1=0x1 898600000000: movMR 0,EAX (x) rhs 1 y/right/i z/left/b x/leftright/i lhs x symbol table

  13. ; := := x 1 z < x y Code Generation Example – 13 source text: x:=1; z := y < x stmtWalk(): stmtWalk(getKid(2)) 55 89e5 8b7508 60 b801000000 89860000000 x86 code y/right/i z/left/b x/leftright/i symbol table

  14. ; := := x 1 z < x y Code Generation Example – 14 source text: x:=1; z := y < x stmtWalk(): assignWalk(getKid(3)) 55 89e5 8b7508 60 b801000000 89860000000 x86 code y/right/i z/left/b x/leftright/i symbol table

  15. ; := := x 1 z < x y Code Generation Example – 15 source text: x:=1; z := y < x assignWalk(): lhs =varsWalk(getKid(1)) 55 89e5 8b7508 60 b801000000 89860000000 x86 code y/right/i z/left/b x/leftright/i symbol table

  16. ; := := x 1 z < x y Code Generation Example – 16 source text: x:=1; z := y < x varsWalk(): opd=emit.var(tok) 55 89e5 8b7508 60 b801000000 89860000000 x86 code y/right/i z/left/b x/leftright/i symbol table

  17. ; := := x 1 z < x y Code Generation Example – 17 source text: x:=1; z := y < x assignWalk(): rhs =exprsWalk(getKid(3)) 55 89e5 8b7508 60 b801000000 89860000000 x86 code y/right/i z/left/b x/leftright/i lhs z symbol table

  18. ; := := x 1 z < x y Code Generation Example – 18 source text: x:=1; z := y < x exprWalk(): lft=exprWalk(getKid(1)) 55 89e5 8b7508 60 b801000000 89860000000 x86 code y/right/i z/left/b x/leftright/i lhs z symbol table

  19. ; := := x 1 z < x y Code Generation Example – 19 source text: x:=1; z := y < x exprWalk(): res=emit.expr0(tok) 55 89e5 8b7508 60 b801000000 89860000000 x86 code y/right/i z/left/b x/leftright/i lhs z symbol table

  20. ; := := x 1 z < x y Code Generation Example – 20 source text: x:=1; z := y < x exprWalk(): rgt=exprWalk(getKid(3)) 55 89e5 8b7508 60 b801000000 89860000000 x86 code y/right/i z/left/b x/leftright/i y lft lhs z symbol table

  21. ; := := x 1 z < x y Code Generation Example – 21 source text: x:=1; z := y < x exprWalk(): res = emit.expr0(r, tok) 55 89e5 8b7508 60 b801000000 89860000000 x86 code y/right/i z/left/b x/leftright/i y lft lhs z symbol table

  22. ; := := x 1 z < x y Code Generation Example – 22 source text: x:=1; z := y < x exprWalk(): emit.expr2(rule,lft,rgt) 55 89e5 8b7508 60 b801000000 89860000000 8b8608000000 8b8e00000000 3bc1 8b8608000000: movRM EAX,8 (y) 8b8e00000000: movRM ECX,0 (x) 3bc1: cmpRR EAX,ECX x rgt y/right/i z/left/b x/leftright/i y lft lhs z symbol table

  23. ; := := x 1 z < x y Code Generation Example – 23 source text: x:=1; z := y < x assignWalk(): emit.store(lhs,rhs) 55 89e5 8b7508 60 b801000000 89860000000 8b8608000000 8b8e00000000 3bc1 0f9cc0 81e001000000 898604000000 0f9cc0: setlR EAX 81e001000000: andRC EAX,=1=0x1 898604000000: movMR 4,EAX (z) y/right/i z/left/b x/leftright/i F rhs lhs z symbol table

  24. ; := := x 1 z < x y Code Generation Example – 24 source text: x:=1; z := y < x stmtWalk(): 55 89e5 8b7508 60 b801000000 89860000000 8b8608000000 8b8e00000000 3bc1 0f9cc0 81e001000000 898604000000 x86 code y/right/i z/left/b x/leftright/i symbol table

  25. ; := := x 1 z < x y Code Generation Example – 25 source text: x:=1; z := y < x genWalk(): emit.epilog() 55 89e5 8b7508 60 b801000000 89860000000 8b8608000000 8b8e00000000 3bc 0f9cc0 81e001000000 898604000000 61 33C0 c9 c3 61: popA # callee restore 33C0: xorRR EAX,EAX # 0 means no error c9: leave # restore stack c3: ret # restore EIP

More Related