InstructionHandle target = oldIfInst.getTarget(); int relativeTargetOffset = target.getPosition() - oldIfHandle.getPosition(); InstructionHandle nextHandle = oldIfHandle.getNext(); IfInstruction invertedIfInst = oldIfInst.negate(); BranchHandle invertedIfHandle = il.append(oldIfHandle, invertedIfHandle.updateTarget(target, nextHandle); if (oldIfHandle.hasTargeters()) { InstructionTargeter[] targeters = oldIfHandle.getTargeters();
/** * Back patch a flow list. All instruction handles must be branch handles. */ public void backPatch(InstructionHandle target) { if (_elements != null) { final int n = _elements.size(); for (int i = 0; i < n; i++) { BranchHandle bh = (BranchHandle)_elements.elementAt(i); bh.setTarget(target); } _elements.clear(); // avoid backpatching more than once } }
public void visitBranchInstruction(BranchInstruction bi) { BranchHandle bh = (BranchHandle)branch_map.get(bi); int pos = bh.getPosition(); String name = bi.getName() + "_" + pos; int t_pos = bh.getTarget().getPosition(); String target; if(bh.hasTargeters()) _out.println(" ih_" + pos + " = il.append(" + name + ");"); else
InstructionHandle target = oldIfInst.getTarget(); int relativeTargetOffset = target.getPosition() - oldIfHandle.getPosition(); invertedIfHandle.updateTarget(target, nextHandle);
private void updateBranchTargets() { for(Iterator i = branches.iterator(); i.hasNext(); ) { BranchInstruction bi = (BranchInstruction)i.next(); BranchHandle bh = (BranchHandle)branch_map.get(bi); int pos = bh.getPosition(); String name = bi.getName() + "_" + pos; int t_pos = bh.getTarget().getPosition(); _out.println(" " + name + ".setTarget(ih_" + t_pos + ");"); if(bi instanceof Select) { InstructionHandle[] ihs = ((Select)bi).getTargets(); for(int j = 0; j < ihs.length; j++) { t_pos = ihs[j].getPosition(); _out.println(" " + name + ".setTarget(" + j + ", ih_" + t_pos + ");"); } } } }
static BranchHandle getBranchHandle( final BranchInstruction i ) { if (bh_list == null) { return new BranchHandle(i); } final BranchHandle bh = bh_list; bh_list = (BranchHandle) bh.getNext(); bh.setInstruction(i); return bh; }
@Test(expected=ClassGenException.class) public void testsetInstructionNull() { final BranchHandle bh = BranchHandle.getBranchHandle(new GOTO(null));// have to start with a valid BI Assert.assertNotNull(bh); bh.setInstruction(null); Assert.assertNotNull(bh); }
/** * Append a branch instruction to the end of this list. * * @param i * branch instruction to append * @return branch instruction handle of the appended instruction */ public BranchHandle append(final BranchInstruction i) { final BranchHandle ih = BranchHandle.getBranchHandle(i); append(ih); return ih; }
static final BranchHandle getBranchHandle(BranchInstruction i) { if(bh_list == null) return new BranchHandle(i); else { BranchHandle bh = bh_list; bh_list = (BranchHandle)bh.next; bh.setInstruction(i); return bh; } }
theBranch.setInstruction(new GOTO(((BranchHandle) theBranch).getTarget())); } else { try {
@Override public void visitBranchInstruction( final BranchInstruction bi ) { final BranchHandle bh = (BranchHandle) branch_map.get(bi); final int pos = bh.getPosition(); final String name = bi.getName() + "_" + pos; if (bi instanceof Select) { final int t_pos = bh.getTarget().getPosition(); String target; if (pos > t_pos) { + ");"); if (bh.hasTargeters()) { _out.println(" ih_" + pos + " = il.append(" + name + ");"); } else {
InstructionHandle target = oldIfInst.getTarget(); int relativeTargetOffset = target.getPosition() - oldIfHandle.getPosition(); invertedIfHandle.updateTarget(target, nextHandle);
private void updateBranchTargets() { for (final BranchInstruction bi : branches) { final BranchHandle bh = (BranchHandle) branch_map.get(bi); final int pos = bh.getPosition(); final String name = bi.getName() + "_" + pos; int t_pos = bh.getTarget().getPosition(); _out.println(" " + name + ".setTarget(ih_" + t_pos + ");"); if (bi instanceof Select) { final InstructionHandle[] ihs = ((Select) bi).getTargets(); for (int j = 0; j < ihs.length; j++) { t_pos = ihs[j].getPosition(); _out.println(" " + name + ".setTarget(" + j + ", ih_" + t_pos + ");"); } } } }
@Test(expected=ClassGenException.class) public void testsetInstructionnotBI() { final BranchHandle bh = BranchHandle.getBranchHandle(new GOTO(null));// have to start with a valid BI Assert.assertNotNull(bh); bh.setInstruction(new NOP()); Assert.assertNotNull(bh); }
/** * Insert a branch instruction at start of this list. * * @param i * branch instruction to insert * @return branch instruction handle of the appended instruction */ public BranchHandle insert(final BranchInstruction i) { final BranchHandle ih = BranchHandle.getBranchHandle(i); insert(ih); return ih; }
public static void compilePreserveSpace(BranchHandle preserve[], int pCount, InstructionList il) { final InstructionHandle target = il.append(ICONST_0); il.append(IRETURN); for (int i = 0; i < pCount; i++) { preserve[i].setTarget(target); } }
InstructionHandle target = oldIfInst.getTarget(); int relativeTargetOffset = target.getPosition() - oldIfHandle.getPosition(); InstructionHandle nextHandle = oldIfHandle.getNext(); IfInstruction invertedIfInst = oldIfInst.negate(); BranchHandle invertedIfHandle = il.append(oldIfHandle, invertedIfHandle.updateTarget(target, nextHandle); if (oldIfHandle.hasTargeters()) { InstructionTargeter[] targeters = oldIfHandle.getTargeters();
@Test public void testsetInstructionBI() { final BranchHandle bh = BranchHandle.getBranchHandle(new GOTO(null));// have to start with a valid BI Assert.assertNotNull(bh); bh.setInstruction(new GOTO(null)); Assert.assertNotNull(bh); }