From e7425630779581857fa3f4bd00113fde515e5592 Mon Sep 17 00:00:00 2001 From: Bob Pan Date: Wed, 8 Oct 2014 21:31:25 +0800 Subject: [PATCH] split DIV to Idiv/Ldiv/Fdiv/Ddiv Fixes issue 230 --HG-- branch : 2.x --- .../com/googlecode/dex2jar/ir/expr/Exprs.java | 13 ++++++++++- .../com/googlecode/dex2jar/ir/expr/Value.java | 2 +- .../dex2jar/ir/ts/TypeTransformer.java | 5 +++- .../d2j/converter/IR2JConverter.java | 5 +++- .../src/test/resources/smalis/i230.smali | 23 +++++++++++++++++++ 5 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 dex-translator/src/test/resources/smalis/i230.smali diff --git a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/expr/Exprs.java b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/expr/Exprs.java index f0286901..11ed482d 100644 --- a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/expr/Exprs.java +++ b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/expr/Exprs.java @@ -106,7 +106,18 @@ public final class Exprs { } public static BinopExpr nDiv(Value a, Value b, String type) { - return new BinopExpr(VT.DIV, a, b, type); + switch (type){ + case "I": + return new BinopExpr(VT.IDIV, a, b, type); + case "J": + return new BinopExpr(VT.LDIV, a, b, type); + case "F": + return new BinopExpr(VT.FDIV, a, b, type); + case "D": + return new BinopExpr(VT.DDIV, a, b, type); + default: + throw new RuntimeException("type must set to one of I/J/F/D"); + } } public static BinopExpr nEq(Value a, Value b, String type) { diff --git a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/expr/Value.java b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/expr/Value.java index 5d74e03f..69bfa40d 100644 --- a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/expr/Value.java +++ b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/expr/Value.java @@ -176,7 +176,7 @@ public abstract class Value implements Cloneable { public static enum VT { ADD("+", MAY_THROW), AND("&", MAY_THROW), ARRAY(MAY_THROW), CAST(MAY_THROW), CHECK_CAST(CAN_THROW), CONSTANT(0), DCMPG( - MAY_THROW), DCMPL(MAY_THROW), DIV("/", CAN_THROW), EQ("==", MAY_THROW), EXCEPTION_REF(0), FCMPG( + MAY_THROW), DCMPL(MAY_THROW), IDIV("/", CAN_THROW), LDIV("/", CAN_THROW), FDIV("/", MAY_THROW), DDIV("/", MAY_THROW), EQ("==", MAY_THROW), EXCEPTION_REF(0), FCMPG( MAY_THROW), FCMPL(MAY_THROW), FIELD(CAN_THROW), FILLED_ARRAY(CAN_THROW), GE(">=", MAY_THROW), GT(">", MAY_THROW), INSTANCE_OF(CAN_THROW), INVOKE_INTERFACE(CAN_THROW), // INVOKE_NEW(CAN_THROW), INVOKE_SPECIAL(CAN_THROW), INVOKE_STATIC(CAN_THROW), INVOKE_VIRTUAL(CAN_THROW), LCMP( diff --git a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/TypeTransformer.java b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/TypeTransformer.java index 891312fd..0c29b9a0 100644 --- a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/TypeTransformer.java +++ b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/TypeTransformer.java @@ -590,7 +590,10 @@ public class TypeTransformer implements Transformer { break; case ADD: case SUB: - case DIV: + case IDIV: + case LDIV: + case FDIV: + case DDIV: case MUL: case REM: { BinopExpr be = (BinopExpr) e2; diff --git a/dex-translator/src/main/java/com/googlecode/d2j/converter/IR2JConverter.java b/dex-translator/src/main/java/com/googlecode/d2j/converter/IR2JConverter.java index 4c631012..435da3f0 100755 --- a/dex-translator/src/main/java/com/googlecode/d2j/converter/IR2JConverter.java +++ b/dex-translator/src/main/java/com/googlecode/d2j/converter/IR2JConverter.java @@ -814,7 +814,10 @@ public class IR2JConverter implements Opcodes { case SUB: asm.visitInsn(getOpcode(type, ISUB)); break; - case DIV: + case IDIV: + case LDIV: + case FDIV: + case DDIV: asm.visitInsn(getOpcode(type, IDIV)); break; case MUL: diff --git a/dex-translator/src/test/resources/smalis/i230.smali b/dex-translator/src/test/resources/smalis/i230.smali new file mode 100644 index 00000000..cf7c1e48 --- /dev/null +++ b/dex-translator/src/test/resources/smalis/i230.smali @@ -0,0 +1,23 @@ +.class Li230; +.super Li230; + +.method public i230(II)F + .catchall { :L5 .. :L10 } :L9 + .registers 10 + move-object v0, p0 + monitor-enter v0 + :L5 + int-to-float v0, p1 + int-to-float v1, p2 + div-float/2addr v1, v0 + move-object v0, p0 + monitor-exit v0 + return v1 + + :L9 + move-exception v1 + monitor-exit v0 + :L10 + const v1, 0 + return v1 +.end method