bug fix: check for if_ne

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@802 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 7b849a651e
commit 0df4bdab28
  1. 66
      jode/jode/jvm/Interpreter.java

@ -18,7 +18,9 @@
*/ */
package jode.jvm; package jode.jvm;
import jode.*; import jode.AssertError;
import jode.GlobalOptions;
import jode.type.*;
import jode.bytecode.*; import jode.bytecode.*;
import jode.decompiler.ClassAnalyzer; import jode.decompiler.ClassAnalyzer;
import java.lang.reflect.Array; import java.lang.reflect.Array;
@ -33,6 +35,16 @@ import java.lang.reflect.InvocationTargetException;
*/ */
public class Interpreter implements Opcodes { public class Interpreter implements Opcodes {
private final static int CMP_EQ = 0;
private final static int CMP_NE = 1;
private final static int CMP_LT = 2;
private final static int CMP_GE = 3;
private final static int CMP_GT = 4;
private final static int CMP_LE = 5;
private final static int CMP_GREATER_MASK = 1 << (CMP_GT|CMP_GE|CMP_NE);
private final static int CMP_LESS_MASK = 1 << (CMP_LT|CMP_LE|CMP_NE);
private final static int CMP_EQUAL_MASK = 1 << (CMP_GE|CMP_LE|CMP_EQ);
public static Object interpretMethod public static Object interpretMethod
(RuntimeEnvironment env, BytecodeInfo code, Value[] locals) (RuntimeEnvironment env, BytecodeInfo code, Value[] locals)
throws InterpreterException, InvocationTargetException { throws InterpreterException, InvocationTargetException {
@ -46,21 +58,23 @@ public class Interpreter implements Opcodes {
for(;;) { for(;;) {
try { try {
Instruction instr = pc; Instruction instr = pc;
System.err.print(instr.addr+": ["); if ((GlobalOptions.debuggingFlags
for (int i=0; i<stacktop; i++) { & GlobalOptions.DEBUG_INTERPRT) != 0) {
if (i>0) GlobalOptions.err.print(instr.addr+": [");
System.err.print(","); for (int i=0; i<stacktop; i++) {
System.err.print(stack[i]); if (i>0)
if (stack[i].objectValue() instanceof char[]) { GlobalOptions.err.print(",");
System.err.print(new String((char[])stack[i].objectValue())); GlobalOptions.err.print(stack[i]);
if (stack[i].objectValue() instanceof char[]) {
GlobalOptions.err.print(new String((char[])stack[i].objectValue()));
}
} }
GlobalOptions.err.println("]");
GlobalOptions.err.print("local: [");
for (int i=0; i<locals.length; i++)
GlobalOptions.err.print(locals[i]+",");
GlobalOptions.err.println("]");
} }
System.err.println("]");
System.err.print("local: [");
for (int i=0; i<locals.length; i++)
System.err.print(locals[i]+",");
System.err.println("]");
pc = instr.nextByAddr; pc = instr.nextByAddr;
int opcode = instr.opcode; int opcode = instr.opcode;
switch (opcode) { switch (opcode) {
@ -477,15 +491,14 @@ public class Interpreter implements Opcodes {
case opc_ifnull: case opc_ifnonnull: { case opc_ifnull: case opc_ifnonnull: {
int value; int value;
if (opcode >= opc_if_acmpeq) { if (opcode >= opc_if_acmpeq) {
Object objValue = stack[--stacktop].objectValue();
if (opcode >= opc_ifnull) { if (opcode >= opc_ifnull) {
value = value = objValue == null ? 0 : 1;
stack[--stacktop].objectValue() == null ? 0 : 1; opcode -= opc_ifnull;
opcode += opc_ifeq - opc_ifnull;
} else { } else {
value = value = objValue
stack[--stacktop].objectValue()
== stack[--stacktop].objectValue() ? 0 : 1; == stack[--stacktop].objectValue() ? 0 : 1;
opcode += opc_ifeq - opc_if_acmpeq; opcode -= opc_if_acmpeq;
} }
} else { } else {
value = stack[--stacktop].intValue(); value = stack[--stacktop].intValue();
@ -493,13 +506,14 @@ public class Interpreter implements Opcodes {
int val1 = stack[--stacktop].intValue(); int val1 = stack[--stacktop].intValue();
value = (val1 == value ? 0 value = (val1 == value ? 0
: val1 < value ? -1 : 1); : val1 < value ? -1 : 1);
opcode += opc_ifeq - opc_if_icmpeq; opcode -= opc_if_icmpeq;
} } else
opcode -= opc_ifeq;
} }
if (value > 0 && (opcode == opc_ifgt || opcode == opc_ifge) int opc_mask = 1 << opcode;
|| value < 0 && (opcode == opc_iflt || opcode == opc_ifle) if (value > 0 && (opc_mask & CMP_GREATER_MASK) != 0
|| value == 0 && (opcode == opc_ifge || opcode == opc_ifle || value < 0 && (opc_mask & CMP_LESS_MASK) != 0
|| opcode == opc_ifeq)) || value == 0 && (opc_mask & CMP_EQUAL_MASK) != 0)
pc = instr.succs[0]; pc = instr.succs[0];
break; break;
} }

Loading…
Cancel
Save