@Override public SSAInstruction copyForSSA(SSAInstructionFactory insts, int[] defs, int[] uses) { if (params == null) { return insts.NewInstruction(iindex, defs == null ? result : defs[0], site); } else { return insts.NewInstruction(iindex, defs == null ? result : defs[0], site, uses == null ? params : uses); } }
@Override public SSAInstruction copyForSSA(SSAInstructionFactory insts, int[] defs, int[] uses) throws IllegalArgumentException { if (uses != null && uses.length != 1) { throw new IllegalArgumentException("if non-null, uses.length must be 1"); } return insts.ThrowInstruction(iindex, uses == null ? getException() : uses[0]); }
public void addSetArrayField(final TypeReference elementType, final int baseObject, final int indexValue, final int value) { statements.add(insts.ArrayStoreInstruction(statements.size(), baseObject, indexValue, value, elementType)); }
if (klass.isArrayClass()) { int length = nextLocal++; statements.add(insts.ArrayLengthInstruction(statements.size(), length, 1)); int[] sizes = new int[((ArrayClass)klass).getDimensionality()]; Arrays.fill(sizes, length); N = insts.NewInstruction(statements.size(), retValue, ref, sizes); } else { N = insts.NewInstruction(statements.size(), retValue, ref); params[0] = 1; params[1] = retValue; SSAInvokeInstruction S = insts.InvokeInstruction(statements.size(), params, exceptionValue, ARRAYCOPY_SITE, null); statements.add(S); } else { for (IField f : klass.getDeclaredInstanceFields()) { int tempValue = nextLocal++; SSAGetInstruction G = insts.GetInstruction(statements.size(), tempValue, 1, f.getReference()); statements.add(G); SSAPutInstruction P = insts.PutInstruction(statements.size(), retValue, tempValue, f.getReference()); statements.add(P); SSAReturnInstruction R = insts.ReturnInstruction(statements.size(), retValue, false); statements.add(R);
insts.SwitchInstruction(methodSummary.getNumberOfStatements(), switchValue, defLabel, casesAndLabels)); mp.getIMethod().getReference(), dispatch)); methodSummary.addStatement(insts.GotoInstruction(methodSummary.getNumberOfStatements(), loopLabel));
@Override public SSAInstruction copyForSSA(SSAInstructionFactory insts, int[] defs, int[] uses) { return insts.GotoInstruction(iindex, target); }
/** * @see com.ibm.wala.shrikeBT.IInstruction.Visitor#visitBinaryOp(IBinaryOpInstruction) */ @Override public void visitBinaryOp(IBinaryOpInstruction instruction) { int val2 = workingState.pop(); int val1 = workingState.pop(); int result = reuseOrCreateDef(); workingState.push(result); boolean isFloat = instruction.getType().equals(TYPE_double) || instruction.getType().equals(TYPE_float); emitInstruction(insts.BinaryOpInstruction(getCurrentInstructionIndex(), instruction.getOperator(), instruction.throwsExceptionOnOverflow(), instruction .isUnsigned(), result, val1, val2, !isFloat)); }
@Override protected boolean visitLoop(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; // loop test block context.cfg().newBlock(true); PreBasicBlock headerB = context.cfg().getCurrentBlock(); visitor.visit(n.getChild(0), context, visitor); assert c.getValue(n.getChild(0)) != -1 : "error in loop test " + CAstPrinter.print(n.getChild(0), context.top().getSourceMap()) + " of loop " + CAstPrinter.print(n, context.top().getSourceMap()); context.cfg().addInstruction( insts.ConditionalBranchInstruction(context.cfg().currentInstruction, translateConditionOpcode(CAstOperator.OP_EQ), null, c.getValue(n.getChild(0)), context .currentScope().getConstantValue(Integer.valueOf(0)), -1)); PreBasicBlock branchB = context.cfg().getCurrentBlock(); // loop body context.cfg().newBlock(true); visitor.visit(n.getChild(1), context, visitor); if (!context.cfg().isDeadBlock(context.cfg().getCurrentBlock())) { context.cfg().addInstruction(insts.GotoInstruction(context.cfg().currentInstruction, -1)); PreBasicBlock bodyB = context.cfg().getCurrentBlock(); context.cfg().addEdge(bodyB, headerB); // next block context.cfg().newBlock(false); } PreBasicBlock nextB = context.cfg().getCurrentBlock(); // control flow mapping; context.cfg().addEdge(branchB, nextB); return true; }
@Override public SSAInstruction copyForSSA(SSAInstructionFactory insts, int[] defs, int[] uses) { assert uses == null || uses.length == 1; return insts.SwitchInstruction(iindex, uses == null ? val : uses[0], defaultLabel, casesAndLabels); }
@Override public SSAInstruction copyForSSA(SSAInstructionFactory insts, int[] defs, int[] uses) throws IllegalArgumentException { if (uses != null && uses.length < 2) { throw new IllegalArgumentException("(uses != null) and (uses.length < 2)"); } return insts.ConditionalBranchInstruction(iindex, operator, type, uses == null ? val1 : uses[0], uses == null ? val2 : uses[1], target); }
@Override public SSAInstruction copyForSSA(SSAInstructionFactory insts, int[] defs, int[] uses) throws IllegalArgumentException { if (defs != null && defs.length != 1) { throw new IllegalArgumentException(); } if (uses != null && uses.length != 1) { throw new IllegalArgumentException(); } return insts.ArrayLengthInstruction(iindex, defs == null ? result : defs[0], uses == null ? arrayref : uses[0]); }
public int addCheckcast(TypeReference[] types, int rv, boolean isPEI) { int lv = nextLocal++; statements.add(insts.CheckCastInstruction(statements.size(), lv, rv, types, isPEI)); return lv; }
public int addGetArrayField(final TypeReference elementType, final int baseObject, final int indexValue) { int result = nextLocal++; statements.add(insts.ArrayLoadInstruction(statements.size(), result, baseObject, indexValue, elementType)); return result; }
@Override protected void leaveCast(CAstNode n, WalkContext context, CAstVisitor<WalkContext> visitor) { int result = context.getValue(n); CAstType toType = (CAstType) n.getChild(0).getValue(); TypeReference toRef = makeType(toType); CAstType fromType = (CAstType) n.getChild(2).getValue(); TypeReference fromRef = makeType(fromType); if (toRef.isPrimitiveType()) { context.cfg().addInstruction( insts.ConversionInstruction( context.cfg().getCurrentInstruction(), result, context.getValue(n.getChild(1)), fromRef, toRef, false)); } else { context.cfg().addInstruction( insts.CheckCastInstruction( context.cfg().getCurrentInstruction(), result, context.getValue(n.getChild(1)), toRef, true)); processExceptions(n, context); } }
/** * @see com.ibm.wala.shrikeBT.IInstruction.Visitor#visitArrayLoad(IArrayLoadInstruction) */ @Override public void visitArrayLoad(IArrayLoadInstruction instruction) { int index = workingState.pop(); int arrayRef = workingState.pop(); int result = reuseOrCreateDef(); workingState.push(result); TypeReference t = ShrikeUtil.makeTypeReference(loader, instruction.getType()); if (instruction.isAddressOf()) { emitInstruction(insts.AddressOfInstruction(getCurrentInstructionIndex(), result, arrayRef, index, t)); } else { emitInstruction(insts.ArrayLoadInstruction(getCurrentInstructionIndex(), result, arrayRef, index, t)); } }
if (klass.isArrayClass()) { int length = nextLocal++; statements.add(insts.ArrayLengthInstruction(statements.size(), length, 1)); int[] sizes = new int[((ArrayClass)klass).getDimensionality()]; Arrays.fill(sizes, length); N = insts.NewInstruction(statements.size(), retValue, ref, sizes); } else { N = insts.NewInstruction(statements.size(), retValue, ref); params[0] = 1; params[1] = retValue; SSAInvokeInstruction S = insts.InvokeInstruction(statements.size(), params, exceptionValue, ARRAYCOPY_SITE, null); statements.add(S); } else { for (IField f : klass.getDeclaredInstanceFields()) { int tempValue = nextLocal++; SSAGetInstruction G = insts.GetInstruction(statements.size(), tempValue, 1, f.getReference()); statements.add(G); SSAPutInstruction P = insts.PutInstruction(statements.size(), retValue, tempValue, f.getReference()); statements.add(P); SSAReturnInstruction R = insts.ReturnInstruction(statements.size(), retValue, false); statements.add(R);
context.cfg().addInstruction(insts.SwitchInstruction(currentInstruction, v, defaultBlock, casesAndLabels)); context.cfg().noteOperands(currentInstruction, context.getSourceMap().getPosition(switchValue)); context.cfg().addPreNode(n, context.getUnwindState()); context.cfg().addInstruction(insts.GotoInstruction(context.cfg().currentInstruction, -1)); defaultHackBlock = context.cfg().getCurrentBlock(); context.cfg().newBlock(false);
@Override public SSAInstruction copyForSSA(SSAInstructionFactory insts, int[] defs, int[] uses) { return insts.GotoInstruction(iindex, target); }
/** * @see com.ibm.wala.shrikeBT.IInstruction.Visitor#visitBinaryOp(IBinaryOpInstruction) */ @Override public void visitBinaryOp(IBinaryOpInstruction instruction) { int val2 = workingState.pop(); int val1 = workingState.pop(); int result = reuseOrCreateDef(); workingState.push(result); boolean isFloat = instruction.getType().equals(TYPE_double) || instruction.getType().equals(TYPE_float); emitInstruction(insts.BinaryOpInstruction(getCurrentInstructionIndex(), instruction.getOperator(), instruction.throwsExceptionOnOverflow(), instruction .isUnsigned(), result, val1, val2, !isFloat)); }
@Override protected boolean visitLoop(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; // loop test block context.cfg().newBlock(true); PreBasicBlock headerB = context.cfg().getCurrentBlock(); visitor.visit(n.getChild(0), context, visitor); assert c.getValue(n.getChild(0)) != -1 : "error in loop test " + CAstPrinter.print(n.getChild(0), context.top().getSourceMap()) + " of loop " + CAstPrinter.print(n, context.top().getSourceMap()); context.cfg().addInstruction( insts.ConditionalBranchInstruction(context.cfg().currentInstruction, translateConditionOpcode(CAstOperator.OP_EQ), null, c.getValue(n.getChild(0)), context .currentScope().getConstantValue(Integer.valueOf(0)), -1)); PreBasicBlock branchB = context.cfg().getCurrentBlock(); // loop body context.cfg().newBlock(true); visitor.visit(n.getChild(1), context, visitor); if (!context.cfg().isDeadBlock(context.cfg().getCurrentBlock())) { context.cfg().addInstruction(insts.GotoInstruction(context.cfg().currentInstruction, -1)); PreBasicBlock bodyB = context.cfg().getCurrentBlock(); context.cfg().addEdge(bodyB, headerB); // next block context.cfg().newBlock(false); } PreBasicBlock nextB = context.cfg().getCurrentBlock(); // control flow mapping; context.cfg().addEdge(branchB, nextB); return true; }