Merge branch 'master' of https://code.google.com/p/dexmaker
Conflicts:
src/test/java/com/google/dexmaker/DexMakerTest.java
diff --git a/src/main/java/com/google/dexmaker/Code.java b/src/main/java/com/google/dexmaker/Code.java
index 50345c3..0d232bd 100644
--- a/src/main/java/com/google/dexmaker/Code.java
+++ b/src/main/java/com/google/dexmaker/Code.java
@@ -429,7 +429,7 @@
currentLabel.marked = true;
}
- // instructions: constants
+ // instructions: locals
public <T> void loadConstant(Local<T> target, T value) {
Rop rop = value == null
@@ -445,6 +445,14 @@
}
}
+ /**
+ * Copies the value in {@code source} to {@code target}.
+ */
+ public <T> void move(Local<T> target, Local<T> source) {
+ addInstruction(new PlainInsn(Rops.opMove(source.type.ropType),
+ sourcePosition, target.spec(), source.spec()));
+ }
+
// instructions: unary and binary
public <T> void op(UnaryOp op, Local<T> target, Local<T> source) {
@@ -480,7 +488,10 @@
}
/**
- * Compare floats or doubles.
+ * Compare floats or doubles. This stores -1 in {@code target} if {@code
+ * a < b}, 0 in {@code target} if {@code a == b} and 1 in target if {@code
+ * a > b}. This stores {@code nanValue} in {@code target} if either value
+ * is {@code NaN}.
*/
public <T extends Number> void compareFloatingPoint(
Local<Integer> target, Local<T> a, Local<T> b, int nanValue) {
@@ -497,7 +508,9 @@
}
/**
- * Compare longs.
+ * Compare longs. This stores -1 in {@code target} if {@code
+ * a < b}, 0 in {@code target} if {@code a == b} and 1 in target if {@code
+ * a > b}.
*/
public void compareLongs(Local<Integer> target, Local<Long> a, Local<Long> b) {
addInstruction(new PlainInsn(Rops.CMPL_LONG, sourcePosition, target.spec(),
diff --git a/src/test/java/com/google/dexmaker/DexMakerTest.java b/src/test/java/com/google/dexmaker/DexMakerTest.java
index cf16f62..2355916 100644
--- a/src/test/java/com/google/dexmaker/DexMakerTest.java
+++ b/src/test/java/com/google/dexmaker/DexMakerTest.java
@@ -1536,7 +1536,7 @@
assertEquals(5, intArrayLength.invoke(null, new Object[] { new int[5] }));
Method longArrayLength = arrayLengthMethod(LONG_ARRAY);
- assertEquals(0, longArrayLength.invoke(null, new Object[]{new long[0]}));
+ assertEquals(0, longArrayLength.invoke(null, new Object[] { new long[0] }));
assertEquals(5, longArrayLength.invoke(null, new Object[] { new long[5] }));
Method objectArrayLength = arrayLengthMethod(OBJECT_ARRAY);
@@ -1714,6 +1714,26 @@
method.invoke(instance); // will take 100ms
}
+ public void testMoveInt() throws Exception {
+ /*
+ * public static int call(int a) {
+ * int b = a;
+ * int c = a + b;
+ * return c;
+ * }
+ */
+ MethodId<?, Integer> methodId = GENERATED.getMethod(TypeId.INT, "call", TypeId.INT);
+ Code code = dexMaker.declare(methodId, PUBLIC | STATIC);
+ Local<Integer> a = code.getParameter(0, TypeId.INT);
+ Local<Integer> b = code.newLocal(TypeId.INT);
+ Local<Integer> c = code.newLocal(TypeId.INT);
+ code.move(b, a);
+ code.op(BinaryOp.ADD, c, a, b);
+ code.returnValue(c);
+
+ assertEquals(6, getMethod().invoke(null, 3));
+ }
+
public void testPrivateClassesAreUnsupported() {
try {
dexMaker.declare(TypeId.get("LPrivateClass;"), "PrivateClass.generated", PRIVATE,