use of soot.toDex.instructions.Insn12x in project soot by Sable.
the class ExprVisitor method caseLengthExpr.
@Override
public void caseLengthExpr(LengthExpr le) {
Value array = le.getOp();
constantV.setOrigStmt(origStmt);
// In buggy code, the parameter could be a NullConstant.
// This is why we use .asImmediate() and not .asLocal()
Register arrayReg = regAlloc.asImmediate(array, constantV);
stmtV.addInsn(new Insn12x(Opcode.ARRAY_LENGTH, destinationReg, arrayReg), origStmt);
}
use of soot.toDex.instructions.Insn12x in project soot by Sable.
the class ExprVisitor method build2AddrBinaryInsn.
private Insn build2AddrBinaryInsn(final String binaryOperation, Register secondOpReg) {
String localTypeString = destinationReg.getTypeString();
localTypeString = fixIntTypeString(localTypeString);
Opcode opc = Opcode.valueOf(binaryOperation + "_" + localTypeString.toUpperCase() + "_2ADDR");
return new Insn12x(opc, destinationReg, secondOpReg);
}
use of soot.toDex.instructions.Insn12x in project soot by Sable.
the class ExprVisitor method caseNegExpr.
@Override
public void caseNegExpr(NegExpr ne) {
Value source = ne.getOp();
constantV.setOrigStmt(origStmt);
Register sourceReg = regAlloc.asImmediate(source, constantV);
Opcode opc;
Type type = source.getType();
if (type instanceof IntegerType) {
opc = Opcode.NEG_INT;
} else if (type instanceof FloatType) {
opc = Opcode.NEG_FLOAT;
} else if (type instanceof DoubleType) {
opc = Opcode.NEG_DOUBLE;
} else if (type instanceof LongType) {
opc = Opcode.NEG_LONG;
} else {
throw new RuntimeException("unsupported value type for neg-* opcode: " + type);
}
stmtV.addInsn(new Insn12x(opc, destinationReg, sourceReg), origStmt);
}
use of soot.toDex.instructions.Insn12x in project soot by Sable.
the class ExprVisitor method castPrimitive.
private void castPrimitive(Register sourceReg, Value source, Type castSootType) {
PrimitiveType castType = PrimitiveType.getByName(castSootType.toString());
// than sorry and it's easy to fix it here.
if (castType == PrimitiveType.INT && source.getType() instanceof NullType)
source = IntConstant.v(0);
// select fitting conversion opcode, depending on the source and cast
// type
Type srcType = source.getType();
if (srcType instanceof RefType)
throw new RuntimeException("Trying to cast reference type " + srcType + " to a primitive");
PrimitiveType sourceType = PrimitiveType.getByName(srcType.toString());
if (castType == PrimitiveType.BOOLEAN) {
// there is no "-to-boolean" opcode, so just pretend to move an int
// to an int
castType = PrimitiveType.INT;
sourceType = PrimitiveType.INT;
}
if (shouldCastFromInt(sourceType, castType)) {
// pretend to cast from int since that is OK
sourceType = PrimitiveType.INT;
Opcode opc = getCastOpc(sourceType, castType);
stmtV.addInsn(new Insn12x(opc, destinationReg, sourceReg), origStmt);
} else if (isMoveCompatible(sourceType, castType)) {
/*
* no actual cast needed, just move the reg content if regs differ
*/
if (destinationReg.getNumber() != sourceReg.getNumber()) {
stmtV.addInsn(StmtVisitor.buildMoveInsn(destinationReg, sourceReg), origStmt);
} else // one for jumps
if (!origStmt.getBoxesPointingToThis().isEmpty())
stmtV.addInsn(new Insn10x(Opcode.NOP), origStmt);
} else if (needsCastThroughInt(sourceType, castType)) {
/*
* an unsupported "dest = (cast) src" is broken down to
* "tmp = (int) src" and "dest = (cast) tmp", using a tmp reg to not
* mess with the original reg types
*/
Opcode castToIntOpc = getCastOpc(sourceType, PrimitiveType.INT);
Opcode castFromIntOpc = getCastOpc(PrimitiveType.INT, castType);
Register tmp = regAlloc.asTmpReg(IntType.v());
stmtV.addInsn(new Insn12x(castToIntOpc, tmp, sourceReg), origStmt);
stmtV.addInsn(new Insn12x(castFromIntOpc, destinationReg, tmp.clone()), origStmt);
} else {
// the leftover simple cases, where we just cast as stated
Opcode opc = getCastOpc(sourceType, castType);
stmtV.addInsn(new Insn12x(opc, destinationReg, sourceReg), origStmt);
}
}
use of soot.toDex.instructions.Insn12x in project soot by Sable.
the class ExprVisitor method caseXorExpr.
@Override
public void caseXorExpr(XorExpr xe) {
Value firstOperand = xe.getOp1();
Value secondOperand = xe.getOp2();
constantV.setOrigStmt(origStmt);
// conversion
if (secondOperand.equals(IntConstant.v(-1)) || secondOperand.equals(LongConstant.v(-1))) {
PrimitiveType destRegType = PrimitiveType.getByName(destinationReg.getType().toString());
Register orgDestReg = destinationReg;
// We may need a temporary register if we need a typecast
if (isBiggerThan(PrimitiveType.getByName(secondOperand.getType().toString()), destRegType)) {
destinationReg = regAlloc.asTmpReg(IntType.v());
}
if (secondOperand.equals(IntConstant.v(-1))) {
Register sourceReg = regAlloc.asImmediate(firstOperand, constantV);
stmtV.addInsn(new Insn12x(Opcode.NOT_INT, destinationReg, sourceReg), origStmt);
} else if (secondOperand.equals(LongConstant.v(-1))) {
Register sourceReg = regAlloc.asImmediate(firstOperand, constantV);
stmtV.addInsn(new Insn12x(Opcode.NOT_LONG, destinationReg, sourceReg), origStmt);
}
// result
if (orgDestReg != destinationReg) {
Register tempReg = destinationReg.clone();
destinationReg = orgDestReg.clone();
castPrimitive(tempReg, secondOperand, destinationReg.getType());
}
} else {
// No shortcut, create normal binary operation
buildCalculatingBinaryInsn("XOR", firstOperand, secondOperand, xe);
}
}
Aggregations