From: <mic...@us...> - 2007-07-04 15:17:38
|
Revision: 145 http://svn.sourceforge.net/pearcolator/?rev=145&view=rev Author: michael_baer Date: 2007-07-04 08:17:39 -0700 (Wed, 04 Jul 2007) Log Message: ----------- - Added support for IfCmp branches to a target address. Modified Paths: -------------- src/org/binarytranslator/arch/arm/decoder/ARM_Translator.java src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java src/org/binarytranslator/generic/decoder/AbstractCodeTranslator.java Modified: src/org/binarytranslator/arch/arm/decoder/ARM_Translator.java =================================================================== --- src/org/binarytranslator/arch/arm/decoder/ARM_Translator.java 2007-07-02 16:02:39 UTC (rev 144) +++ src/org/binarytranslator/arch/arm/decoder/ARM_Translator.java 2007-07-04 15:17:39 UTC (rev 145) @@ -833,8 +833,8 @@ default: throw new RuntimeException("Unexpected condition code: " + condition); - } - + } + arm2ir.setCurrentBlock(condBlock); conditionalInstruction.translate(); } @@ -1773,7 +1773,7 @@ } else { //just branch and never return from it - arm2ir.appendBranch(destination, lazy, BranchType.DIRECT_BRANCH); + arm2ir.appendBranch(destination, lazy); arm2ir.getCurrentBlock().deleteNormalOut(); } } @@ -1798,7 +1798,6 @@ arm2ir.getCurrentBlock().deleteNormalOut(); } } - } public Condition getCondition() { Modified: src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java =================================================================== --- src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java 2007-07-02 16:02:39 UTC (rev 144) +++ src/org/binarytranslator/arch/ppc/decoder/PPC_InstructionDecoder.java 2007-07-04 15:17:39 UTC (rev 145) @@ -11704,7 +11704,7 @@ } if (LK == 0) - ppc2ir.appendBranch(target_address, lazy, BranchType.DIRECT_BRANCH); + ppc2ir.appendBranch(target_address, lazy); else ppc2ir.appendCall(target_address, lazy, pc + 4); @@ -11727,7 +11727,7 @@ ppc2ir.setCurrentBlock(instructionEndBlock); ppc2ir.setNextBlock(ppc2ir.createBlockAfterCurrent()); - ppc2ir.appendBranch(pc + 4, lazy, BranchType.DIRECT_BRANCH); + ppc2ir.appendBranch(pc + 4, lazy); return target_address; } } Modified: src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java =================================================================== --- src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java 2007-07-02 16:02:39 UTC (rev 144) +++ src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java 2007-07-04 15:17:39 UTC (rev 145) @@ -4035,7 +4035,7 @@ translationHelper.appendInstruction(gotoInstr); translationHelper.setCurrentBlock(executeBranch); - translationHelper.appendBranch(target_address, lazy, BranchType.DIRECT_BRANCH); + translationHelper.appendBranch(target_address, lazy); translationHelper.setCurrentBlock(fallThrough); return pc + length; @@ -4169,7 +4169,7 @@ if (modrm == null) { target_address = absolute ? immediate : pc + length + immediate; translationHelper.getCurrentBlock().deleteNormalOut(); - translationHelper.appendBranch(target_address, lazy, BranchType.DIRECT_BRANCH); + translationHelper.appendBranch(target_address, lazy); } else { int operandSize; if (prefix3 == null) { Modified: src/org/binarytranslator/generic/decoder/AbstractCodeTranslator.java =================================================================== --- src/org/binarytranslator/generic/decoder/AbstractCodeTranslator.java 2007-07-02 16:02:39 UTC (rev 144) +++ src/org/binarytranslator/generic/decoder/AbstractCodeTranslator.java 2007-07-04 15:17:39 UTC (rev 145) @@ -34,6 +34,7 @@ import org.jikesrvm.compilers.opt.ir.Call; import org.jikesrvm.compilers.opt.ir.Goto; import org.jikesrvm.compilers.opt.ir.IfCmp; +import org.jikesrvm.compilers.opt.ir.IfCmp2; import org.jikesrvm.compilers.opt.ir.LookupSwitch; import org.jikesrvm.compilers.opt.ir.Move; import org.jikesrvm.compilers.opt.ir.New; @@ -559,13 +560,25 @@ * The address where we shall jump to. * @param targetLaziness * The current at the point of jump. - * @param branchType - * The type of branch that best describes this jump. */ - public void appendBranch(int targetPC, Laziness targetLaziness, BranchType branchType) { + public void appendBranch(int targetPC, Laziness targetLaziness) { + + appendStaticBranch(Goto.create(GOTO, null), targetPC, targetLaziness, BranchType.DIRECT_BRANCH, -1); + } + + /** + * Appends the conditional branch instruction <code>conditional</code> that jumps to the address + * <code>targetPc</code> to the current block. + * + * @param targetPC + * The address where we shall jump to. + * @param targetLaziness + * The current at the point of jump. + */ + public void appendConditionalBranch(OPT_Instruction conditional, int targetPC, Laziness targetLaziness) { - if (DBT.VerifyAssertions && branchType == BranchType.CALL) throw new RuntimeException("Use the more specific appendCall to create dynamic calls."); - appendStaticBranch(targetPC, targetLaziness, branchType, -1); + if (DBT.VerifyAssertions) DBT._assert(IfCmp.conforms(conditional) || IfCmp2.conforms(conditional)); + appendStaticBranch(conditional, targetPC, targetLaziness, BranchType.DIRECT_BRANCH, -1); } /** @@ -582,16 +595,15 @@ */ public void appendCall(int targetPC, Laziness targetLaziness, int retAddr) { - appendStaticBranch(targetPC, targetLaziness, BranchType.CALL, retAddr); + appendStaticBranch(Goto.create(GOTO, null), targetPC, targetLaziness, BranchType.CALL, retAddr); } - private void appendStaticBranch(int targetPC, Laziness targetLaziness, BranchType branchType, int retAddr) { + private void appendStaticBranch(OPT_Instruction branch, int targetPC, Laziness targetLaziness, BranchType branchType, int retAddr) { // Place a GOTO instruction at this point. However, this instruction // serves more as a placeholder and might be mutated later on. - OPT_Instruction jump = Goto.create(GOTO, null); - appendInstruction(jump); + appendInstruction(branch); UnresolvedJumpInstruction unresolvedJump = new UnresolvedJumpInstruction( - jump, (Laziness) targetLaziness.clone(), currentPC, targetPC, BranchType.CALL); + branch, (Laziness) targetLaziness.clone(), currentPC, targetPC, BranchType.CALL); unresolvedDirectBranches.add(unresolvedJump); if (branchType == BranchType.CALL) @@ -677,10 +689,6 @@ int targetPc = unresolvedInstr.targetPC; Laziness lazyStateAtJump = unresolvedInstr.lazyStateAtJump; OPT_Instruction gotoInstr = unresolvedInstr.instruction; - - if (DBT.VerifyAssertions) - DBT._assert(Goto.conforms(gotoInstr)); - OPT_BasicBlock targetBB = resolveBranchTarget(targetPc, unresolvedInstr); if (DBT_Options.debugBranchResolution) { @@ -688,13 +696,32 @@ + " to " + lazyStateAtJump.makeKey(targetPc) + " " + targetBB); } - // Fix up instruction - Goto.setTarget(gotoInstr, targetBB.makeJumpTarget()); + // Fix up instruction + setBranchTarget(gotoInstr, targetBB.makeJumpTarget()); gotoInstr.getBasicBlock().insertOut(targetBB); } } /** + * Sets the target of the branching instruction <code>branch</code> to <code>target</code>. + * @param branch + * A branching instruction. Either a Goto or + * @param target + * The jump target. + */ + private void setBranchTarget(OPT_Instruction branch, OPT_BranchOperand target) { + if (Goto.conforms(branch)) { + Goto.setTarget(branch, target); + } + else if (IfCmp.conforms(branch)) { + IfCmp.setTarget(branch, target); + } + else if (IfCmp2.conforms(branch)) { + IfCmp2.setTarget1(branch, target); + } + } + + /** * This function is being called to decide whether a branch to <code>targetPc</code> (caused by the * jump instruction <code>jump</code>) shall be inlined into the trace. This function is only called when * the jump target is not part of the current trace anyway. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |