ask Brian a question
[org.ibex.classgen.git] / src / org / ibex / classgen / JSSA.java
index 8582df2..55ed8db 100644 (file)
@@ -15,45 +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;
-            }
-        }
-    }
-
-    public void debugBodyToString(StringBuffer sb) {
-        StringBuffer sb0 = new StringBuffer();
-        super.debugBodyToString(sb0);
-        StringTokenizer st = new StringTokenizer(sb0.toString(), "\n");
-        String[] lines = new String[st.countTokens()];
-        for(int i=0; i<lines.length; i++) lines[i] = st.nextToken();
-        for(int j=0; j<ofs[0]; j++) {
-            String s = "    /* " + lines[j].trim();
-            while(s.length() < 50) s += " ";
-            s += " */";
-            sb.append(s);
-            sb.append("\n");
-        }
-        for(int i=0; i<numOps; i++) {
-            String s = "    /* " + lines[ofs[i]].trim();
-            while(s.length() < 50) s += " ";
-            s += " */  ";
-            s += ops[i].toString();
-            sb.append(s);
-            sb.append(";\n");
-            for(int j=ofs[i]+1; j<(i==numOps-1?size():ofs[i+1]); j++) {
-                s = "    /* " + lines[j].trim();
-                while(s.length() < 50) s += " ";
-                s += " */";
-                sb.append(s);
-                sb.append("\n");
+            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");
             }
         }
     }
