public IInstruction[] getInstructions() { try { return method.getInstructions(); } catch (InvalidClassFileException e) { e.printStackTrace(); Assertions.UNREACHABLE(); return null; } }
/* * @see com.ibm.wala.cfg.ControlFlowGraph#getProgramCounter(int) */ public int getProgramCounter(int index) { try { return method.getBytecodeIndex(index); } catch (InvalidClassFileException e) { e.printStackTrace(); Assertions.UNREACHABLE(); return -1; } }
public ShrikeCFG(IBytecodeMethod method) throws IllegalArgumentException { super(method); if (method == null) { throw new IllegalArgumentException("method cannot be null"); } this.method = method; this.hashBase = method.hashCode() * 9967; makeBasicBlocks(); init(); computeI2BMapping(); computeEdges(); if (DEBUG) { System.err.println(this); } }
public int getMaxLocals() { return method.getMaxLocals(); }
public int getMaxStackHeight() { return method.getMaxStackHeight(); }
private void makeBasicBlocks() { ExceptionHandler[][] handlers; try { handlers = method.getHandlers(); } catch (InvalidClassFileException e) { e.printStackTrace(); Assertions.UNREACHABLE(); handlers = null; } boolean[] r = new boolean[getInstructions().length]; boolean[] catchers = new boolean[getInstructions().length]; // we initially start with both the entry and exit block. int blockCount = 2; // Compute r so r[i] == true iff instruction i begins a basic block. // While doing so count the number of blocks. r[0] = true; IInstruction[] instructions = getInstructions(); for (int i = 0; i < instructions.length; i++) { int[] targets = instructions[i].getBranchTargets(); // if there are any targets, then break the basic block here. // also break the basic block after a return if (targets.length > 0 || !instructions[i].isFallThrough()) { if (i + 1 < instructions.length && !r[i + 1]) { r[i + 1] = true; blockCount++; } } for (int j = 0; j < targets.length; j++) { if (!r[targets[j]]) { r[targets[j]] = true; blockCount++; } } if (instructions[i].isPEI()) { ExceptionHandler[] hs = handlers[i]; // break the basic block here. if (i + 1 < instructions.length && !r[i + 1]) { r[i + 1] = true; blockCount++; } if (hs != null && hs.length > 0) { for (int j = 0; j < hs.length; j++) { exceptionHandlers.add(hs[j]); if (!r[hs[j].getHandler()]) { // we have not discovered the catch block yet. // form a new basic block r[hs[j].getHandler()] = true; blockCount++; } catchers[hs[j].getHandler()] = true; } } } } BasicBlock entry = new BasicBlock(-1); addNode(entry); int j = 1; for (int i = 0; i < r.length; i++) { if (r[i]) { BasicBlock b = new BasicBlock(i); addNode(b); if (catchers[i]) { setCatchBlock(j); } j++; } } BasicBlock exit = new BasicBlock(-1); addNode(exit); }