@Override public SSAInstruction copyForSSA(SSAInstructionFactory insts, int[] defs, int[] uses) { if (result == -1) return insts.ReturnInstruction(iindex); else { if (uses != null && uses.length != 1) { throw new IllegalArgumentException("invalid uses. must have exactly one use."); } return insts.ReturnInstruction(iindex, uses == null ? result : uses[0], isPrimitive); } }
@Override public SSAInstruction copyForSSA(SSAInstructionFactory insts, int[] defs, int[] uses) { if (result == -1) return insts.ReturnInstruction(iindex); else { if (uses != null && uses.length != 1) { throw new IllegalArgumentException("invalid uses. must have exactly one use."); } return insts.ReturnInstruction(iindex, uses == null ? result : uses[0], isPrimitive); } }
/** * Add a return statement */ public SSAReturnInstruction addReturn(int vn, boolean isPrimitive) { SSAReturnInstruction s = insts.ReturnInstruction(statements.size(), vn, isPrimitive); statements.add(s); cache.invalidate(this, Everywhere.EVERYWHERE); return s; }
/** * Add a return statement */ public SSAReturnInstruction addReturn(int vn, boolean isPrimitive) { SSAReturnInstruction s = insts.ReturnInstruction(statements.size(), vn, isPrimitive); statements.add(s); cache.invalidate(this, Everywhere.EVERYWHERE); return s; }
/** * @see com.ibm.wala.shrikeBT.IInstruction.Visitor#visitReturn(ReturnInstruction) */ @Override public void visitReturn(com.ibm.wala.shrikeBT.ReturnInstruction instruction) { if (instruction.getPoppedCount() == 1) { int result = workingState.pop(); TypeReference t = ShrikeUtil.makeTypeReference(loader, instruction.getType()); emitInstruction(insts.ReturnInstruction(getCurrentInstructionIndex(), result, t.isPrimitiveType())); } else { emitInstruction(insts.ReturnInstruction(getCurrentInstructionIndex())); } }
/** * @see com.ibm.wala.shrikeBT.IInstruction.Visitor#visitReturn(ReturnInstruction) */ @Override public void visitReturn(com.ibm.wala.shrikeBT.ReturnInstruction instruction) { if (instruction.getPoppedCount() == 1) { int result = workingState.pop(); TypeReference t = ShrikeUtil.makeTypeReference(loader, instruction.getType()); emitInstruction(insts.ReturnInstruction(getCurrentInstructionIndex(), result, t.isPrimitiveType())); } else { emitInstruction(insts.ReturnInstruction(getCurrentInstructionIndex())); } }
private static SSAInstruction[] makeStatements(Context context) { SSAInstructionFactory insts = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType().getClassLoader().getInstructionFactory(); ArrayList<SSAInstruction> statements = new ArrayList<>(); // vn1 is the string parameter int retValue = 2; TypeReference tr = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getTypeReference(); if (tr != null) { SSALoadMetadataInstruction l = insts.LoadMetadataInstruction(statements.size(), retValue, TypeReference.JavaLangClass, tr); statements.add(l); SSAReturnInstruction R = insts.ReturnInstruction(statements.size(), retValue, false); statements.add(R); } else { SSAThrowInstruction t = insts.ThrowInstruction(statements.size(), retValue); statements.add(t); } SSAInstruction[] result = new SSAInstruction[statements.size()]; statements.toArray(result); return result; }
private static SSAInstruction[] makeStatements(Context context) { SSAInstructionFactory insts = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType().getClassLoader().getInstructionFactory(); ArrayList<SSAInstruction> statements = new ArrayList<>(); // vn1 is the string parameter int retValue = 2; TypeReference tr = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getTypeReference(); if (tr != null) { SSALoadMetadataInstruction l = insts.LoadMetadataInstruction(statements.size(), retValue, TypeReference.JavaLangClass, tr); statements.add(l); SSAReturnInstruction R = insts.ReturnInstruction(statements.size(), retValue, false); statements.add(R); } else { SSAThrowInstruction t = insts.ThrowInstruction(statements.size(), retValue); statements.add(t); } SSAInstruction[] result = new SSAInstruction[statements.size()]; statements.toArray(result); return result; }
private static SSAInstruction[] makeStatements(Context context) { ArrayList<SSAInstruction> statements = new ArrayList<>(); int nextLocal = 2; int retValue = nextLocal++; TypeReference tr = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getTypeReference(); SSAInstructionFactory insts = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType().getClassLoader().getInstructionFactory(); if (tr != null) { SSALoadMetadataInstruction l = insts.LoadMetadataInstruction(statements.size(), retValue, TypeReference.JavaLangClass, tr); statements.add(l); SSAReturnInstruction R = insts.ReturnInstruction(statements.size(), retValue, false); statements.add(R); } SSAInstruction[] result = new SSAInstruction[statements.size()]; Iterator<SSAInstruction> it = statements.iterator(); for (int i = 0; i < result.length; i++) { result[i] = it.next(); } return result; }
private static SSAInstruction[] makeStatements(Context context) { ArrayList<SSAInstruction> statements = new ArrayList<>(); int nextLocal = 2; int retValue = nextLocal++; TypeReference tr = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getTypeReference(); SSAInstructionFactory insts = ((TypeAbstraction)context.get(ContextKey.RECEIVER)).getType().getClassLoader().getInstructionFactory(); if (tr != null) { SSALoadMetadataInstruction l = insts.LoadMetadataInstruction(statements.size(), retValue, TypeReference.JavaLangClass, tr); statements.add(l); SSAReturnInstruction R = insts.ReturnInstruction(statements.size(), retValue, false); statements.add(R); } SSAInstruction[] result = new SSAInstruction[statements.size()]; Iterator<SSAInstruction> it = statements.iterator(); for (int i = 0; i < result.length; i++) { result[i] = it.next(); } return result; }
emitInstruction(insts.ReturnInstruction(getCurrentInstructionIndex(), result, isPrimitive)); emitInstruction(insts.ReturnInstruction(getCurrentInstructionIndex(), result, isPrimitive)); } else if (instruction instanceof Return.ReturnVoid) emitInstruction(insts.ReturnInstruction(getCurrentInstructionIndex()));
int c = nextLocal++; constants.put(c, new ConstantValue(m)); SSAReturnInstruction R = insts.ReturnInstruction(statements.size(), c, false); statements.add(R);
/** * Process an element indicating a return statement. */ private void processReturn(Attributes atts) { Language lang = scope.getLanguage(governingLoader.getLanguage()); SSAInstructionFactory insts = lang.instructionFactory(); if (governingMethod.getReturnType() != null) { String retV = atts.getValue(A_VALUE); if (retV == null) { SSAReturnInstruction R = insts.ReturnInstruction(governingMethod.getNumberOfStatements()); governingMethod.addStatement(R); } else { Integer valueNumber = symbolTable.get(retV); if (valueNumber == null) { if (!retV.equals(V_NULL)) { Assertions.UNREACHABLE("Cannot return value with no def: " + retV); } else { valueNumber = getValueNumberForNull(); } } boolean isPrimitive = governingMethod.getReturnType().isPrimitiveType(); SSAReturnInstruction R = insts.ReturnInstruction(governingMethod.getNumberOfStatements(), valueNumber.intValue(), isPrimitive); governingMethod.addStatement(R); } } }
/** * Process an element indicating a return statement. */ private void processReturn(Attributes atts) { Language lang = scope.getLanguage(governingLoader.getLanguage()); SSAInstructionFactory insts = lang.instructionFactory(); if (governingMethod.getReturnType() != null) { String retV = atts.getValue(A_VALUE); if (retV == null) { SSAReturnInstruction R = insts.ReturnInstruction(governingMethod.getNumberOfStatements()); governingMethod.addStatement(R); } else { Integer valueNumber = symbolTable.get(retV); if (valueNumber == null) { if (!retV.equals(V_NULL)) { Assertions.UNREACHABLE("Cannot return value with no def: " + retV); } else { valueNumber = getValueNumberForNull(); } } boolean isPrimitive = governingMethod.getReturnType().isPrimitiveType(); SSAReturnInstruction R = insts.ReturnInstruction(governingMethod.getNumberOfStatements(), valueNumber.intValue(), isPrimitive); governingMethod.addStatement(R); } } }
@Override public SSAInstruction[] getStatements() { if (getReturnType().equals(TypeReference.Void)) { return NO_STATEMENTS; } else { int nullValue = getNumberOfParameters() + 1; SSAInstruction[] result = new SSAInstruction[1]; SSAInstructionFactory insts = l.instructionFactory(); result[0] = insts.ReturnInstruction(0, nullValue, getReturnType().isPrimitiveType()); return result; } }
@Override public SSAInstruction[] getStatements() { if (getReturnType().equals(TypeReference.Void)) { return NO_STATEMENTS; } else { int nullValue = getNumberOfParameters() + 1; SSAInstruction[] result = new SSAInstruction[1]; SSAInstructionFactory insts = l.instructionFactory(); result[0] = insts.ReturnInstruction(0, nullValue, getReturnType().isPrimitiveType()); return result; } }
@Override protected void leaveReturn(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; int currentInstruction = context.cfg().currentInstruction; if (n.getChildCount() > 0) { CAstNode returnExpr = n.getChild(0); context.cfg().addInstruction(insts.ReturnInstruction(currentInstruction, c.getValue(returnExpr), false)); context.cfg().noteOperands(currentInstruction, context.getSourceMap().getPosition(returnExpr)); } else { context.cfg().addInstruction(insts.ReturnInstruction(currentInstruction)); } context.cfg().addPreNode(n, context.getUnwindState()); context.cfg().newBlock(false); context.cfg().addPreEdgeToExit(n, false); }
@Override public IR getIR(CGNode node) { if (!irs.containsKey(node) || irs.get(node).get() == null) { MethodSummary code = new MethodSummary(node.getMethod().getReference()); SummarizedMethod m = new SummarizedMethod(node.getMethod().getReference(), code, node.getMethod().getDeclaringClass()); SSAInstructionFactory insts = node.getMethod().getDeclaringClass().getClassLoader().getLanguage().instructionFactory(); assert node.getContext().isA(FindContext.class); @SuppressWarnings("unchecked") IClass cls = node.getClassHierarchy().lookupClass(((HandlesItem<TypeReference>)node.getContext().get(CLASS_KEY)).item); @SuppressWarnings("unchecked") String selector = ((HandlesItem<String>)node.getContext().get(NAME_KEY)).item; int vn = 10; for(IMethod handleMethod : cls.getAllMethods()) { if (handleMethod.getName().toString().contains(selector)) { code.addStatement(insts.LoadMetadataInstruction(code.getNextProgramCounter(), vn, TypeReference.JavaLangInvokeMethodHandle, handleMethod.getReference())); code.addStatement(insts.ReturnInstruction(code.getNextProgramCounter(), vn , false)); vn++; } } irs.put(node, new SoftReference<>(m.makeIR(node.getContext(), SSAOptions.defaultOptions()))); } return irs.get(node).get(); } }
@Override public IR getIR(CGNode node) { if (!irs.containsKey(node) || irs.get(node).get() == null) { MethodSummary code = new MethodSummary(node.getMethod().getReference()); SummarizedMethod m = new SummarizedMethod(node.getMethod().getReference(), code, node.getMethod().getDeclaringClass()); SSAInstructionFactory insts = node.getMethod().getDeclaringClass().getClassLoader().getLanguage().instructionFactory(); assert node.getContext().isA(FindContext.class); @SuppressWarnings("unchecked") IClass cls = node.getClassHierarchy().lookupClass(((HandlesItem<TypeReference>)node.getContext().get(CLASS_KEY)).item); @SuppressWarnings("unchecked") String selector = ((HandlesItem<String>)node.getContext().get(NAME_KEY)).item; int vn = 10; for(IMethod handleMethod : cls.getAllMethods()) { if (handleMethod.getName().toString().contains(selector)) { code.addStatement(insts.LoadMetadataInstruction(code.getNextProgramCounter(), vn, TypeReference.JavaLangInvokeMethodHandle, handleMethod.getReference())); code.addStatement(insts.ReturnInstruction(code.getNextProgramCounter(), vn , false)); vn++; } } irs.put(node, new SoftReference<>(m.makeIR(node.getContext(), SSAOptions.defaultOptions()))); } return irs.get(node).get(); } }
@Override protected void leaveReturn(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; int currentInstruction = context.cfg().currentInstruction; if (n.getChildCount() > 0) { CAstNode returnExpr = n.getChild(0); context.cfg().addInstruction(insts.ReturnInstruction(currentInstruction, c.getValue(returnExpr), false)); context.cfg().noteOperands(currentInstruction, context.getSourceMap().getPosition(returnExpr)); } else { context.cfg().addInstruction(insts.ReturnInstruction(currentInstruction)); } context.cfg().addPreNode(n, context.getUnwindState()); context.cfg().newBlock(false); context.cfg().addPreEdgeToExit(n, false); }