public StatementVisitor(CGNode node, IR ir, DefUse du) { this.node = node; this.ir = ir; this.symbolTable = ir.getSymbolTable(); assert symbolTable != null; this.du = du; }
// add inter-procedural flow for local calls private void resolveLocalCalls(FlowGraph flowgraph) { for (IClass klass : cha) { for (IMethod method : klass.getDeclaredMethods()) { if (filterFunction(method)) { IR ir = cache.getIR(method); ir.visitAllInstructions( new LocalCallSSAVisitor(method, ir.getSymbolTable(), cache.getDefUse(ir), flowgraph)); } } } }
/** * add nodes for parameters and return values * * @param node */ private void addNodesForParameters(CGNode node) { // TODO Auto-generated method stub IR ir = node.getIR(); TypeInference ti = TypeInference.make(ir, false); SymbolTable symbolTable = ir.getSymbolTable(); for (int i = 0; i < symbolTable.getNumberOfParameters(); i++) { int parameter = symbolTable.getParameter(i); TypeAbstraction t = ti.getType(parameter); if (t != null) { PointerKey paramPk = heapModel.getPointerKeyForLocal(node, parameter); addNode(paramPk); params.put(paramPk, node); } } addNode(heapModel.getPointerKeyForReturnValue(node)); addNode(heapModel.getPointerKeyForExceptionalReturnValue(node)); }
/** Taken from com.ibm.wala.viz.PDFViewUtil */ @Override public String getText(Object element) { if (element instanceof BasicBlock) { BasicBlock bb = (BasicBlock) element; IR ir = irView.getIR(); StringBuilder result = new StringBuilder(); int start = bb.getFirstInstructionIndex(); int end = bb.getLastInstructionIndex(); result.append("BB").append(bb.getNumber()); if (bb.isEntryBlock()) { result.append(" (en)\n"); } else if (bb.isExitBlock()) { result.append(" (ex)\n"); } if (bb instanceof ExceptionHandlerBasicBlock) { result.append("<Handler>"); } result.append("\n"); for (Iterator<SSAPhiInstruction> it = bb.iteratePhis(); it.hasNext(); ) { SSAPhiInstruction phi = it.next(); if (phi != null) { result.append(phi.toString(ir.getSymbolTable())).append("\n"); } } if (bb instanceof ExceptionHandlerBasicBlock) { ExceptionHandlerBasicBlock ebb = (ExceptionHandlerBasicBlock) bb; SSAGetCaughtExceptionInstruction s = ebb.getCatchInstruction(); if (s != null) { result.append(s.toString(ir.getSymbolTable())).append("\n"); } else { result.append(" No catch instruction. Unreachable?\n"); } } SSAInstruction[] instructions = ir.getInstructions(); IMethod method = ir.getMethod(); for (int j = start; j <= end; j++) { if (instructions[j] != null) { String x; int sourceLineNum = method.getLineNumber(j); x = String.format( j + " [L%03d] " + instructions[j].toString(ir.getSymbolTable()), sourceLineNum); String padded = String.format("%1$-35s", x); result.append(padded); result.append("\n"); result.append(SSAValuesToLocalVariables(instructions[j], j, ir)); result.append("\n"); } } for (Iterator<SSAPiInstruction> it = bb.iteratePis(); it.hasNext(); ) { SSAPiInstruction pi = it.next(); if (pi != null) { result.append(" " + pi.toString(ir.getSymbolTable())).append("\n"); } } return result.toString(); } if (element instanceof EntityConnectionData) { return "\n"; } return ""; }
private IMethod makeFunctionConstructor( IR callerIR, SSAAbstractInvokeInstruction callStmt, IClass cls, int nargs) { SymbolTable ST = callerIR.getSymbolTable(); if (nargs == 0) { return makeFunctionConstructor(cls, cls); } else if (nargs == 1) { if (ST.isStringConstant(callStmt.getUse(1))) { TypeReference ref = TypeReference.findOrCreate( JavaScriptTypes.jsLoader, TypeName.string2TypeName((String) ST.getStringValue(callStmt.getUse(1)))); if (DEBUG) { System.err.println( ("ctor type name is " + (String) ST.getStringValue(callStmt.getUse(1)))); } IClass cls2 = cha.lookupClass(ref); if (cls2 != null) { return makeFunctionConstructor(cls, cls2); } } return makeFunctionConstructor(cls, cls); } else { assert nargs > 1; JavaScriptLoader cl = (JavaScriptLoader) cha.getLoader(JavaScriptTypes.jsLoader); for (int i = 1; i < callStmt.getNumberOfUses(); i++) if (!ST.isStringConstant(callStmt.getUse(i))) return makeFunctionConstructor(cls, cls); StringBuffer fun = new StringBuffer("function _fromctor ("); for (int j = 1; j < callStmt.getNumberOfUses() - 1; j++) { if (j != 1) fun.append(","); fun.append(ST.getStringValue(callStmt.getUse(j))); } fun.append(") {"); fun.append(ST.getStringValue(callStmt.getUse(callStmt.getNumberOfUses() - 1))); fun.append("}"); try { String fileName = "ctor$" + ++ctorCount; File f = new File(System.getProperty("java.io.tmpdir") + File.separator + fileName); FileWriter FO = new FileWriter(f); FO.write(fun.toString()); FO.close(); Set<String> fnNames = JSCallGraphUtil.loadAdditionalFile(cha, cl, fileName, f.toURI().toURL()); IClass fcls = null; for (String nm : fnNames) { if (nm.endsWith("_fromctor")) { fcls = cl.lookupClass(nm, cha); } } assert fcls != null : "cannot find class for " + fileName + " in " + f; f.delete(); if (DEBUG) System.err.println(("looking for ctor " + ctorCount + " and got " + fcls)); if (fcls != null) return makeFunctionConstructor(cls, fcls); } catch (IOException e) { } return makeFunctionConstructor(cls, cls); } }