This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: 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 Frst) 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 Copyright c 2007 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 proFt or commercial advantage and that copies bear this notice and full citation on the Frst page. Request permission to publish from firstname.lastname@example.org. CS502 Translation to IR trees 1 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 rela- tional 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 DeFne constant value of name n as current code address; NAME ( n ) can be used as target of jumps, calls, etc. CS502 Translation to IR trees 2 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 CS502 Translation to IR trees 3 Translating MiniJava Local variables: Allocate as a temporary t t TEMP Ex(TEMP t ) Array elements: Array expression is reference to array in heap. or exressions e and i , translate e [ i ] as: Ex(MEM(ADD( e .unEx(), ( i .unEx(), CONST( w ))))) where w is the target machines word size: all values are word-sized (scalar) in MiniJava Array bounds check: array index i < e . size ; runtime will put size in word preceding array base Object Felds: Object expression is reference to object in heap....
View Full Document
- Spring '08