do not push void method results
[org.ibex.classgen.git] / src / org / ibex / classgen / JSSA.java
index 8582df2..d01aa06 100644 (file)
@@ -15,15 +15,24 @@ public class JSSA extends MethodGen implements CGConst {
         super(c, in, cp);
         local = new Expr[maxLocals];
         stack = new Expr[maxStack];
-        for(int i=0; i<this.method.getNumArgs(); i++)
-            local[i] = new Argument("arg"+i, this.method.getArgType(i));
+        int n=0;
+        if (!isStatic())
+            local[n++] = new Argument("this",method.getDeclaringClass());
+        for(int i=0;i<this.method.getNumArgs(); i++)
+            local[n++] = new Argument("arg"+i, this.method.getArgType(i));
         for(int i=0; i<size(); i++) {
             int    op  = get(i);
             Object arg = getArg(i);
-            Object o = addOp(op, arg);
-            if (o != null) {
-                ops[numOps] = o;
-                ofs[numOps++] = i;
+            try {
+                Object o = addOp(op, arg);
+                if (o != null) {
+                    ops[numOps] = o;
+                    ofs[numOps++] = i;
+                }
+            } catch(RuntimeException e) {
+                System.err.println("Had a problem at PC: " + i + " of " + method);
+                e.printStackTrace();
+                throw new IOException("invalid class file");
             }
         }
     }
@@ -426,8 +435,8 @@ public class JSSA extends MethodGen implements CGConst {
             if (o instanceof Long) return Type.LONG;
             if (o instanceof Double) return Type.DOUBLE;
             if (o instanceof Float) return Type.FLOAT;
-            if (o instanceof ConstantPool.Ent) throw new Error("unimplemented");
-            throw new Error("this should not happen");
+            if (o instanceof Integer) return Type.INT;
+            throw new IllegalStateException("unknown constant type");
         }
     }
 
@@ -548,12 +557,16 @@ public class JSSA extends MethodGen implements CGConst {
                 Type.Class.Method method = (Type.Class.Method)arg;
                 Expr args[] = new Expr[method.getNumArgs()];
                 for(int i=0; i<args.length; i++) args[args.length-i-1] = pop();
+                Expr ret;
                 switch(op) {
-                    case INVOKEVIRTUAL:   return push(new InvokeVirtual(method, args, pop()));
-                    case INVOKEINTERFACE: return push(new InvokeInterface(method, args, pop()));
-                    case INVOKESPECIAL:   return push(new InvokeSpecial(method, args, pop()));
-                    case INVOKESTATIC:    return push(new InvokeStatic(method, args));
+                    case INVOKEVIRTUAL:   ret = new InvokeVirtual(method, args, pop()); break;
+                    case INVOKEINTERFACE: ret = new InvokeInterface(method, args, pop()); break;
+                    case INVOKESPECIAL:   ret = new InvokeSpecial(method, args, pop()); break;
+                    case INVOKESTATIC:    ret = new InvokeStatic(method, args); break;
+                    default: throw new Error("should never happen");
                 }
+                if(ret.getType() != Type.VOID) push(ret);
+                return ret;
             }
 
                 // Field Access //////////////////////////////////////////////////////////////////////////////