Fix some bugs in the new dx instruction code.

http://b/3447216

Change-Id: I9a77541b994f184da0e389840e5cac728ad6c072
diff --git a/dx/src/com/android/dx/io/instructions/DecodedInstruction.java b/dx/src/com/android/dx/io/instructions/DecodedInstruction.java
index c526f87..e418a1c 100644
--- a/dx/src/com/android/dx/io/instructions/DecodedInstruction.java
+++ b/dx/src/com/android/dx/io/instructions/DecodedInstruction.java
@@ -202,7 +202,7 @@
      * throw if the value is out of the range of a signed int.
      */
     public final int getLiteralInt() {
-        if (literal != (int) target) {
+        if (literal != (int) literal) {
             throw new DexException("Literal out of range: " + Hex.u8(literal));
         }
 
@@ -214,7 +214,7 @@
      * value is out of the range of a signed code unit.
      */
     public final short getLiteralUnit() {
-        if (literal != (short) target) {
+        if (literal != (short) literal) {
             throw new DexException("Literal out of range: " + Hex.u8(literal));
         }
 
@@ -226,7 +226,7 @@
      * throw if the value is out of the range of a signed byte.
      */
     public final int getLiteralByte() {
-        if (literal != (byte) target) {
+        if (literal != (byte) literal) {
             throw new DexException("Literal out of range: " + Hex.u8(literal));
         }
 
diff --git a/dx/src/com/android/dx/io/instructions/InstructionCodec.java b/dx/src/com/android/dx/io/instructions/InstructionCodec.java
index b178019..0790385 100644
--- a/dx/src/com/android/dx/io/instructions/InstructionCodec.java
+++ b/dx/src/com/android/dx/io/instructions/InstructionCodec.java
@@ -268,7 +268,7 @@
         @Override public void encode(DecodedInstruction insn, CodeOutput out) {
             out.write(
                     codeUnit(insn.getOpcode(), insn.getA()),
-                    insn.getLiteralUnit());
+                    insn.getIndexUnit());
         }
     },
 
@@ -595,7 +595,7 @@
         }
 
         @Override public void encode(DecodedInstruction insn, CodeOutput out) {
-            int literal = insn.getLiteralInt();
+            long literal = insn.getLiteral();
             out.write(
                     codeUnit(insn.getOpcode(), insn.getA()),
                     unit0(literal),
diff --git a/dx/src/com/android/dx/io/instructions/ShortArrayCodeInput.java b/dx/src/com/android/dx/io/instructions/ShortArrayCodeInput.java
index bb5a4a0..03897c9 100644
--- a/dx/src/com/android/dx/io/instructions/ShortArrayCodeInput.java
+++ b/dx/src/com/android/dx/io/instructions/ShortArrayCodeInput.java
@@ -55,18 +55,18 @@
 
     /** @inheritDoc */
     public int readInt() throws EOFException {
-        int short0 = read();
-        int short1 = read();
+        int short0 = read() & 0xffff;
+        int short1 = read() & 0xffff;
 
         return short0 | (short1 << 16);
     }
 
     /** @inheritDoc */
     public long readLong() throws EOFException {
-        long short0 = read();
-        long short1 = read();
-        long short2 = read();
-        long short3 = read();
+        long short0 = read() & 0xffff;
+        long short1 = read() & 0xffff;
+        long short2 = read() & 0xffff;
+        long short3 = read() & 0xffff;
 
         return short0 | (short1 << 16) | (short2 << 32) | (short3 << 48);
     }
diff --git a/dx/src/com/android/dx/merge/InstructionTransformer.java b/dx/src/com/android/dx/merge/InstructionTransformer.java
index 339055b..62c3a49 100644
--- a/dx/src/com/android/dx/merge/InstructionTransformer.java
+++ b/dx/src/com/android/dx/merge/InstructionTransformer.java
@@ -17,7 +17,6 @@
 package com.android.dx.merge;
 
 import com.android.dx.io.CodeReader;
-import com.android.dx.io.OpcodeInfo;
 import com.android.dx.io.instructions.DecodedInstruction;
 import com.android.dx.io.instructions.ShortArrayCodeOutput;
 import com.android.dx.util.DexException;
@@ -104,5 +103,4 @@
             throw new DexException("Cannot handle conversion to jumbo index!");
         }
     }
-
 }