{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

06-trans - Translation From ASTs to IR trees Copyright c...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Translation From ASTs to IR trees Copyright c circlecopyrt 2010 by Antony L. Hosking. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and full citation on the first page. To copy otherwise, to republish, to post on servers, or to redistribute to lists, requires prior specific permission and/or fee. Request permission to publish from [email protected]
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
IR trees: Expressions i CONST Integer constant i n NAME Symbolic constant n [a code label] t TEMP Temporary t [one of any number of “registers”] e 1 e 2 BINOP Application of binary operator: ADD, SUB, MUL, DIV [arithmetic] AND, OR, XOR [bitwise logical] SLL, SRL [logical shifts] SRA [arithmetic right-shift] to integer operands e 1 (evaluated first) and e 2 (evaluated second) e MEM Contents of a word of memory starting at address e f [ e 1 ,..., e n ] CALL Procedure call; expression f is evaluated before arguments e 1 ,..., e n s e ESEQ Expression sequence; evaluate s for side-effects, then e for result CS352 Translating ASTs to IR trees 2
Background image of page 2
IR trees: Statements t TEMP e MOVE Evaluate e into temporary t e 1 MEM e 2 MOVE Evaluate e 1 yielding address a , e 2 into word at a e EXP Evaluate e and discard result e [ l 1 ,..., l n ] JUMP Transfer control to address e ; l 1 ,..., l n are all possible values for e e 1 e 2 t f CJUMP Evaluate e 1 then e 2 , yielding a and b , respectively; compare a with b using relational operators: BEQ, BNE [signed and unsigned integers] BLT, BGT, BLE, BGE [signed] jump to t if true, f if false s 1 s 2 SEQ Statement s 1 followed by s 2 n LABEL Define constant value of name n as current code address; NAME ( n ) can be used as target of jumps, calls, etc. CS352 Translating ASTs to IR trees 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Kinds of expressions Expression kinds indicate “how expression might be used” Ex(exp) expressions that compute a value Nx(stm) statements: expressions that compute no value Cx conditionals (jump to true and false destinations) RelCx. op (left, right) eq, ne, gt, lt, ge, le IfThenElseExp expression or statement, depending on use Conversion operators allow use of one form in context of another: unEx convert to tree expression that computes value of inner tree unNx convert to tree statement that computes inner tree but returns no value unCx(t, f) convert to statement that evaluates inner tree and branches to true destination if non-zero, false destination otherwise CS352 Translating ASTs to IR trees 4
Background image of page 4
Translating MiniJava Local variables: Allocate as a temporary t t TEMP Ex(TEMP t ) Array elements: Array expression is reference to array in heap.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}