List of usage examples for org.objectweb.asm.tree InsnList getFirst
public AbstractInsnNode getFirst()
From source file:org.epoxide.surge.asm.InstructionComparator.java
License:Creative Commons License
public static InsnList getImportantList(InsnList list) { if (list.size() == 0) return list; final HashMap<LabelNode, LabelNode> labels = new HashMap<>(); for (AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext()) if (insn instanceof LabelNode) { labels.put((LabelNode) insn, (LabelNode) insn); }// w ww. j a v a2 s.c om final InsnList importantNodeList = new InsnList(); for (AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext()) { if (insn instanceof LabelNode || insn instanceof LineNumberNode) { continue; } importantNodeList.add(insn.clone(labels)); } return importantNodeList; }
From source file:org.evosuite.instrumentation.NodeRegularExpression.java
License:Open Source License
/** * <p>matches</p>/*from w ww . j av a 2 s. c o m*/ * * @param instructions a {@link org.objectweb.asm.tree.InsnList} object. * @return a boolean. */ public boolean matches(InsnList instructions) { int match = 0; AbstractInsnNode node = instructions.getFirst(); while (node != instructions.getLast()) { if (node.getType() == AbstractInsnNode.FRAME || node.getType() == AbstractInsnNode.LABEL || node.getType() == AbstractInsnNode.LINE) { node = node.getNext(); continue; } else { boolean found = false; for (int opcode : pattern[match]) { if (node.getOpcode() == opcode) { match++; found = true; break; } } if (!found) match = 0; } if (match == pattern.length) return true; node = node.getNext(); } return false; }
From source file:org.jacoco.playground.filter.MethodDumper.java
License:Open Source License
private static void insertLabels(InsnList list, TestCaseDumper printer) { boolean hasLabel = false; for (AbstractInsnNode node = list.getFirst(); node != null; node = node.getNext()) { switch (node.getType()) { case AbstractInsnNode.LINE: break; case AbstractInsnNode.LABEL: printer.declareLabel(((LabelNode) node).getLabel()); hasLabel = true;/*from w w w . j a va 2 s . co m*/ break; default: if (hasLabel) { hasLabel = false; } else { final Label label = new Label(); printer.declareLabel(label); list.insertBefore(node, new LabelNode(label)); } break; } } }
From source file:org.parboiled.transform.process.SuperCallRewriter.java
License:Apache License
@Override public void process(@Nonnull final ParserClassNode classNode, @Nonnull final RuleMethod method) throws Exception { Objects.requireNonNull(classNode, "classNode"); Objects.requireNonNull(method, "method"); final InsnList instructions = method.instructions; AbstractInsnNode insn = instructions.getFirst(); while (insn.getOpcode() != ARETURN) { if (insn.getOpcode() == INVOKESPECIAL) process(classNode, method, (MethodInsnNode) insn); insn = insn.getNext();/*from w ww. j a v a 2 s .c o m*/ } }
From source file:org.spongepowered.asm.mixin.injection.points.MethodHead.java
License:MIT License
@Override public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) { nodes.add(insns.getFirst()); return true;/* ww w . j a v a 2 s. c o m*/ }
From source file:pxb.android.dex2jar.optimize.D.java
License:Apache License
private void cut(MethodNode method) { InsnList insns = method.instructions; method.instructions = null;//from w w w .j a v a2s .c om { AbstractInsnNode p = insns.getFirst(); if (!(p instanceof LabelNode)) { insns.insertBefore(p, new LabelNode()); } AbstractInsnNode q = insns.getLast(); if (!(q instanceof LabelNode)) { insns.insert(q, new LabelNode()); } } @SuppressWarnings("serial") Map<LabelNode, LabelNode> cloneMap = new HashMap<LabelNode, LabelNode>() { public LabelNode get(Object key) { LabelNode l = super.get(key); if (l == null) { l = new LabelNode(); put((LabelNode) key, l); } return l; } }; Map<LabelNode, Block> preBlockMap = new HashMap<LabelNode, Block>(); int i = 0; LabelNode label = null; Block block = null; List<AbstractInsnNode> currentInsnList = null; for (AbstractInsnNode p = insns.getFirst(); p != null; p = p.getNext()) { final AbstractInsnNode cp = p.clone(cloneMap); switch (cp.getType()) { case AbstractInsnNode.LABEL: { if (label != null) { block = new Block(i++, label); block.insns = currentInsnList; block.next = (LabelNode) cp; addToMap(block); } currentInsnList = new ArrayList<AbstractInsnNode>(); label = (LabelNode) cp; preBlockMap.put(label, block); break; } case AbstractInsnNode.JUMP_INSN: case AbstractInsnNode.LOOKUPSWITCH_INSN: case AbstractInsnNode.TABLESWITCH_INSN: { if (cp.getOpcode() == GOTO) { block = new Block(i++, label); block.next = (LabelNode) ((JumpInsnNode) cp).label; } else {// block = new BranchBlock(i++, label, cp); block.next = (LabelNode) getNextLabelNode(p, insns).clone(cloneMap); } block.insns = currentInsnList; addToMap(block); currentInsnList = null; label = null; break; } case AbstractInsnNode.FRAME: case AbstractInsnNode.LINE: // ignore break; default: switch (cp.getOpcode()) { case IRETURN: case LRETURN: case FRETURN: case DRETURN: case ARETURN: case RETURN: case ATHROW: block = new EndBlock(i++, label, cp); block.next = null; getNextLabelNode(p, insns); block.insns = currentInsnList; addToMap(block); currentInsnList = null; label = null; break; default: currentInsnList.add(cp); } } } for (Iterator<?> it = method.tryCatchBlocks.iterator(); it.hasNext();) { TryCatchBlockNode tcn = (TryCatchBlockNode) it.next(); Block s = map.get((LabelNode) tcn.start.clone(cloneMap)); Block e = map.get((LabelNode) tcn.end.clone(cloneMap)); Block handler = map.get(tcn.handler.clone(cloneMap)); TcbK key = new TcbK(s, e); Map<Block, String> handlers = tcbs.get(key); if (handlers == null) { handlers = new TreeMap<Block, String>(new Comparator<Block>() { @Override public int compare(Block o1, Block o2) { return o1.id - o2.id; } }); tcbs.put(key, handlers); } handlers.put(handler, tcn.type); tcn.start = s.label; tcn.end = e.label; tcn.handler = handler.label; } }