@@ -74,17 +53,22 @@ public class JSSA extends MethodGen implements CGConst {
     private int sp = 0;
     
     private Expr push(Expr e) {
-        if(sp == stack.length) {
+        if (sp == stack.length) {
             for(int i=0;i<stack.length;i++) System.err.println("Stack " + i + ": " + stack[i]);
             throw new IllegalStateException("stack overflow (" + stack.length + ")");
         }
-        if(e.getType() == Type.VOID) throw new IllegalArgumentException("can't push a void");
+        if (e.getType() == Type.VOID) throw new IllegalArgumentException("can't push a void");
         return stack[sp++] = e;
     }
     private Expr pop() {
-        if(sp == 0) throw new IllegalStateException("stack underflow");
+        if (sp == 0) throw new IllegalStateException("stack underflow");
         return stack[--sp];
     }
+    
+    private Op seqPush(Expr e) {
+        push(e);
+        return new Seq(e);
+    }
 
 
     // SSA-node classes /////////////////////////////////////////////////////////////////////////////////////////
@@ -105,7 +89,16 @@ public class JSSA extends MethodGen implements CGConst {
             return name;
         }
     }
-
+    
+    /** A sequence point. expr is evaluated for side effects at this point, this does not generate data 
+        Expressions that haven't been evaluated with Seq are evaluated when they are first encountered
+      */
+    public class Seq extends Op {
+        private final Expr expr;
+        public String toString() { return expr.toString(); }
+        public Seq(Expr expr) { this.expr = expr; }
+    }
+    
     /** an operation which generates data */
     public abstract class Expr extends Op {
         //public abstract Expr[] contributors();  // not implemented yet
@@ -114,6 +107,9 @@ public class JSSA extends MethodGen implements CGConst {
         /** every JSSA.Expr either remembers its type _OR_ knows how to figure it out (the latter is preferred to eliminate
          *  redundant information that could possibly "disagree" with itself -- this happened a LOT in Soot) */
         public abstract Type getType();
+        
+        public final String toString() { return exprToString(this); }
+        public String _toString() { return super.toString(); } // Adam is going to hate me for this (yes; why is this here?)
     }
 
     /**
@@ -143,7 +139,7 @@ public class JSSA extends MethodGen implements CGConst {
         public final String name;
         public final Type t;
         public Argument(String name, Type t) { this.name = name; this.t = t; }
-        public String toString() { return name; }
+        public String _toString() { return name; }
         public Type getType() { return t; }
     }
     
@@ -151,21 +147,21 @@ public class JSSA extends MethodGen implements CGConst {
     public class Not extends Expr {
         public final Expr e;
         public Not(Expr e) {
-            if(e.getType() != Type.BOOLEAN) throw new IllegalArgumentException("not needs a boolean expression");
+            if (e.getType() != Type.BOOLEAN) throw new IllegalArgumentException("not needs a boolean expression");
             this.e = e;
         }
         public Type getType() { return Type.BOOLEAN; }
-        public String toString() { return "!(" + e + ")"; }
+        public String _toString() { return "!(" + e + ")"; }
     }
     
     public class Neg extends Expr {
         public final Expr e;
         public Neg(Expr e) {
-            if(!e.getType().isPrimitive()) throw new IllegalArgumentException("can only negate a primitive");
+            if (!e.getType().isPrimitive()) throw new IllegalArgumentException("can only negate a primitive");
             this.e = e;
         }
         public Type getType() { return e.getType(); }
-        public String toString() { return "- (" + e + ")"; }
+        public String _toString() { return "- (" + e + ")"; }
     }
     
     // Binary Operations //////////////////////////////////////////////////////////////////////////////
@@ -175,7 +171,7 @@ public class JSSA extends MethodGen implements CGConst {
         public final Expr e2;
         private final String show;
         public BinExpr(Expr e1, Expr e2, String show) { this.e1 = e1; this.e2 = e2; this.show = show; }
-        public String toString() {
+        public String _toString() {
             // FEATURE: should we be doing some precedence stuff here? probably no worth it for debugging output
             return "(" + e1 + show + e2 + ")";
         }
@@ -189,9 +185,9 @@ public class JSSA extends MethodGen implements CGConst {
     public class Eq extends Comparison {
         public Eq(Expr e1, Expr e2) {
             super(e1, e2, "=="); 
-            if(e1.getType().isPrimitive() != e2.getType().isPrimitive())
+            if (e1.getType().isPrimitive() != e2.getType().isPrimitive())
                 throw new IllegalArgumentException("type mismatch");
-            if(e1.getType().isPrimitive() && e1.getType() != e2.getType())
+            if (e1.getType().isPrimitive() && e1.getType() != e2.getType())
                 throw new IllegalArgumentException("type mismatch");            
             // FEATURE: Check if we can compare these classes
         }
@@ -201,7 +197,7 @@ public class JSSA extends MethodGen implements CGConst {
     public class PrimitiveComparison extends Comparison {
         public PrimitiveComparison(Expr e1, Expr e2, String show) {
             super(e1, e2, show);
-            if(!e1.getType().isPrimitive() || e1.getType() != e2.getType()) throw new IllegalArgumentException("type mismatch");
+            if (!e1.getType().isPrimitive() || e1.getType() != e2.getType()) throw new IllegalArgumentException("type mismatch");
         }
     }
     
@@ -215,7 +211,7 @@ public class JSSA extends MethodGen implements CGConst {
     public class BinMath extends BinExpr {
         public BinMath(Expr e1, Expr e2, String show) {
             super(e2, e1, show); 
-            if(e1.getType() != e2.getType()) throw new IllegalArgumentException("types disagree");
+            if (e1.getType() != e2.getType()) throw new IllegalArgumentException("types disagree");
         }
         public Type getType() { return e1.getType(); }
     }
@@ -233,8 +229,8 @@ public class JSSA extends MethodGen implements CGConst {
         public BitShiftExpr(Expr e1, Expr e2, String show) {
             super(e1,e2,show);
             Type t = e1.getType();
-            if(t != Type.INT && t != Type.LONG) throw new IllegalArgumentException("type mismatch");
-            if(e2.getType() != Type.INT) throw new IllegalArgumentException("type mismatch");
+            if (t != Type.INT && t != Type.LONG) throw new IllegalArgumentException("type mismatch");
+            if (e2.getType() != Type.INT) throw new IllegalArgumentException("type mismatch");
         }
         public Type getType() { return e1.getType(); }
     }
@@ -248,7 +244,7 @@ public class JSSA extends MethodGen implements CGConst {
         final Expr e;
         final Type t;
         public Cast(Expr e, Type t) {
-            if(e.getType().isRef() != t.isRef()) throw new IllegalArgumentException("invalid cast");
+            if (e.getType().isRef() != t.isRef()) throw new IllegalArgumentException("invalid cast");
             // FEATURE: Check that one is a subclass of the other if it is a ref
             this.e = e;
             this.t = t; 
@@ -260,7 +256,7 @@ public class JSSA extends MethodGen implements CGConst {
         final Expr e;
         final Type.Ref t;
         public InstanceOf(Expr e, Type.Ref t) {
-            if(!e.getType().isRef()) throw new IllegalArgumentException("can't do an instanceof check on a non-ref");
+            if (!e.getType().isRef()) throw new IllegalArgumentException("can't do an instanceof check on a non-ref");
             this.e = e; 
             this.t = t; 
         }
@@ -270,7 +266,7 @@ public class JSSA extends MethodGen implements CGConst {
     public class Throw extends Op {
         public final Expr e;
         public Throw(Expr e) {
-            if(!e.getType().isRef()) throw new IllegalArgumentException("can't throw a non ref");
+            if (!e.getType().isRef()) throw new IllegalArgumentException("can't throw a non ref");
             // FEATURE: CHeck that it is a subclass of Throwable
             this.e = e; 
         }
@@ -299,6 +295,7 @@ public class JSSA extends MethodGen implements CGConst {
         public final Type.Class t;
         public Type getType() { return t; }
         public New(Type.Class t) { this.t = t; }
+        public String _toString() { return "new " + t + "()"; }
     }
     
     public class NewArray extends Expr {
@@ -307,12 +304,28 @@ public class JSSA extends MethodGen implements CGConst {
         public NewArray(Type.Array t, Expr[] dims) { this.t = t; this.dims = dims; }
         public NewArray(Type.Array t, Expr dim) { this(t,new Expr[]{dim}); }
         public Type getType() { return t; }
+        public String _toString() {
+            Type base = t;
+            int totalDims = 0;
+            while(base.isArray()) {
+                totalDims++;
+                base = base.asArray().getElementType(); 
+            }
+            StringBuffer sb = new StringBuffer("new " + base);
+            for(int i=0;i<totalDims;i++)
+                sb.append("[" + (i < dims.length ? dims[i].toString() : "") + "]");
+            return sb.toString();
+        }
     }
     
     public class Return extends Op {
         final Expr e;
         public Return() { this(VOID_EXPR); }
-        public Return(Expr e) { this.e = e; }
+        public Return(Expr e) {
+            this.e = e; 
+            if (Type.unify(method.getReturnType(),e.getType()) != method.getReturnType())
+               throw new IllegalArgumentException("type mismatch");
+        }
         public String toString() { return e.getType() == Type.VOID ? "return" : ("return "+e.toString()); }
     }
 
@@ -323,7 +336,7 @@ public class JSSA extends MethodGen implements CGConst {
         public Type getType() { return f.getType(); }
         public Get(Type.Class.Field f) { this(f, null); }
         public Get(Type.Class.Field f, Expr e) { this.f = f; this.e = e; }
-        public String toString() {
+        public String _toString() {
             return
                 (e!=null
                  ? e+"."+f.name
@@ -352,13 +365,15 @@ public class JSSA extends MethodGen implements CGConst {
 
     public class ArrayPut extends Op {
         final Expr e, i, v;
-        public ArrayPut(Expr e, Expr i, Expr v) { this.e = e; this.i = i; this.v = v; }
+        public ArrayPut(Expr v, Expr i, Expr e) { this.e = e; this.i = i; this.v = v; }
+        public String toString() { return e + "[" + i + "] := " + v; }
     }
 
     public class ArrayGet extends Expr {
         final Expr e, i;
-        public ArrayGet(Expr e, Expr i) { this.e = e; this.i = i; }
+        public ArrayGet(Expr i, Expr e) { this.e = e; this.i = i; }
         public Type getType() { return e.getType().asArray().getElementType(); }
+        public String _toString() { return e + "[" + i + "]"; }
     }
 
     public class ArrayLength extends Expr {
@@ -382,7 +397,7 @@ public class JSSA extends MethodGen implements CGConst {
             sb.append(")");
         }
 
-        public String toString() {
+        public String _toString() {
             StringBuffer sb = new StringBuffer();
             sb.append(method.getDeclaringClass() == JSSA.this.method.getDeclaringClass()
                       ? method.name
@@ -394,20 +409,17 @@ public class JSSA extends MethodGen implements CGConst {
     public class InvokeStatic    extends Invoke  { public InvokeStatic(Type.Class.Method m, Expr[] a) { super(m,a); } }
     public class InvokeSpecial   extends InvokeVirtual {
         public InvokeSpecial(Type.Class.Method m, Expr[] a, Expr e) { super(m,a,e); }
-        public String toString() {
-            StringBuffer sb = new StringBuffer();
-            sb.append(method.name.equals("<init>") ? "super" : method.name);
-            args(sb);
-            return sb.toString();
-        }
+        public String _toString() { return _toString(method.name.equals("<init>") ? method.getDeclaringClass().getName() : method.name); }
     }
     public class InvokeInterface extends InvokeVirtual{public InvokeInterface(Type.Class.Method m, Expr[] a, Expr e){super(m,a,e);}}
     public class InvokeVirtual   extends Invoke  {
         public final Expr instance;
         public InvokeVirtual(Type.Class.Method m, Expr[] a, Expr e) { super(m, a); instance = e; }
-        public String toString() {
+        public String _toString() { return _toString(method.name); }
+        protected String _toString(String name) {
             StringBuffer sb = new StringBuffer();
-            sb.append(method.name);
+            sb.append(instance+".");
+            sb.append(name);
             args(sb);
             return sb.toString();
         }
@@ -417,8 +429,9 @@ public class JSSA extends MethodGen implements CGConst {
         private final Object o;
         public Constant(int i) { this(new Integer(i)); }
         public Constant(Object o) { this.o = o; }
-        public String toString() { return o.toString(); }
+        public String _toString() { return o == null ? "null" : o instanceof String ? "\"" + o + "\"" : o.toString(); }
         public Type getType() {
+            if (o == null) return Type.NULL;
             if (o instanceof Byte) return Type.BYTE;
             if (o instanceof Short) return Type.SHORT;
             if (o instanceof Character) return Type.CHAR;
@@ -426,8 +439,9 @@ 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;
+            if (o instanceof String) return Type.STRING;
+            throw new IllegalStateException("unknown constant type");
         }
     }
 
@@ -456,28 +470,28 @@ public class JSSA extends MethodGen implements CGConst {
 
                 // Stack manipulations //////////////////////////////////////////////////////////////////////////////
 
-            case ACONST_NULL:                                                      return stack[sp++] = new Constant(null);
-            case ICONST_M1:                                                        return stack[sp++] = new Constant(-1);
+            case ACONST_NULL:                                                      push(new Constant(null)); return null;
+            case ICONST_M1:                                                        push(new Constant(-1)); return null;
             case ICONST_0: case LCONST_0: case FCONST_0: case DCONST_0:            push(new Constant(0)); return null;
             case ICONST_1: case LCONST_1: case FCONST_1: case DCONST_1:            push(new Constant(1)); return null;
             case ICONST_2: case FCONST_2:                                          push(new Constant(2)); return null;
             case ICONST_3:                                                         push(new Constant(3)); return null;
             case ICONST_4:                                                         push(new Constant(4)); return null;
             case ICONST_5:                                                         push(new Constant(5)); return null;
-            case ILOAD:    case LLOAD:    case FLOAD:    case DLOAD:    case ALOAD:    return push(local[i1]);
-            case ILOAD_0:  case LLOAD_0:  case FLOAD_0:  case DLOAD_0:  case ALOAD_0:  return push(local[0]);
-            case ILOAD_1:  case LLOAD_1:  case FLOAD_1:  case DLOAD_1:  case ALOAD_1:  return push(local[1]);
-            case ALOAD_2:  case DLOAD_2:  case FLOAD_2:  case LLOAD_2:  case ILOAD_2:  return push(local[2]);
-            case ILOAD_3:  case LLOAD_3:  case FLOAD_3:  case DLOAD_3:  case ALOAD_3:  return push(local[3]);
+            case ILOAD:    case LLOAD:    case FLOAD:    case DLOAD:    case ALOAD:    push(local[i1]); return null;
+            case ILOAD_0:  case LLOAD_0:  case FLOAD_0:  case DLOAD_0:  case ALOAD_0:  push(local[0]); return null;
+            case ILOAD_1:  case LLOAD_1:  case FLOAD_1:  case DLOAD_1:  case ALOAD_1:  push(local[1]); return null;
+            case ALOAD_2:  case DLOAD_2:  case FLOAD_2:  case LLOAD_2:  case ILOAD_2:  push(local[2]); return null;
+            case ILOAD_3:  case LLOAD_3:  case FLOAD_3:  case DLOAD_3:  case ALOAD_3:  push(local[3]); return null;
             case ISTORE:   case LSTORE:   case FSTORE:   case DSTORE:   case ASTORE:   local[i1] = pop(); return null;
             case ISTORE_0: case LSTORE_0: case FSTORE_0: case DSTORE_0: case ASTORE_0: local[0]  = pop(); return null;
             case ISTORE_1: case LSTORE_1: case FSTORE_1: case DSTORE_1: case ASTORE_1: local[1]  = pop(); return null;
             case ASTORE_2: case DSTORE_2: case FSTORE_2: case LSTORE_2: case ISTORE_2: local[2]  = pop(); return null;
             case ISTORE_3: case LSTORE_3: case FSTORE_3: case DSTORE_3: case ASTORE_3: local[3]  = pop(); return null;
-            case POP:      stack[--sp] = null;                    
-            case POP2:     stack[--sp] = null; stack[--sp] = null;   /** fixme: pops a WORD, not an item */
-            case DUP:      stack[sp] = stack[sp-1]; sp++;
-            case DUP2:     stack[sp] = stack[sp-2]; stack[sp+1] = stack[sp-1]; sp+=2;
+            case POP:      pop(); return null;
+            case POP2:     pop(); pop(); return null;
+            case DUP:      push(stack[sp-1]); return null;
+            case DUP2:     push(stack[sp-2]); push(stack[sp-2]); return null;
 
                 // Conversions //////////////////////////////////////////////////////////////////////////////
 
@@ -538,9 +552,11 @@ public class JSSA extends MethodGen implements CGConst {
                 // Array manipulations //////////////////////////////////////////////////////////////////////////////
 
             case IALOAD:  case LALOAD:  case FALOAD:  case DALOAD:  case AALOAD:
-            case BALOAD:  case CALOAD:  case SALOAD:                                  push(new ArrayGet(pop(), pop())); return null;
+            case BALOAD:  case CALOAD:  case SALOAD:
+                return seqPush(new ArrayGet(pop(), pop()));
             case IASTORE: case LASTORE: case FASTORE: case DASTORE: case AASTORE:
-            case BASTORE: case CASTORE: case SASTORE:                                 return new ArrayPut(pop(), pop(), pop());
+            case BASTORE: case CASTORE: case SASTORE:
+                return new ArrayPut(pop(), pop(), pop());
 
                 // Invocation //////////////////////////////////////////////////////////////////////////////
 
@@ -548,19 +564,23 @@ 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 new Seq(ret);
             }
 
                 // Field Access //////////////////////////////////////////////////////////////////////////////
 
-            case GETSTATIC:         push(new Get((Type.Class.Field)arg, null)); return null;
+            case GETSTATIC:         return seqPush(new Get((Type.Class.Field)arg, null));
             case PUTSTATIC:         return new Put((Type.Class.Field)arg, pop(), null);
-            case GETFIELD:          push(new Get((Type.Class.Field)arg, pop())); return null;
+            case GETFIELD:          return seqPush(new Get((Type.Class.Field)arg, pop()));
             case PUTFIELD:          return new Put((Type.Class.Field)arg, pop(), pop());
 
                 // Allocation //////////////////////////////////////////////////////////////////////////////
@@ -579,31 +599,29 @@ public class JSSA extends MethodGen implements CGConst {
                     case 11: base = Type.LONG; break;
                     default: throw new IllegalStateException("invalid array type");
                 }
-                push(new NewArray(base.makeArray(),pop()));
-                return null;
+                return seqPush(new NewArray(base.makeArray(),pop()));
             }
             case ANEWARRAY:         push(new NewArray(((Type.Ref)arg).makeArray(), pop())); return null;
             case MULTIANEWARRAY: {
                 MethodGen.MultiANewArray mana = (MethodGen.MultiANewArray) arg;
                 Expr[] dims = new Expr[mana.dims];
                 for(int i=0;i<dims.length;i++) dims[i] = pop();
-                push(new NewArray(mana.type, dims));
-                return null;
+                return seqPush(new NewArray(mana.type, dims));
             }
-            case ARRAYLENGTH:       push(new ArrayLength(pop())); return null;
+            case ARRAYLENGTH:       return seqPush(new ArrayLength(pop()));
 
                 // Runtime Type information //////////////////////////////////////////////////////////////////////////////
 
-            case CHECKCAST:         push(new Cast(pop(), (Type.Ref)arg)); return null;
+            case CHECKCAST:         return seqPush(new Cast(pop(), (Type.Ref)arg));
             case INSTANCEOF:        push(new InstanceOf(pop(), (Type.Ref)arg)); return null;
 
             case LDC: case LDC_W: case LDC2_W: push(new Constant(arg)); return null;
 
-            case BIPUSH:    push(new Constant(i1));  // FIXME return null;
-            case SIPUSH:    push(new Constant(i1));  // FIXME return null;
+            case BIPUSH:    push(new Constant((Integer)arg)); return null;
+            case SIPUSH:    push(new Constant((Integer)arg)); return null;
 
-            case TABLESWITCH:    new Branch((MethodGen.Switch)arg);
-            case LOOKUPSWITCH:   new Branch((MethodGen.Switch)arg);
+            case TABLESWITCH:    return new Branch((MethodGen.Switch)arg);
+            case LOOKUPSWITCH:   return new Branch((MethodGen.Switch)arg);
 
                 /*
             case MONITORENTER:   Op.monitorEnter(pop());
@@ -625,6 +643,58 @@ public class JSSA extends MethodGen implements CGConst {
         }
     }
 
+    
+    public void debugBodyToString(StringBuffer sb) {
+        StringBuffer sb0 = new StringBuffer();
+        super.debugBodyToString(sb0);
+        StringTokenizer st = new StringTokenizer(sb0.toString(), "\n");
+        String[] lines = new String[st.countTokens()];
+        for(int i=0; i<lines.length; i++) lines[i] = st.nextToken();
+        for(int j=0; j<ofs[0]; j++) {
+            String s = "    /* " + lines[j].trim();
+             while(s.length() < 50) s += " ";
+             s += " */";
+             sb.append(s);
+             sb.append("\n");
+        }
+        
+        bindingMap = new IdentityHashMap();
+        nextVar = 0;
+        
+        for(int i=0; i<numOps; i++) {
+            String s = "    /* " + lines[ofs[i]].trim();
+             while(s.length() < 50) s += " ";
+             s += " */  ";
+             s += ops[i].toString();
+             sb.append(s);
+             sb.append(";\n");
+             for(int j=ofs[i]+1; j<(i==numOps-1?size():ofs[i+1]); j++) {
+                 s = "    /* " + lines[j].trim();
+                  while(s.length() < 50) s += " ";
+                  s += " */";
+                  sb.append(s);
+                  sb.append("\n");
+             }
+        }
+    }
+    
+    private Map bindingMap;
+    private int nextVar;
+    String exprToString(Expr e) {
+        if (e instanceof Constant) return e._toString();
+        String s = (String)bindingMap.get(e);
+        if (s != null) return s;
+        String prefix;
+        if (e.getType() == Type.VOID) return e._toString();
+        else if (e.getType() == Type.DOUBLE || e.getType() == Type.FLOAT) prefix = "f";
+        else if (e.getType().isPrimitive()) prefix = "i";
+        else if (e.getType().isArray()) prefix = "a";
+        else prefix = "o";
+        s = prefix + (nextVar++);
+        bindingMap.put(e,s);
+        return "(" + s + " = " + e._toString() + ")";
+    }
+    
     public static void main(String[] args) throws Exception {
         InputStream is = Class.forName(args[0]).getClassLoader().getResourceAsStream(args[0].replace('.', '/')+".class");
         System.out.println(new ClassFile(new DataInputStream(is), true).toString());