use of soot.jimple.AssignStmt in project soot by Sable.
the class DexDefUseAnalysis method collectDefinitionsWithAliases.
/**
* Collect definitions of l in body including the definitions of aliases of
* l. This analysis exploits that the problem is flow-insensitive anyway.
*
* In this context an alias is a local that propagates its value to l.
*
* @param l
* the local whose definitions are to collect
*/
protected Set<Unit> collectDefinitionsWithAliases(Local l) {
Set<Unit> defs = localToDefsWithAliases.get(l);
if (defs == null) {
Set<Local> seenLocals = new HashSet<Local>();
defs = new HashSet<Unit>();
List<Local> newLocals = new ArrayList<Local>();
newLocals.add(l);
while (!newLocals.isEmpty()) {
Local curLocal = newLocals.remove(0);
// Definition of l?
BitSet bsDefs = localToDefsBits[localToNumber.get(curLocal)];
if (bsDefs != null) {
for (int i = bsDefs.nextSetBit(0); i >= 0; i = bsDefs.nextSetBit(i + 1)) {
Unit u = unitList.get(i);
defs.add(u);
DefinitionStmt defStmt = (DefinitionStmt) u;
if (defStmt.getRightOp() instanceof Local && seenLocals.add((Local) defStmt.getRightOp()))
newLocals.add((Local) defStmt.getRightOp());
}
}
// Use of l?
BitSet bsUses = localToUsesBits[localToNumber.get(curLocal)];
if (bsUses != null) {
for (int i = bsUses.nextSetBit(0); i >= 0; i = bsUses.nextSetBit(i + 1)) {
Unit use = unitList.get(i);
if (use instanceof AssignStmt) {
AssignStmt assignUse = (AssignStmt) use;
if (assignUse.getRightOp() == curLocal && assignUse.getLeftOp() instanceof Local && seenLocals.add((Local) assignUse.getLeftOp()))
newLocals.add((Local) assignUse.getLeftOp());
}
}
}
}
localToDefsWithAliases.put(l, defs);
}
return defs;
}
use of soot.jimple.AssignStmt in project soot by Sable.
the class ConstInstruction method jimplify.
@Override
public void jimplify(DexBody body) {
int dest = ((OneRegisterInstruction) instruction).getRegisterA();
Constant cst = getConstant(dest, body);
AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), cst);
setUnit(assign);
addTags(assign);
body.add(assign);
if (IDalvikTyper.ENABLE_DVKTYPER) {
if (cst instanceof UntypedConstant) {
DalvikTyper.v().addConstraint(assign.getLeftOpBox(), assign.getRightOpBox());
} else {
DalvikTyper.v().setType(assign.getLeftOpBox(), cst.getType(), false);
}
}
}
use of soot.jimple.AssignStmt in project soot by Sable.
the class CastInstruction method jimplify.
@Override
public void jimplify(DexBody body) {
TwoRegisterInstruction i = (TwoRegisterInstruction) instruction;
int dest = i.getRegisterA();
int source = i.getRegisterB();
Type targetType = getTargetType();
CastExpr cast = Jimple.v().newCastExpr(body.getRegisterLocal(source), targetType);
AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), cast);
assign.addTag(getTag());
setUnit(assign);
addTags(assign);
body.add(assign);
if (IDalvikTyper.ENABLE_DVKTYPER) {
DalvikTyper.v().setType(assign.getLeftOpBox(), cast.getType(), false);
// DalvikTyper.v().captureAssign((JAssignStmt)assign, op);
}
}
use of soot.jimple.AssignStmt in project soot by Sable.
the class CmpInstruction method jimplify.
@Override
public void jimplify(DexBody body) {
if (!(instruction instanceof Instruction23x))
throw new IllegalArgumentException("Expected Instruction23x but got: " + instruction.getClass());
Instruction23x cmpInstr = (Instruction23x) instruction;
int dest = cmpInstr.getRegisterA();
Local first = body.getRegisterLocal(cmpInstr.getRegisterB());
Local second = body.getRegisterLocal(cmpInstr.getRegisterC());
// Expr cmpExpr;
// Type type = null
Opcode opcode = instruction.getOpcode();
Expr cmpExpr = null;
Type type = null;
switch(opcode) {
case CMPL_DOUBLE:
setTag(new DoubleOpTag());
type = DoubleType.v();
cmpExpr = Jimple.v().newCmplExpr(first, second);
break;
case CMPL_FLOAT:
setTag(new FloatOpTag());
type = FloatType.v();
cmpExpr = Jimple.v().newCmplExpr(first, second);
break;
case CMPG_DOUBLE:
setTag(new DoubleOpTag());
type = DoubleType.v();
cmpExpr = Jimple.v().newCmpgExpr(first, second);
break;
case CMPG_FLOAT:
setTag(new FloatOpTag());
type = FloatType.v();
cmpExpr = Jimple.v().newCmpgExpr(first, second);
break;
case CMP_LONG:
setTag(new LongOpTag());
type = LongType.v();
cmpExpr = Jimple.v().newCmpExpr(first, second);
break;
default:
throw new RuntimeException("no opcode for CMP: " + opcode);
}
AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), cmpExpr);
assign.addTag(getTag());
setUnit(assign);
addTags(assign);
body.add(assign);
if (IDalvikTyper.ENABLE_DVKTYPER) {
getTag().getName();
BinopExpr bexpr = (BinopExpr) cmpExpr;
DalvikTyper.v().setType(bexpr.getOp1Box(), type, true);
DalvikTyper.v().setType(bexpr.getOp2Box(), type, true);
DalvikTyper.v().setType(((JAssignStmt) assign).leftBox, IntType.v(), false);
}
}
use of soot.jimple.AssignStmt in project soot by Sable.
the class ConstClassInstruction method jimplify.
@Override
public void jimplify(DexBody body) {
if (!(instruction instanceof Instruction21c))
throw new IllegalArgumentException("Expected Instruction21c but got: " + instruction.getClass());
ReferenceInstruction constClass = (ReferenceInstruction) this.instruction;
TypeReference tidi = (TypeReference) (constClass.getReference());
Constant cst = ClassConstant.v(tidi.getType());
int dest = ((OneRegisterInstruction) instruction).getRegisterA();
AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), cst);
setUnit(assign);
addTags(assign);
body.add(assign);
if (IDalvikTyper.ENABLE_DVKTYPER) {
// DalvikTyper.v().captureAssign((JAssignStmt)assign, op); //TODO:
// classtype could be null!
DalvikTyper.v().setType(assign.getLeftOpBox(), cst.getType(), false);
}
}
Aggregations