List of usage examples for org.objectweb.asm.tree LookupSwitchInsnNode LookupSwitchInsnNode
public LookupSwitchInsnNode(final LabelNode dflt, final int[] keys, final LabelNode[] labels)
From source file:com.facebook.swift.codec.internal.compiler.byteCode.MethodDefinition.java
License:Apache License
public MethodDefinition switchStatement(String defaultCase, List<CaseStatement> cases) { LabelNode defaultLabel = getLabel(defaultCase); int[] keys = new int[cases.size()]; LabelNode[] labels = new LabelNode[cases.size()]; for (int i = 0; i < cases.size(); i++) { keys[i] = cases.get(i).getKey(); labels[i] = getLabel(cases.get(i).getLabel()); }/*from w w w .ja v a2s. c o m*/ instructionList.add(new LookupSwitchInsnNode(defaultLabel, keys, labels)); return this; }
From source file:com.github.fge.grappa.transform.CodeBlock.java
License:Apache License
public CodeBlock lookupswitch(LabelNode defaultHandler, int[] keys, LabelNode[] handlers) { instructionList.add(new LookupSwitchInsnNode(defaultHandler, keys, handlers)); return this; }
From source file:com.github.fge.grappa.transform.CodeBlock.java
License:Apache License
public CodeBlock visitLookupSwitchInsn(LabelNode defaultHandler, int[] keys, LabelNode[] handlers) { instructionList.add(new LookupSwitchInsnNode(defaultHandler, keys, handlers)); return this; }
From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java
License:Open Source License
private void emit(SwitchInst i, InsnList insns) { load(i.getValue(), insns);//from w w w. j a va 2 s .c om LookupSwitchInsnNode insn = new LookupSwitchInsnNode(null, null, null); insn.dflt = labels.get(i.getDefault()); Iterator<Constant<Integer>> cases = i.cases().iterator(); Iterator<BasicBlock> targets = i.successors().iterator(); while (cases.hasNext()) { insn.keys.add(cases.next().getConstant()); insn.labels.add(labels.get(targets.next())); } insns.add(insn); }
From source file:kilim.analysis.BasicBlock.java
License:Open Source License
@SuppressWarnings("unchecked") static ArrayList<BasicBlock> dupCopyContents(boolean deepCopy, BasicBlock targetBB, BasicBlock returnToBB, HashMap<BasicBlock, BasicBlock> bbCopyMap, HashMap<Label, LabelNode> labelCopyMap) throws KilimException { ArrayList<BasicBlock> newBBs = new ArrayList<BasicBlock>(targetBB.getSubBlocks().size()); for (BasicBlock orig : targetBB.getSubBlocks()) { BasicBlock dup = bbCopyMap.get(orig); dup.flags = orig.flags;/*from w w w .j a v a 2 s. c o m*/ dup.caughtExceptionType = orig.caughtExceptionType; dup.startPos = orig.startPos; dup.endPos = orig.endPos; dup.flow = orig.flow; dup.numPredecessors = orig.numPredecessors; dup.startFrame = null; dup.usage = orig.usage.copy(); dup.handlers = orig.handlers; if (orig.follower != null) { dup.follower = bbCopyMap.get(orig.follower); if (dup.follower == null) { assert dup.lastInstruction() == RET; } } dup.successors = new ArrayList<BasicBlock>(orig.successors.size()); if (orig.lastInstruction() == RET) { dup.addSuccessor(returnToBB); } else { for (BasicBlock s : orig.successors) { BasicBlock b = bbCopyMap.get(s); dup.addSuccessor(b); } } if (deepCopy) { MethodFlow flow = targetBB.flow; InsnList instructions = flow.instructions; // copy instructions dup.startLabel = labelCopyMap.get(orig.startLabel).getLabel(); dup.startPos = instructions.size(); dup.endPos = dup.startPos + (orig.endPos - orig.startPos); // Note: last instruction (@endPos) isn't copied in the loop. // If it has labels, a new instruction is generated; either // way the last instruction is appended separately. int newPos = instructions.size(); int end = orig.endPos; // create new labels and instructions for (int i = orig.startPos; i <= end; i++, newPos++) { Label l = flow.getLabelAt(i); if (l != null) { l = labelCopyMap.get(l).getLabel(); assert l != null; flow.setLabel(newPos, l); } if (i != end) { // last insn gets special treatment instructions.add(instructions.get(i)); } } AbstractInsnNode lastInsn = (AbstractInsnNode) instructions.get(orig.endPos); LabelNode dupLabel; int opcode = lastInsn.getOpcode(); if (lastInsn instanceof JumpInsnNode) { JumpInsnNode jin = (JumpInsnNode) lastInsn; if (lastInsn.getOpcode() != JSR) { dupLabel = labelCopyMap.get(jin.label); assert dupLabel != null; lastInsn = new JumpInsnNode(lastInsn.getOpcode(), dupLabel); } } else if (opcode == TABLESWITCH) { TableSwitchInsnNode tsin = (TableSwitchInsnNode) lastInsn; LabelNode[] labels = new LabelNode[tsin.labels.size()]; for (int i = 0; i < labels.length; i++) { dupLabel = labelCopyMap.get(tsin.labels.get(i)); assert dupLabel != null; labels[i] = dupLabel; } dupLabel = labelCopyMap.get(tsin.dflt); assert dupLabel != null; lastInsn = new TableSwitchInsnNode(tsin.min, tsin.max, dupLabel, labels); } else if (opcode == LOOKUPSWITCH) { LookupSwitchInsnNode lsin = (LookupSwitchInsnNode) lastInsn; LabelNode[] labels = new LabelNode[lsin.labels.size()]; for (int i = 0; i < labels.length; i++) { dupLabel = labelCopyMap.get(lsin.labels.get(i)); assert dupLabel != null; labels[i] = dupLabel; } dupLabel = labelCopyMap.get(lsin.dflt); assert dupLabel != null; int[] keys = new int[lsin.keys.size()]; for (int i = 0; i < keys.length; i++) { keys[i] = (Integer) lsin.keys.get(i); } lastInsn = new LookupSwitchInsnNode(dupLabel, keys, labels); } instructions.add(lastInsn); // new handlers dup.handlers = new ArrayList<Handler>(orig.handlers.size()); if (orig.handlers.size() > 0) { for (Handler oh : orig.handlers) { Handler h = new Handler(dup.startPos + (oh.from - orig.startPos), dup.endPos + (oh.to - orig.endPos), oh.type, oh.catchBB); dup.handlers.add(h); } } } newBBs.add(dup); } return newBBs; }
From source file:me.qmx.jitescript.CodeBlock.java
License:Apache License
public CodeBlock lookupswitch(LabelNode arg0, int[] arg1, LabelNode[] arg2) { this.instructionList.add(new LookupSwitchInsnNode(arg0, arg1, arg2)); return this; }
From source file:me.qmx.jitescript.CodeBlock.java
License:Apache License
public CodeBlock visitLookupSwitchInsn(LabelNode arg0, int[] arg1, LabelNode[] arg2) { this.instructionList.add(new LookupSwitchInsnNode(arg0, arg1, arg2)); return this; }
From source file:net.sourceforge.cobertura.instrument.HistoryMethodAdapter.java
License:GNU General Public License
@Override public void visitLookupSwitchInsn(Label arg0, int[] arg1, Label[] arg2) { super.visitLookupSwitchInsn(arg0, arg1, arg2); LabelNode nodes[] = new LabelNode[arg2.length]; for (int i = 0; i < arg2.length; i++) { nodes[i] = new LabelNode(arg2[i]); }/*from w w w . j a va2s . com*/ appendToBacklog(new LookupSwitchInsnNode(new LabelNode(arg0), arg1, nodes)); }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateSwitchAdapter.java
License:Open Source License
@Override public boolean transform() { MethodNode methodNode = getMethod(method); if (methodNode == null) return false; // doesn't exist, don't transform methodNode.instructions.clear();//w w w. j a va2s. c o m addPreSwitchInstructions(methodNode); LabelNode def = new LabelNode(); LookupSwitchInsnNode switchNode = new LookupSwitchInsnNode(def, new int[0], new LabelNode[0]); methodNode.instructions.add(switchNode); methodNode.instructions.add(def); addInstructionForDefaultLabel(methodNode); addPostSwitchInstructions(methodNode); methodNode.maxStack = getMaxStack(); return true; }
From source file:org.evosuite.instrumentation.coverage.BranchInstrumentation.java
License:Open Source License
/** * <p>//from ww w . j a va2s . c o m * addInstrumentationForDefaultLookupswitchCase * </p> * * @param v * a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object. * @param instrumentation * a {@link org.objectweb.asm.tree.InsnList} object. */ protected void addInstrumentationForDefaultLookupswitchCase(BytecodeInstruction v, InsnList instrumentation) { if (!v.isLookupSwitch()) throw new IllegalArgumentException("lookup switch expected"); // setup instructions LookupSwitchInsnNode toInstrument = (LookupSwitchInsnNode) v.getASMNode(); LabelNode caseLabel = new LabelNode(); LabelNode defaultLabel = new LabelNode(); LabelNode endLabel = new LabelNode(); int keySize = toInstrument.keys.size(); int[] keys = new int[keySize]; LabelNode[] labels = new LabelNode[keySize]; for (int i = 0; i < keySize; i++) { keys[i] = (Integer) toInstrument.keys.get(i); labels[i] = caseLabel; } LookupSwitchInsnNode myLookup = new LookupSwitchInsnNode(defaultLabel, keys, labels); addDefaultCaseInstrumentation(v, instrumentation, myLookup, defaultLabel, caseLabel, endLabel); }