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));
}
Aggregations