use of soot.toDex.instructions.Insn23x in project soot by Sable.
the class ExprVisitor method buildCmpInsn.
private Insn buildCmpInsn(String opcodePrefix, Value firstOperand, Value secondOperand) {
constantV.setOrigStmt(origStmt);
Register firstReg = regAlloc.asImmediate(firstOperand, constantV);
Register secondReg = regAlloc.asImmediate(secondOperand, constantV);
// select fitting opcode according to the prefix and the type of the
// operands
Opcode opc = null;
// first one
if (opcodePrefix.equals("CMP_LONG")) {
opc = Opcode.CMP_LONG;
} else if (firstReg.isFloat()) {
opc = Opcode.valueOf(opcodePrefix + "_FLOAT");
} else if (firstReg.isDouble()) {
opc = Opcode.valueOf(opcodePrefix + "_DOUBLE");
} else {
throw new RuntimeException("unsupported type of operands for cmp* opcode: " + firstOperand.getType());
}
return new Insn23x(opc, destinationReg, firstReg, secondReg);
}
use of soot.toDex.instructions.Insn23x in project soot by Sable.
the class StmtVisitor method buildArrayPutInsn.
private Insn buildArrayPutInsn(ArrayRef destRef, Value source) {
Local array = (Local) destRef.getBase();
Register arrayReg = regAlloc.asLocal(array);
Value index = destRef.getIndex();
Register indexReg = regAlloc.asImmediate(index, constantV);
Register sourceReg = regAlloc.asImmediate(source, constantV);
String arrayTypeDescriptor = SootToDexUtils.getArrayTypeDescriptor((ArrayType) array.getType());
Opcode opc = getPutGetOpcodeWithTypeSuffix(APUT_OPCODE, arrayTypeDescriptor);
return new Insn23x(opc, sourceReg, arrayReg, indexReg);
}
use of soot.toDex.instructions.Insn23x in project soot by Sable.
the class StmtVisitor method buildArrayGetInsn.
private Insn buildArrayGetInsn(Register destinationReg, ArrayRef sourceRef) {
Value index = sourceRef.getIndex();
Register indexReg = regAlloc.asImmediate(index, constantV);
Local array = (Local) sourceRef.getBase();
Register arrayReg = regAlloc.asLocal(array);
String arrayTypeDescriptor = SootToDexUtils.getArrayTypeDescriptor((ArrayType) array.getType());
Opcode opc = getPutGetOpcodeWithTypeSuffix(AGET_OPCODE, arrayTypeDescriptor);
return new Insn23x(opc, destinationReg, arrayReg, indexReg);
}
use of soot.toDex.instructions.Insn23x in project soot by Sable.
the class ExprVisitor method buildNormalBinaryInsn.
private Insn buildNormalBinaryInsn(String binaryOperation, Register firstOpReg, Register secondOpReg) {
String localTypeString = firstOpReg.getTypeString();
localTypeString = fixIntTypeString(localTypeString);
Opcode opc = Opcode.valueOf(binaryOperation + "_" + localTypeString.toUpperCase());
return new Insn23x(opc, destinationReg, firstOpReg, secondOpReg);
}
use of soot.toDex.instructions.Insn23x in project soot by Sable.
the class RegisterAssigner method findFittingInsn.
private Insn findFittingInsn(Insn insn) {
if (!insn.hasIncompatibleRegs()) {
// no incompatible regs -> no fitting needed
return null;
}
// we expect the dex specification to rarely change, so we hard-code the
// mapping "unfitting -> fitting"
Opcode opc = insn.getOpcode();
if (insn instanceof Insn11n && opc.equals(Opcode.CONST_4)) {
// const-4 (11n, byteReg) -> const-16 (21s, shortReg)
Insn11n unfittingInsn = (Insn11n) insn;
if (unfittingInsn.getRegA().fitsShort()) {
return new Insn21s(Opcode.CONST_16, unfittingInsn.getRegA(), unfittingInsn.getLitB());
}
} else if (insn instanceof TwoRegInsn && opc.name.endsWith("_2ADDR")) {
// */2addr (12x, byteReg,byteReg) -> * (23x,
// shortReg,shortReg,shortReg)
Register regA = ((TwoRegInsn) insn).getRegA();
Register regB = ((TwoRegInsn) insn).getRegB();
if (regA.fitsShort() && regB.fitsShort()) {
// use new opcode without the "/2addr"
int oldOpcLength = opc.name.length();
String newOpcName = opc.name.substring(0, oldOpcLength - 6);
Opcode newOpc = Opcode.valueOf(newOpcName);
Register regAClone = regA.clone();
return new Insn23x(newOpc, regA, regAClone, regB);
}
} else if (insn instanceof TwoRegInsn && SootToDexUtils.isNormalMove(opc)) {
/*
* move+ (12x, byteReg,byteReg) -> move+/from16 (22x,
* shortReg,unconstReg) -> move+/16 (32x, unconstReg,unconstReg)
* where "+" is "", "-object" or "-wide"
*/
Register regA = ((TwoRegInsn) insn).getRegA();
Register regB = ((TwoRegInsn) insn).getRegB();
if (regA.getNumber() != regB.getNumber()) {
return StmtVisitor.buildMoveInsn(regA, regB);
}
}
// no fitting insn found
return null;
}