public static boolean insnEqual(AbstractInsnNode node1, AbstractInsnNode node2) { if (node1.getType() != node2.getType()) { return false; } else if (node1.getOpcode() != node2.getOpcode()) { return false; } switch (node2.getType()) { case VAR_INSN: return varInsnEqual((VarInsnNode) node1, (VarInsnNode) node2); case TYPE_INSN: return typeInsnEqual((TypeInsnNode) node1, (TypeInsnNode) node2); case FIELD_INSN: return fieldInsnEqual((FieldInsnNode) node1, (FieldInsnNode) node2); case METHOD_INSN: return methodInsnEqual((MethodInsnNode) node1, (MethodInsnNode) node2); case LDC_INSN: return ldcInsnEqual((LdcInsnNode) node1, (LdcInsnNode) node2); case IINC_INSN: return iincInsnEqual((IincInsnNode) node1, (IincInsnNode) node2); case INT_INSN: return intInsnEqual((IntInsnNode) node1, (IntInsnNode) node2); default: return true; } }
@Override public void handle(AbstractInsnNode node) throws IncorrectNodeException { super.handle(node); LOG.debug(logNode(node)); checkType(node, IincInsnNode.class); ExpressionStack stack = mState.getActiveStack(); LocalVariable variable = mState.getLocalVariable(((IincInsnNode) node).var); UnaryExpression.OpPosition opPosition = getUnaryOperandPosition(node); if (opPosition != null) { stack.push(new UnaryExpression(node.getOpcode(), variable, DataType.INT, opPosition)); } else { stack.push(new AssignmentExpression(node.getOpcode(), new LeftHandSide(node.getOpcode(), variable), new PrimaryExpression(node.getOpcode(), ((IincInsnNode) node).incr, DataType.INT))); } }
public static boolean insnEqual(AbstractInsnNode node1, AbstractInsnNode node2) { if (node1.getOpcode() != node2.getOpcode()) { return false; } switch (node2.getType()) { case VAR_INSN: return varInsnEqual((VarInsnNode) node1, (VarInsnNode) node2); case TYPE_INSN: return typeInsnEqual((TypeInsnNode) node1, (TypeInsnNode) node2); case FIELD_INSN: return fieldInsnEqual((FieldInsnNode) node1, (FieldInsnNode) node2); case METHOD_INSN: return methodInsnEqual((MethodInsnNode) node1, (MethodInsnNode) node2); case LDC_INSN: return ldcInsnEqual((LdcInsnNode) node1, (LdcInsnNode) node2); case IINC_INSN: return iincInsnEqual((IincInsnNode) node1, (IincInsnNode) node2); case INT_INSN: return intInsnEqual((IntInsnNode) node1, (IntInsnNode) node2); default: return true; } }
private InsnList localVarValue(AbstractInsnNode insnNode, int opositeOpcode, String param) { int varIdx = -1; if (insnNode instanceof VarInsnNode) { varIdx = ((VarInsnNode) insnNode).var; } else if (insnNode instanceof IincInsnNode) { varIdx = ((IincInsnNode) insnNode).var; } else { throw new RuntimeException("Not implemented for type " + insnNode.getClass()); } InsnList instrumentation = new InsnList(); MethodNode methodNode = (MethodNode) mv; if (methodNode.localVariables.size() <= varIdx) { throw new RuntimeException("varInsnNode is pointing outside of local variables!"); } LocalVariableNode localVariableNode = getLocalVariableNode(varIdx, insnNode, methodNode); instrumentation.add(new VarInsnNode(opositeOpcode, varIdx)); instrumentation.add(new LdcInsnNode(localVariableNode.name)); instrumentation.add(new LdcInsnNode(currentLine)); instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "org/evosuite/junit/TestRuntimeValuesDeterminer", "localVarValueChanged", "(" + param + "Ljava/lang/String;I)V")); logger.debug("Adding localVarValueChanged for var {} in line {}.", localVariableNode.name, currentLine); return instrumentation; }
public static boolean insnEqual(AbstractInsnNode node1, AbstractInsnNode node2) { if(node1.getOpcode() != node2.getOpcode()) return false; switch(node2.getType()) { case VAR_INSN: return varInsnEqual((VarInsnNode) node1, (VarInsnNode) node2); case TYPE_INSN: return typeInsnEqual((TypeInsnNode) node1, (TypeInsnNode) node2); case FIELD_INSN: return fieldInsnEqual((FieldInsnNode) node1, (FieldInsnNode) node2); case METHOD_INSN: return methodInsnEqual((MethodInsnNode) node1, (MethodInsnNode) node2); case LDC_INSN: return ldcInsnEqual((LdcInsnNode) node1, (LdcInsnNode) node2); case IINC_INSN: return iincInsnEqual((IincInsnNode) node1, (IincInsnNode) node2); case INT_INSN: return intInsnEqual((IntInsnNode)node1, (IntInsnNode)node2); default: return true; } }
/** * To for loop. * * @param loop * the loop * @return the for loop */ public static ForLoop toForLoop(final Loop loop) { if (loop == null) { return null; } if (!loop.isPlain()) { return null; } final VarInsnNode varNode = (VarInsnNode) loop.getCounter(); final AbstractInsnNode endValue = loop.getEndValue(); final JumpInsnNode ifNode = (JumpInsnNode) loop.getIfNode(); final IincInsnNode iInc = (IincInsnNode) loop.getIInc(); final ForLoopFooter footer = new ForLoopFooter(varNode, endValue, ifNode, iInc); final ForLoopBody body = new ForLoopBody(loop.getBody()); final Number start = NodeHelper.getNumberValue(loop.getStartValue()); final ForLoop forLoop = new ForLoop(body, footer, start); return forLoop; }
private static AbstractInsnNode getStoreOfLoopForIf(final AbstractInsnNode node) { if (node == null) { return null; } if (!NodeHelper.isIf(node)) { return null; } final AbstractInsnNode previous = ((JumpInsnNode) node).label.getPrevious(); if (!NodeHelper.isGoto(previous)) { return null; } final AbstractInsnNode previous2 = previous.getPrevious(); if (previous2 instanceof IincInsnNode) { return ((JumpInsnNode) previous).label.getPrevious(); } return previous2; }
private static AbstractInsnNode getStoreOfLoopForIInc(final AbstractInsnNode node) { if (node == null) { return null; } if (!(node instanceof IincInsnNode)) { return null; } final AbstractInsnNode next = node.getNext(); if (NodeHelper.isGoto(next)) { return ((JumpInsnNode) next).label.getPrevious(); } if (next instanceof LabelNode) { final AbstractInsnNode gotoNode = findGotoForLabel(next, true); if (gotoNode == null) { return null; } return gotoNode.getPrevious(); } return null; }
/** * Gets the loop bounds. * * @param currentNode * the current node * @return the loop bounds */ public static Pair<AbstractInsnNode, AbstractInsnNode> getLoopBounds(final AbstractInsnNode currentNode) { final AbstractInsnNode storeOfLoop; if (NodeHelper.isGoto(currentNode)) { storeOfLoop = getStoreOfLoopForGoto(currentNode); } else if (NodeHelper.isIf(currentNode)) { storeOfLoop = getStoreOfLoopForIf(currentNode); } else if (currentNode instanceof IincInsnNode) { storeOfLoop = getStoreOfLoopForIInc(currentNode); } else { storeOfLoop = currentNode; } final Loop loop = getLoop(storeOfLoop); if (loop == null) { return null; } return Pair.of(loop.getCounter().getPrevious(), loop.getEndOfLoop()); }
/** * Adds the given operation. * * @param opcode * the opcode * @param args * the args * @return the class node builder */ public ClassNodeBuilder add(final int opcode, final Object... args) { if (opcode == IINC) { return addInsn(new IincInsnNode((Integer) args[0], (Integer) args[1])); } if (opcode >= NOP && opcode <= DCONST_1 || opcode >= POP && opcode <= DCMPG || opcode >= IALOAD && opcode <= SALOAD || opcode >= IASTORE && opcode <= SASTORE || opcode == ARRAYLENGTH || opcode == ATHROW) { return addInsn(new InsnNode(opcode)); } if (opcode >= BIPUSH && opcode <= SIPUSH || opcode == NEWARRAY) { return addInsn(new IntInsnNode(opcode, (Integer) args[0])); } if (opcode == LDC) { return loadConstant(args[0]); } if (opcode >= ILOAD && opcode <= ALOAD) { return addInsn(new VarInsnNode(opcode, (Integer) args[0])); } if (opcode >= ISTORE && opcode <= ASTORE) { return addInsn(new VarInsnNode(opcode, (Integer) args[0])); } if (opcode >= IFEQ && opcode <= JSR) { return jump(opcode, (LabelNode) args[0]); } return this; }
/** * Tests that LocalVarInliner is working correctly. * There is a single (direct) store to the var, but * the var is altered via a iinc instruction. Therefore * the load of the variable is not replaced. */ @Test public void testLocalVarInlinerIInc() { // INIT builder.addInsn(new InsnNode(ICONST_0)).// addInsn(new VarInsnNode(ISTORE, 1)).// addInsn(new IincInsnNode(1, 1)).// addInsn(new VarInsnNode(ILOAD, 1)).// addInsn(new InsnNode(IRETURN));// // RUN assertEquals(5, methodNode.instructions.size()); final InsnList optimized = optimizer.optimize(methodNode.instructions, methodNode); // ASSERT assertEquals(5, optimized.size()); assertTrue(optimizer.isOptimized()); assertEquals(ICONST_1, optimized.get(3).getOpcode()); }
public static boolean matchInstruction(AbstractInsnNode ain, AbstractInsnNode ain2) { if (ain.getOpcode() != ain2.getOpcode()) return false; if (ain instanceof InsnNode) { return true; } else if (ain instanceof VarInsnNode) { return ((VarInsnNode)ain).var == ((VarInsnNode)ain2).var; } else if (ain instanceof LdcInsnNode) { return ((LdcInsnNode)ain).cst.equals(((LdcInsnNode)ain2).cst); } else if (ain instanceof IntInsnNode) { return ((IntInsnNode)ain).operand == ((IntInsnNode)ain2).operand; } else if (ain instanceof TypeInsnNode) { return ((TypeInsnNode)ain).desc.equals(((TypeInsnNode)ain2).desc); } else if (ain instanceof FieldInsnNode) { FieldInsnNode fin = (FieldInsnNode)ain; FieldInsnNode fin2 = (FieldInsnNode)ain2; return fin.owner.equals(fin2.owner) && fin.name.equals(fin2.name) && fin.desc.equals(fin2.desc); } else if (ain instanceof MethodInsnNode) { MethodInsnNode min = (MethodInsnNode)ain; MethodInsnNode min2 = (MethodInsnNode)ain2; return min.owner.equals(min2.owner) && min.name.equals(min2.name) && min.desc.equals(min2.desc) && min.itf == min2.itf; } else if (ain instanceof JumpInsnNode) { return ((JumpInsnNode)ain).label == ((JumpInsnNode)ain2).label; } else if (ain instanceof IincInsnNode) { IincInsnNode iin = (IincInsnNode)ain; IincInsnNode iin2 = (IincInsnNode)ain2; return iin.var == iin2.var && iin.incr == iin2.incr; } return false; }
public static boolean matchInstruction(AbstractInsnNode ain, int opcode, Object... args) { if (ain.getOpcode() != opcode) return false; if (ain instanceof InsnNode) { return true; } else if (ain instanceof VarInsnNode) { return args[0] instanceof Integer && ((VarInsnNode)ain).var == (Integer)args[0]; } else if (ain instanceof LdcInsnNode) { return args[0].equals(((LdcInsnNode)ain).cst); } else if (ain instanceof IntInsnNode) { return args[0] instanceof Integer && ((IntInsnNode)ain).operand == (Integer)args[0]; } else if (ain instanceof TypeInsnNode) { return args[0] instanceof String && ((TypeInsnNode)ain).desc.equals(args[0]); } else if (ain instanceof FieldInsnNode) { if (args.length != 3 || !(args[0] instanceof String) || !(args[1] instanceof String) || !(args[2] instanceof String)) return false; FieldInsnNode fin = (FieldInsnNode)ain; return fin.owner.equals(args[0]) && fin.name.equals(args[1]) && fin.desc.equals(args[2]); } else if (ain instanceof MethodInsnNode) { if (args.length != 4 || !(args[0] instanceof String) || !(args[1] instanceof String) || !(args[2] instanceof String) || !(args[3] instanceof Boolean)) return false; MethodInsnNode min = (MethodInsnNode)ain; return min.owner.equals(args[0]) && min.name.equals(args[1]) && min.desc.equals(args[2]) && min.itf == (Boolean)args[3]; } else if (ain instanceof JumpInsnNode) { return args[0] instanceof LabelNode && ((JumpInsnNode)ain).label == args[0]; } else if (ain instanceof IincInsnNode) { if (args.length != 2 || !(args[0] instanceof Integer) || !(args[1] instanceof Integer)) return false; IincInsnNode iin = (IincInsnNode)ain; return iin.var == (Integer)args[0] && iin.incr == (Integer)args[1]; } return false; }
private void convertIincInsn(IincInsnNode insn) { Local local = getLocal(insn.var); assignReadOps(local); if (!units.containsKey(insn)) { AddExpr add = Jimple.v().newAddExpr(local, IntConstant.v(insn.incr)); setUnit(insn, Jimple.v().newAssignStmt(local, add)); } }
/** * Respects {@link #INT_WILDCARD} and {@link #WILDCARD} instruction properties. * Always returns true if {@code a} and {@code b} are label, line number, or frame instructions. * * @return Whether or not the given instructions are equivalent. */ public boolean areInsnsEqual(AbstractInsnNode a, AbstractInsnNode b) { if (a == b) return true; if (a == null || b == null) return false; if (a.equals(b)) return true; if (a.getOpcode() != b.getOpcode()) return false; switch (a.getType()) { case AbstractInsnNode.VAR_INSN: return areVarInsnsEqual((VarInsnNode) a, (VarInsnNode) b); case AbstractInsnNode.TYPE_INSN: return areTypeInsnsEqual((TypeInsnNode) a, (TypeInsnNode) b); case AbstractInsnNode.FIELD_INSN: return areFieldInsnsEqual((FieldInsnNode) a, (FieldInsnNode) b); case AbstractInsnNode.METHOD_INSN: return areMethodInsnsEqual((MethodInsnNode) a, (MethodInsnNode) b); case AbstractInsnNode.LDC_INSN: return areLdcInsnsEqual((LdcInsnNode) a, (LdcInsnNode) b); case AbstractInsnNode.IINC_INSN: return areIincInsnsEqual((IincInsnNode) a, (IincInsnNode) b); case AbstractInsnNode.INT_INSN: return areIntInsnsEqual((IntInsnNode) a, (IntInsnNode) b); default: return true; } }
/** * <p> * getLocalVar * </p> * * @return a int. */ public int getLocalVariableSlot() { if (asmNode instanceof VarInsnNode) return ((VarInsnNode) asmNode).var; else if (asmNode instanceof IincInsnNode) return ((IincInsnNode) asmNode).var; else return -1; }
private Map<String, InsnList> getLocalReplacementsInc(MethodNode mn, String desc, IincInsnNode node, Frame frame) { Map<String, InsnList> replacements = new HashMap<String, InsnList>(); int otherNum = -1; otherNum = node.var; int currentId = mn.instructions.indexOf(node); for (Object v : mn.localVariables) { LocalVariableNode localVar = (LocalVariableNode) v; int startId = mn.instructions.indexOf(localVar.start); int endId = mn.instructions.indexOf(localVar.end); logger.info("Checking local variable " + localVar.name + " of type " + localVar.desc + " at index " + localVar.index); if (!localVar.desc.equals(desc)) logger.info("- Types do not match: " + localVar.name); if (localVar.index == otherNum) logger.info("- Replacement = original " + localVar.name); if (currentId < startId) logger.info("- Out of scope (start) " + localVar.name); if (currentId > endId) logger.info("- Out of scope (end) " + localVar.name); BasicValue newValue = (BasicValue) frame.getLocal(localVar.index); if (newValue == BasicValue.UNINITIALIZED_VALUE) logger.info("- Not initialized"); if (localVar.desc.equals(desc) && localVar.index != otherNum && currentId >= startId && currentId <= endId && newValue != BasicValue.UNINITIALIZED_VALUE) { logger.info("Adding local variable " + localVar.name + " of type " + localVar.desc + " at index " + localVar.index); InsnList list = new InsnList(); list.add(new IincInsnNode(localVar.index, node.incr)); replacements.put(localVar.name, list); } } return replacements; }
private static AbstractNode createNode(AbstractInsnNode ain, NodeTree tree, TreeSize size) { int opcode = ain.opcode(); if (ain instanceof IntInsnNode) { return new NumberNode(tree, ain, size.collapsing, size.producing); } else if (ain instanceof VarInsnNode) { return new VariableNode(tree, ain, size.collapsing, size.producing); } else if (ain instanceof JumpInsnNode) { return new JumpNode(tree, (JumpInsnNode) ain, size.collapsing, size.producing); } else if (ain instanceof FieldInsnNode) { return new FieldMemberNode(tree, ain, size.collapsing, size.producing); } else if (ain instanceof MethodInsnNode) { return new MethodMemberNode(tree, ain, size.collapsing, size.producing); } else if (ain instanceof LdcInsnNode) { Object cst = ((LdcInsnNode) ain).cst; if (cst instanceof Number) { return new NumberNode(tree, ain, size.collapsing, size.producing); } else { return new ConstantNode(tree, ain, size.collapsing, size.producing); } } else if (ain instanceof IincInsnNode) { return new IincNode(tree, ain, size.collapsing, size.producing); } else if (ain instanceof TypeInsnNode) { return new TypeNode(tree, ain, size.collapsing, size.producing); } else { if (opcode >= ICONST_M1 && opcode <= DCONST_1) { return new NumberNode(tree, ain, size.collapsing, size.producing); } else if (opcode >= I2L && opcode <= I2S) { return new ConversionNode(tree, ain, size.collapsing, size.producing); } else if (opcode >= IADD && opcode <= LXOR) { return new ArithmeticNode(tree, ain, size.collapsing, size.producing); } else { return new AbstractNode(tree, ain, size.collapsing, size.producing); } } }
/** * <p> * This method tracks for mapreduce output method. If found, a counter is * incremented. * </p> * * @param startIndex * Start index of the instructions * @param endIndex * End index of the instructions */ private void handleCtxWrite(int startIndex, int endIndex) { for (int i = startIndex; i < endIndex; i++) { AbstractInsnNode ain = this.insnArr[i]; if (ain instanceof MethodInsnNode) { MethodInsnNode min = (MethodInsnNode) ain; if (InstrumentUtil.isOutputMethod(min)) { // adding incremental statement InsnList il = new InsnList(); il.add(new IincInsnNode(this.localVariableSize, 1)); instructions.insertBefore(ain, il); } } } }
private int __calcMaxLocals (final int initial, final InsnList insns) { // // Calculates the maximum number of referenced local variable slots. // TODO LB: Consider reusing MaxCalculator. // int result = initial; for (final AbstractInsnNode insn : Insns.selectAll (insns)) { if (insn instanceof VarInsnNode) { final VarInsnNode varInsn = (VarInsnNode) insn; switch (varInsn.getOpcode()) { case Opcodes.LLOAD: case Opcodes.DLOAD: case Opcodes.LSTORE: case Opcodes.DSTORE: result = Math.max (varInsn.var + 2, result); break; default: result = Math.max (varInsn.var + 1, result); break; } } else if (insn instanceof IincInsnNode) { final IincInsnNode iincInsn = (IincInsnNode) insn; result = Math.max (iincInsn.var + 1, result); } } return result; }
private void __shiftLocalSlots (final int amount, final InsnList insns) { // // Shifts all local variable slot references by a specified amount. // for (final AbstractInsnNode insn : Insns.selectAll (insns)) { if (insn instanceof VarInsnNode) { final VarInsnNode varInsn = (VarInsnNode) insn; varInsn.var += amount; } else if (insn instanceof IincInsnNode) { final IincInsnNode iincInsn = (IincInsnNode) insn; iincInsn.var += amount; } } }
public static int getMaxLocal(InsnList ilist, String desc, int access) { int maxLocals = (Type.getArgumentsAndReturnSizes(desc) >> 2); if ((access & Opcodes.ACC_STATIC) != 0) { --maxLocals; } for (AbstractInsnNode instr : Insns.selectAll (ilist)) { if (instr instanceof VarInsnNode) { VarInsnNode varInstr = (VarInsnNode) instr; switch (varInstr.getOpcode()) { case Opcodes.LLOAD: case Opcodes.DLOAD: case Opcodes.LSTORE: case Opcodes.DSTORE: maxLocals = Math.max(varInstr.var + 2, maxLocals); break; default: maxLocals = Math.max(varInstr.var + 1, maxLocals); break; } } else if (instr instanceof IincInsnNode) { IincInsnNode iinc = (IincInsnNode) instr; maxLocals = Math.max(iinc.var + 1, maxLocals); } } return maxLocals; }
public static Match<AbstractInsnNode> incrementsVariable(final SlotRead<Integer> counterVariable) { return new Match<AbstractInsnNode>() { @Override public boolean test(Context<AbstractInsnNode> context, AbstractInsnNode a) { return (a instanceof IincInsnNode) && context.retrieve(counterVariable).contains(Prelude.isEqualTo(((IincInsnNode)a).var)); } }; }
@Test public void shouldMatchIncrementsToStoredLocalVariable() { Slot<Integer> slot = Slot.create(Integer.class); context.store(slot.write(), 42); IincInsnNode node = new IincInsnNode(42, 1); assertTrue(incrementsVariable(slot.read()).test(context,node)); }
@Test public void shouldNotMatchIncrementsToDifferentLocalVariable() { Slot<Integer> slot = Slot.create(Integer.class); context.store(slot.write(), 42); IincInsnNode node = new IincInsnNode(42 + 1, 1); assertFalse(incrementsVariable(slot.read()).test(context,node)); }
private void interpret(IincInsnNode insn, FrameState frame, BBInfo block) { switch (insn.getOpcode()) { case Opcodes.IINC: Constant<Integer> c = module.constants().getConstant(insn.incr); BinaryInst bi = new BinaryInst(frame.locals[insn.var], BinaryInst.Operation.ADD, c); block.block.instructions().add(bi); frame.locals[insn.var] = bi; break; default: throw new UnsupportedOperationException(""+insn.getOpcode()); } }
private static AbstractInsnNode getStoreOfLoopForGoto(final AbstractInsnNode node) { if (node == null) { return null; } if (!NodeHelper.isGoto(node)) { return null; } if (node.getPrevious() instanceof IincInsnNode) { return ((JumpInsnNode) node).label.getPrevious(); } return node.getPrevious(); }
private List<Integer> getStores(final AbstractInsnNode start, final AbstractInsnNode end) { AbstractInsnNode tmpNode = start; final List<Integer> stores = new ArrayList<>(); while (tmpNode != null && tmpNode != end) { if (tmpNode.getOpcode() >= ISTORE && tmpNode.getOpcode() <= ASTORE) { stores.add(NodeHelper.getVarIndex(tmpNode)); } else if (tmpNode.getOpcode() == IINC) { final IincInsnNode iinc = (IincInsnNode) tmpNode; final int index = iinc.var; stores.add(index); } tmpNode = tmpNode.getNext(); } return stores; }
private void handleIInc(final AbstractInsnNode currentNode, final Map<Integer, Object> knownValues) { if (LoopMatcher.isIIncOfLoop(currentNode)) { return; } final IincInsnNode iinc = (IincInsnNode) currentNode; final int index = iinc.var; if (knownValues.containsKey(index)) { final int currValue = (Integer) knownValues.get(index); final int newValue = currValue + iinc.incr; knownValues.put(index, newValue); } }
private List<AbstractInsnNode> iincsContains(final List<IincInsnNode> iincs, final VarInsnNode node) { final List<AbstractInsnNode> nodes = new ArrayList<>(); for (final IincInsnNode iinc : iincs) { if (iinc.var == node.var) { nodes.add(iinc); } } return nodes; }
private void findNodes(final InsnList original, final List<VarInsnNode> stores, final List<VarInsnNode> users, // final List<IincInsnNode> iincs) { final Iterator<AbstractInsnNode> iterator = original.iterator(); while (iterator.hasNext()) { final AbstractInsnNode node = iterator.next(); if ((node.getOpcode() >= Opcodes.ISTORE) && (node.getOpcode() <= Opcodes.ASTORE)) { stores.add((VarInsnNode) node); } else if ((node.getOpcode() >= Opcodes.ILOAD) && (node.getOpcode() <= Opcodes.ALOAD)) { users.add((VarInsnNode) node); } else if (node.getOpcode() == Opcodes.IINC) { iincs.add((IincInsnNode) node); } } }
private int getIndex(final AbstractInsnNode node) { if (node instanceof VarInsnNode) { return ((VarInsnNode) node).var; } else if (node instanceof IincInsnNode) { return ((IincInsnNode) node).var; } else { return -1; } }
private void setIndex(final AbstractInsnNode node, final int index) { if (node instanceof VarInsnNode) { ((VarInsnNode) node).var = index; } else if (node instanceof IincInsnNode) { ((IincInsnNode) node).var = index; } }
private void updateState(AbstractInsnNode insn) { switch (insn.getType()) { case AbstractInsnNode.INSN: updateState((InsnNode) insn); break; case AbstractInsnNode.INT_INSN: updateState((IntInsnNode) insn); break; case AbstractInsnNode.VAR_INSN: updateState((VarInsnNode) insn); break; case AbstractInsnNode.TYPE_INSN: updateState((TypeInsnNode) insn); break; case AbstractInsnNode.FIELD_INSN: updateState((FieldInsnNode) insn); break; case AbstractInsnNode.METHOD_INSN: updateState((MethodInsnNode) insn); break; case AbstractInsnNode.INVOKE_DYNAMIC_INSN: updateState((InvokeDynamicInsnNode) insn); break; case AbstractInsnNode.JUMP_INSN: updateState((JumpInsnNode) insn); break; case AbstractInsnNode.LABEL: updateState((LabelNode) insn); break; case AbstractInsnNode.LDC_INSN: updateState((LdcInsnNode) insn); break; case AbstractInsnNode.IINC_INSN: updateState((IincInsnNode) insn); break; case AbstractInsnNode.TABLESWITCH_INSN: updateState((TableSwitchInsnNode) insn); break; case AbstractInsnNode.LOOKUPSWITCH_INSN: updateState((LookupSwitchInsnNode) insn); break; case AbstractInsnNode.MULTIANEWARRAY_INSN: updateState((MultiANewArrayInsnNode) insn); break; case AbstractInsnNode.LINE: updateState((LineNumberNode) insn); break; default: throw new Unreachable("Unexpected instruction " + insn); } }
private void updateState(IincInsnNode insn) { state.readLocal(insn.var, Type.INT_TYPE); }
private void build(AbstractInsnNode insn, IRBuilder builder) { switch (insn.getType()) { case AbstractInsnNode.INSN: build((InsnNode) insn, builder); break; case AbstractInsnNode.INT_INSN: build((IntInsnNode) insn, builder); break; case AbstractInsnNode.VAR_INSN: build((VarInsnNode) insn, builder); break; case AbstractInsnNode.TYPE_INSN: build((TypeInsnNode) insn, builder); break; case AbstractInsnNode.FIELD_INSN: build((FieldInsnNode) insn, builder); break; case AbstractInsnNode.METHOD_INSN: build((MethodInsnNode) insn, builder); break; case AbstractInsnNode.INVOKE_DYNAMIC_INSN: build((InvokeDynamicInsnNode) insn, builder); break; case AbstractInsnNode.JUMP_INSN: build((JumpInsnNode) insn, builder); break; case AbstractInsnNode.LABEL: build((LabelNode) insn, builder); break; case AbstractInsnNode.LDC_INSN: build((LdcInsnNode) insn, builder); break; case AbstractInsnNode.IINC_INSN: build((IincInsnNode) insn, builder); break; case AbstractInsnNode.TABLESWITCH_INSN: build((TableSwitchInsnNode) insn, builder); break; case AbstractInsnNode.LOOKUPSWITCH_INSN: build((LookupSwitchInsnNode) insn, builder); break; case AbstractInsnNode.MULTIANEWARRAY_INSN: build((MultiANewArrayInsnNode) insn, builder); break; case AbstractInsnNode.LINE: build((LineNumberNode) insn, builder); break; default: throw new Unreachable("Unexpected instruction " + insn); } }
private void build(IincInsnNode insn, IRBuilder builder) { int local = state.readLocal(insn.var, Type.INT_TYPE).register; builder.addAddLiteral(NumericType.INT, local, local, insn.incr); }
public static boolean iincInsnEqual(IincInsnNode node1, IincInsnNode node2) { return node1.var == node2.var && node1.incr == node2.incr; }