/** * Initialize the allInstructions field with every {@link SSAInstruction} in the ir. */ protected void initAllInstructions() { for (SSAInstruction inst : Iterator2Iterable.make(ir.iterateAllInstructions())) { allInstructions.add(inst); } }
/** * Initialize the allInstructions field with every {@link SSAInstruction} in the ir. */ protected void initAllInstructions() { for (SSAInstruction inst : Iterator2Iterable.make(ir.iterateAllInstructions())) { allInstructions.add(inst); } }
/** * visit each instruction in this IR */ public void visitAllInstructions(SSAInstruction.IVisitor v) { for (SSAInstruction inst : Iterator2Iterable.make(iterateAllInstructions())) { inst.visit(v); } }
/** * visit each instruction in this IR */ public void visitAllInstructions(SSAInstruction.IVisitor v) { for (SSAInstruction inst : Iterator2Iterable.make(iterateAllInstructions())) { inst.visit(v); } }
/** * Create nodes corresponding to * <ul> * <li>phi instructions * <li>getCaughtExceptions * </ul> */ private void createSpecialStatements(IR ir) { // create a node for instructions which do not correspond to bytecode for (SSAInstruction s : Iterator2Iterable.make(ir.iterateAllInstructions())) { if (s instanceof SSAPhiInstruction) { delegate.addNode(new PhiStatement(node, (SSAPhiInstruction) s)); } else if (s instanceof SSAGetCaughtExceptionInstruction) { delegate.addNode(new GetCaughtExceptionStatement(node, (SSAGetCaughtExceptionInstruction) s)); } else if (s instanceof SSAPiInstruction) { delegate.addNode(new PiStatement(node, (SSAPiInstruction) s)); } } }
/** * Create nodes corresponding to * <ul> * <li>phi instructions * <li>getCaughtExceptions * </ul> */ private void createSpecialStatements(IR ir) { // create a node for instructions which do not correspond to bytecode for (SSAInstruction s : Iterator2Iterable.make(ir.iterateAllInstructions())) { if (s instanceof SSAPhiInstruction) { delegate.addNode(new PhiStatement(node, (SSAPhiInstruction) s)); } else if (s instanceof SSAGetCaughtExceptionInstruction) { delegate.addNode(new GetCaughtExceptionStatement(node, (SSAGetCaughtExceptionInstruction) s)); } else if (s instanceof SSAPiInstruction) { delegate.addNode(new PiStatement(node, (SSAPiInstruction) s)); } } }
@Override public Iterator<NewSiteReference> iterateNewSites(CGNode node) { return new MapIterator<>( new FilterIterator<>( node.getIR().iterateAllInstructions(), SSANewInstruction.class::isInstance), object -> ((SSANewInstruction)object).getNewSite() ); } };
@Override public void check(CallGraph cg) { IR ir = getIR(cg, typeName, "main", "[Ljava/lang/String;", "V"); AstJavaTypeInference inference = new AstJavaTypeInference(ir, true); for (SSAInstruction instr : Iterator2Iterable.make(ir.iterateAllInstructions())) { // Check defs for (int def = 0; def < instr.getNumberOfDefs(); def++) { int ssaVariable = instr.getDef(def); inference.getType(ssaVariable); } // Check uses for (int def = 0; def < instr.getNumberOfUses(); def++) { int ssaVariable = instr.getUse(def); inference.getType(ssaVariable); } } }
public static Statement findCallTo(CGNode n, String methodName) { IR ir = n.getIR(); for (SSAInstruction s : Iterator2Iterable.make(ir.iterateAllInstructions())) { if (s instanceof SSAInvokeInstruction) { SSAInvokeInstruction call = (SSAInvokeInstruction) s; if (call.getCallSite().getDeclaredTarget().getName().toString().equals(methodName)) { IntSet indices = ir.getCallInstructionIndices(((SSAInvokeInstruction) s).getCallSite()); Assertions.productionAssertion(indices.size() == 1, "expected 1 but got " + indices.size()); return new NormalStatement(n, indices.intIterator().next()); } } } Assertions.UNREACHABLE("failed to find call to " + methodName + " in " + n); return null; }
public static PointerKey getParam(CGNode n, String methodName, HeapModel heapModel) { IR ir = n.getIR(); for (SSAInstruction s : Iterator2Iterable.make(ir.iterateAllInstructions())) { if (s instanceof SSAInvokeInstruction) { SSAInvokeInstruction call = (SSAInvokeInstruction) s; if (call.getCallSite().getDeclaredTarget().getName().toString().equals(methodName)) { IntSet indices = ir.getCallInstructionIndices(((SSAInvokeInstruction) s).getCallSite()); Assertions.productionAssertion(indices.size() == 1, "expected 1 but got " + indices.size()); SSAInstruction callInstr = ir.getInstructions()[indices.intIterator().next()]; Assertions.productionAssertion(callInstr.getNumberOfUses() == 1, "multiple uses for call"); return heapModel.getPointerKeyForLocal(n, callInstr.getUse(0)); } } } Assertions.UNREACHABLE("failed to find call to " + methodName + " in " + n); return null; }
private IR doMethod(MethodReference method) { IAnalysisCacheView cache = makeAnalysisCache(); Assert.assertNotNull("method not found", method); IMethod imethod = cha.resolveMethod(method); Assert.assertNotNull("imethod not found", imethod); IR ir1 = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); cache.clear(); checkNotAllNull(ir1.getInstructions()); checkNoneNull(ir1.iterateAllInstructions()); try { GraphIntegrity.check(ir1.getControlFlowGraph()); } catch (UnsoundGraphException e) { System.err.println(ir1); e.printStackTrace(); Assert.assertTrue("unsound CFG for ir1", false); } IR ir2 = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); cache.clear(); try { GraphIntegrity.check(ir2.getControlFlowGraph()); } catch (UnsoundGraphException e1) { System.err.println(ir2); e1.printStackTrace(); Assert.assertTrue("unsound CFG for ir2", false); } Assert.assertEquals(ir1.toString(), ir2.toString()); return ir1; }