Search in sources :

Example 1 with ConcreteRef

use of soot.jimple.ConcreteRef in project soot by Sable.

the class StmtVisitor method caseAssignStmt.

@Override
public void caseAssignStmt(AssignStmt stmt) {
    // If this is the beginning of an array initialization, we shortcut the
    // normal translation process
    List<Value> arrayValues = arrayInitDetector.getValuesForArrayInit(stmt);
    if (arrayValues != null) {
        Insn insn = buildArrayFillInsn((ArrayRef) stmt.getLeftOp(), arrayValues);
        if (insn != null) {
            addInsn(insn, stmt);
            return;
        }
    }
    if (arrayInitDetector.getIgnoreUnits().contains(stmt)) {
        return;
    }
    constantV.setOrigStmt(stmt);
    exprV.setOrigStmt(stmt);
    Value lhs = stmt.getLeftOp();
    if (lhs instanceof ConcreteRef) {
        // special cases that lead to *put* opcodes
        Value source = stmt.getRightOp();
        addInsn(buildPutInsn((ConcreteRef) lhs, source), stmt);
        return;
    }
    // other cases, where lhs is a local
    if (!(lhs instanceof Local)) {
        throw new Error("left-hand side of AssignStmt is not a Local: " + lhs.getClass());
    }
    Local lhsLocal = (Local) lhs;
    final Insn newInsn;
    Register lhsReg = regAlloc.asLocal(lhsLocal);
    Value rhs = stmt.getRightOp();
    if (rhs instanceof Local) {
        // move rhs local to lhs local, if different
        Local rhsLocal = (Local) rhs;
        if (lhsLocal == rhsLocal) {
            return;
        }
        Register sourceReg = regAlloc.asLocal(rhsLocal);
        newInsn = buildMoveInsn(lhsReg, sourceReg);
        addInsn(newInsn, stmt);
    } else if (rhs instanceof Constant) {
        // move rhs constant into the lhs local
        constantV.setDestination(lhsReg);
        rhs.apply(constantV);
        newInsn = insns.get(insns.size() - 1);
    } else if (rhs instanceof ConcreteRef) {
        newInsn = buildGetInsn((ConcreteRef) rhs, lhsReg);
        addInsn(newInsn, stmt);
    } else {
        // evaluate rhs expression, saving the result in the lhs local
        exprV.setDestinationReg(lhsReg);
        rhs.apply(exprV);
        if (rhs instanceof InvokeExpr) {
            // do the actual "assignment" for an invocation: move its result
            // to the lhs reg (it was not used yet)
            Insn moveResultInsn = buildMoveResultInsn(lhsReg);
            int invokeInsnIndex = exprV.getLastInvokeInstructionPosition();
            insns.add(invokeInsnIndex + 1, moveResultInsn);
        }
        newInsn = insns.get(insns.size() - 1);
    }
    this.insnRegisterMap.put(newInsn, LocalRegisterAssignmentInformation.v(lhsReg, lhsLocal));
}
Also used : AddressInsn(soot.toDex.instructions.AddressInsn) Insn(soot.toDex.instructions.Insn) InvokeExpr(soot.jimple.InvokeExpr) Constant(soot.jimple.Constant) LongConstant(soot.jimple.LongConstant) DoubleConstant(soot.jimple.DoubleConstant) IntConstant(soot.jimple.IntConstant) ClassConstant(soot.jimple.ClassConstant) FloatConstant(soot.jimple.FloatConstant) Value(soot.Value) Local(soot.Local) ConcreteRef(soot.jimple.ConcreteRef)

Aggregations

Local (soot.Local)1 Value (soot.Value)1 ClassConstant (soot.jimple.ClassConstant)1 ConcreteRef (soot.jimple.ConcreteRef)1 Constant (soot.jimple.Constant)1 DoubleConstant (soot.jimple.DoubleConstant)1 FloatConstant (soot.jimple.FloatConstant)1 IntConstant (soot.jimple.IntConstant)1 InvokeExpr (soot.jimple.InvokeExpr)1 LongConstant (soot.jimple.LongConstant)1 AddressInsn (soot.toDex.instructions.AddressInsn)1 Insn (soot.toDex.instructions.Insn)1