Fix support of SWAP instruction

This commit is contained in:
Alexey Andreev 2016-05-11 22:05:50 +03:00
parent 88a1a39301
commit 062f30634c

View File

@ -28,10 +28,10 @@ import org.teavm.model.util.ProgramUtils;
* @author Alexey Andreev * @author Alexey Andreev
*/ */
public class ProgramParser implements VariableDebugInformation { public class ProgramParser implements VariableDebugInformation {
static final byte ROOT = 0; private static final byte ROOT = 0;
static final byte SINGLE = 1; private static final byte SINGLE = 1;
static final byte DOUBLE_FIRST_HALF = 2; private static final byte DOUBLE_FIRST_HALF = 2;
static final byte DOUBLE_SECOND_HALF = 3; private static final byte DOUBLE_SECOND_HALF = 3;
private String fileName; private String fileName;
private StackFrame[] stackBefore; private StackFrame[] stackBefore;
private StackFrame[] stackAfter; private StackFrame[] stackAfter;
@ -60,17 +60,17 @@ public class ProgramParser implements VariableDebugInformation {
} }
private static class StackFrame { private static class StackFrame {
public final StackFrame next; final StackFrame next;
public final byte type; final byte type;
public final int depth; final int depth;
public StackFrame(int depth) { StackFrame(int depth) {
this.next = null; this.next = null;
this.type = ROOT; this.type = ROOT;
this.depth = depth; this.depth = depth;
} }
public StackFrame(StackFrame next, byte type) { StackFrame(StackFrame next, byte type) {
this.next = next; this.next = next;
this.type = type; this.type = type;
this.depth = next != null ? next.depth + 1 : 0; this.depth = next != null ? next.depth + 1 : 0;
@ -162,7 +162,7 @@ public class ProgramParser implements VariableDebugInformation {
@Override @Override
public Map<Integer, String> getDebugNames(Instruction insn) { public Map<Integer, String> getDebugNames(Instruction insn) {
Map<Integer, String> map = variableDebugNames.get(insn); Map<Integer, String> map = variableDebugNames.get(insn);
return map != null ? Collections.unmodifiableMap(map) : Collections.<Integer, String>emptyMap(); return map != null ? Collections.unmodifiableMap(map) : Collections.emptyMap();
} }
private void prepare(MethodNode method) { private void prepare(MethodNode method) {
@ -513,8 +513,8 @@ public class ProgramParser implements VariableDebugInformation {
} }
insn.setMethod(new MethodDescriptor(name, MethodDescriptor.parseSignature(desc))); insn.setMethod(new MethodDescriptor(name, MethodDescriptor.parseSignature(desc)));
for (int i = 0; i < bsmArgs.length; ++i) { for (Object bsmArg : bsmArgs) {
insn.getBootstrapArguments().add(convertConstant(bsmArgs[i])); insn.getBootstrapArguments().add(convertConstant(bsmArg));
} }
addInstruction(insn); addInstruction(insn);
@ -1200,8 +1200,9 @@ public class ProgramParser implements VariableDebugInformation {
case Opcodes.SWAP: { case Opcodes.SWAP: {
int b = popSingle(); int b = popSingle();
int a = popSingle(); int a = popSingle();
int tmp = pushSingle();
pushSingle(); pushSingle();
pushSingle();
int tmp = b + 1;
emitAssignInsn(a, tmp); emitAssignInsn(a, tmp);
emitAssignInsn(b, a); emitAssignInsn(b, a);
emitAssignInsn(tmp, b); emitAssignInsn(tmp, b);
@ -1726,7 +1727,7 @@ public class ProgramParser implements VariableDebugInformation {
} }
}; };
static MethodHandle parseHandle(Handle handle) { private static MethodHandle parseHandle(Handle handle) {
switch (handle.getTag()) { switch (handle.getTag()) {
case Opcodes.H_GETFIELD: case Opcodes.H_GETFIELD:
return MethodHandle.fieldGetter(handle.getOwner().replace('/', '.'), handle.getName(), return MethodHandle.fieldGetter(handle.getOwner().replace('/', '.'), handle.getName(),