ff688fd22c439f5fb133bddc1f263a5e071df5ea
[org.ibex.classgen.git] / src / org / ibex / classgen / JSSA.java
1 package org.ibex.classgen;
2 import java.io.*;
3 import java.util.*;
4
5 /**
6  *  a highly streamlined SSA-form intermediate representation of a
7  *  sequence of JVM instructions; all stack manipulation is factored
8  *  out.
9  */
10 public class JSSA extends MethodGen implements CGConst {
11
12     // Constructor //////////////////////////////////////////////////////////////////////////////
13     
14     public JSSA(Type.Class c, DataInput in, ConstantPool cp) throws IOException {
15         super(c, in, cp);
16         for(int i=0; i<this.method.getNumArgs(); i++)
17             local[i] = new Argument("arg"+i, this.method.getArgType(i));
18         for(int i=0; i<size(); i++) {
19             int    op  = get(i);
20             Object arg = getArg(i);
21             Object o = addOp(op, arg);
22             if (o != null) {
23                 ops[numOps] = o;
24                 ofs[numOps++] = i;
25             }
26         }
27     }
28
29     public void debugBodyToString(StringBuffer sb) {
30         StringBuffer sb0 = new StringBuffer();
31         super.debugBodyToString(sb0);
32         StringTokenizer st = new StringTokenizer(sb0.toString(), "\n");
33         String[] lines = new String[st.countTokens()];
34         for(int i=0; i<lines.length; i++) lines[i] = st.nextToken();
35         for(int j=0; j<ofs[0]; j++) {
36             String s = "    /* " + lines[j].trim();
37             while(s.length() < 50) s += " ";
38             s += " */";
39             sb.append(s);
40             sb.append("\n");
41         }
42         for(int i=0; i<numOps; i++) {
43             String s = "    /* " + lines[ofs[i]].trim();
44             while(s.length() < 50) s += " ";
45             s += " */  ";
46             s += ops[i].toString();
47             sb.append(s);
48             sb.append(";\n");
49             for(int j=ofs[i]+1; j<(i==numOps-1?size():ofs[i+1]); j++) {
50                 s = "    /* " + lines[j].trim();
51                 while(s.length() < 50) s += " ";
52                 s += " */";
53                 sb.append(s);
54                 sb.append("\n");
55             }
56         }
57     }
58     
59     private Object[] ops = new Object[65535];
60     private int[] ofs = new int[65535];
61     private int numOps = 0;
62
63     // Instance Data; used ONLY during constructor; then thrown away /////////////////////////////////////////////////
64
65     /** this models the JVM locals; it is only used for unwinding stack-ops into an SSA-tree, then thrown away */
66     private Expr[] local = new Expr[6];
67     
68     /** this models the JVM stack; it is only used for unwinding stack-ops into an SSA-tree, then thrown away */
69     private Expr[] stack = new Expr[65535];
70
71     /** JVM stack pointer */
72     private int sp = 0;
73     
74     private Expr push(Expr e) { return stack[sp++] = e; }
75     private Expr pop()        { return stack[--sp]; }
76
77
78     // SSA-node classes /////////////////////////////////////////////////////////////////////////////////////////
79
80     /** an purely imperative operation which does not generate data */
81     public abstract class Op {
82         //public abstract Op[] predecessors();  // not implemented yet
83         //public abstract Op[] successors();    // not implemented yet
84         public String toString() { return name(); }
85         String name() {
86             String name = this.getClass().getName();
87             if (name.indexOf('$') != -1) name = name.substring(name.lastIndexOf('$')+1);
88             if (name.indexOf('.') != -1) name = name.substring(name.lastIndexOf('.')+1);
89             return name;
90         }
91     }
92
93     /** an operation which generates data */
94     public abstract class Expr extends Op {
95         //public abstract Expr[] contributors();  // not implemented yet
96         //public abstract Expr[] dependents();    // not implemented yet
97
98         /** every JSSA.Expr either remembers its type _OR_ knows how to figure it out (the latter is preferred to eliminate
99          *  redundant information that could possibly "disagree" with itself -- this happened a LOT in Soot) */
100         public abstract Type getType();
101     }
102
103     /**
104      *  A "nondeterministic merge" -- for example when the first instruction in a loop reads from a local which could have been
105      *  written to either by some instruction at the end of the previous iteration of the loop or by some instruction before
106      *  the loop (on the first iteration).
107      */
108     public class Phi extends Expr {
109         private final Expr[] inputs;
110         public Phi(Expr[] inputs) {
111             this.inputs = new Expr[inputs.length];
112             System.arraycopy(inputs, 0, this.inputs, 0, inputs.length);
113         }
114         public Type getType() {
115             // sanity check
116             Type t = inputs[0].getType();
117
118             // FIXME: actually this should check type-unifiability... fe, the "type of null" unifies with any Type.Ref
119             for(int i=1; i<inputs.length; i++)
120                 if (inputs[i].getType() != t)
121                     throw new Error("Phi node with disagreeing types!  Crisis!");
122             return t;
123         }
124     }
125
126     public class Argument extends Expr {
127         public final String name;
128         public final Type t;
129         public Argument(String name, Type t) { this.name = name; this.t = t; }
130         public String toString() { return name; }
131         public Type getType() { return t; }
132     }
133
134     // Binary Operations //////////////////////////////////////////////////////////////////////////////
135
136     public abstract class BinExpr extends Expr {
137         public final Expr e1;
138         public final Expr e2;
139         public BinExpr(Expr e1, Expr e2) { this.e1 = e1; this.e2 = e2; }
140         public String toString() {
141             return name() + "("+e1+", "+e2+")";
142         }
143     }
144
145     public class Comparison extends BinExpr {
146         public Comparison(Expr e1, Expr e2) { super(e1, e2); }
147         public Type getType() { return Type.BOOLEAN; }
148     }
149     public class Gt extends Comparison { public Gt(Expr e1, Expr e2) { super(e1, e2); } }
150     public class Lt extends Comparison { public Lt(Expr e1, Expr e2) { super(e1, e2); } }
151     public class Eq extends Comparison { public Eq(Expr e1, Expr e2) { super(e1, e2); } }
152     public class Not extends Expr {
153         public final Expr e;
154         public Not(Expr e) { this.e = e; }
155         public Type getType() { return Type.BOOLEAN; }
156     }
157
158     // Math Operations //////////////////////////////////////////////////////////////////////////////
159
160     public class Math extends BinExpr {
161         private final String show;
162         public Math(Expr e1, Expr e2, String show) { super(e2, e1); this.show = show; }
163         public String toString() { return e1+" "+show+" "+e2; }
164         public Type getType() {
165             Type t = e1.getType();
166             if (t != e2.getType()) throw new Error("types disagree");
167             return t;
168         }
169     }
170     public class Add  extends Math { public  Add(Expr e, Expr e2) { super(e, e2, "+"); } }
171     public class Sub  extends Math { public  Sub(Expr e, Expr e2) { super(e, e2, "-"); } }
172     public class Mul  extends Math { public  Mul(Expr e, Expr e2) { super(e, e2, "*"); } }
173     public class Rem  extends Math { public  Rem(Expr e, Expr e2) { super(e, e2, "%"); } }
174     //public class Neg  extends Math { public  Neg(Expr e) { super(e, "-"); } }
175     public class Div  extends Math { public  Div(Expr e, Expr e2) { super(e, e2, "/"); } }
176     public class Shl  extends Math { public  Shl(Expr e, Expr e2) { super(e, e2, "<<"); } }
177     public class Shr  extends Math { public  Shr(Expr e, Expr e2) { super(e, e2, ">>"); } }
178     public class Ushr extends Math { public Ushr(Expr e, Expr e2) { super(e, e2, ">>>"); } }
179     public class And  extends Math { public  And(Expr e, Expr e2) { super(e, e2, "&"); } }
180     public class Or   extends Math { public   Or(Expr e, Expr e2) { super(e, e2, "|"); } }
181     public class Xor  extends Math { public  Xor(Expr e, Expr e2) { super(e, e2, "^"); } }
182
183     // Other operations //////////////////////////////////////////////////////////////////////////////
184
185     public class Cast extends Expr {
186         final Expr e;
187         final Type t;
188         public Cast(Expr e, Type t) { this.e = e; this.t = t; }
189         public Type getType() { return t; }
190     }
191
192     public class InstanceOf extends Expr {
193         final Expr e;
194         final Type t;
195         public InstanceOf(Expr e, Type t) { this.e = e; this.t = t; }
196         public Type getType() { return Type.BOOLEAN; }
197     }
198
199     public class Throw extends Op {
200         public final Expr e;
201         public Throw(Expr e) { this.e = e; }
202     }
203
204     public class Branch extends Op {
205         public Branch(Expr condition, Object destination) { }
206         public Branch(Label destination) { }
207         public Branch(MethodGen.Switch s) { }
208         public Branch() { }
209     }
210     public class Goto extends Branch { }
211     public class RET extends Branch { }
212     public class JSR extends Branch { public JSR(Label l) { super(l); } }
213     public class If extends Branch { }
214
215     /** represents a "returnaddr" pushed onto the stack */
216     public class Label extends Expr {
217         public final Op op;
218         public Type getType() { throw new Error("attempted to call getType() on a Label"); }
219         public Label(Op op) { this.op = op; }
220         public Label(int i) { this.op = null; /* FIXME */ }
221     }
222
223     public class Allocate extends Expr {
224         public final Type t;
225         public Type getType() { return t; }
226         public Allocate(Type t) { this.t = t; }
227         public Allocate(Type.Array t, Expr e) { this.t = t; }
228     }
229
230     public class Return extends Op {
231         final Expr e;
232         public Return() { this(null); }
233         public Return(Expr e) { this.e = e; }
234         public String toString() { return e==null?"return":("return "+e.toString()); }
235     }
236
237     /** GETFIELD and GETSTATIC */
238     public class Get extends Expr {
239         final Type.Class.Field f;
240         final Expr e;
241         public Type getType() { return f.getType(); }
242         public Get(Type.Class.Field f) { this(f, null); }
243         public Get(Type.Class.Field f, Expr e) { this.f = f; this.e = e; }
244         public String toString() {
245             return
246                 (e!=null
247                  ? e+"."+f.name
248                  : f.getDeclaringClass() == JSSA.this.method.getDeclaringClass()
249                  ? f.name
250                  : f.toString());
251         }
252     }
253
254     /** PUTFIELD and PUTSTATIC */
255     public class Put extends Op {
256         final Type.Class.Field f;
257         final Expr v;
258         final Expr e;
259         public Put(Type.Class.Field f, Expr v) { this(f, v, null); }
260         public Put(Type.Class.Field f, Expr v, Expr e) { this.f = f; this.v = v; this.e = e; }
261         public String toString() {
262             return
263                 (e!=null
264                  ? e+"."+f.name
265                  : f.getDeclaringClass() == JSSA.this.method.getDeclaringClass()
266                  ? f.name
267                  : f.toString()) + " = " + v;
268         }
269     }
270
271     public class ArrayPut extends Op {
272         final Expr e, i, v;
273         public ArrayPut(Expr e, Expr i, Expr v) { this.e = e; this.i = i; this.v = v; }
274     }
275
276     public class ArrayGet extends Expr {
277         final Expr e, i;
278         public ArrayGet(Expr e, Expr i) { this.e = e; this.i = i; }
279         public Type getType() { return e.getType().asArray().getElementType(); }
280     }
281
282     public class ArrayLength extends Expr {
283         final Expr e;
284         public ArrayLength(Expr e) { this.e = e; }
285         public Type getType() { return Type.INT; }
286     }
287
288     public abstract class Invoke extends Expr {
289         public final Expr[] arguments;
290         public final Type.Class.Method method;
291         protected Invoke(Type.Class.Method m, Expr[] a) { this.arguments = a; this.method = m; } 
292
293         public Type getType() { return method.getReturnType(); }
294         protected void args(StringBuffer sb) {
295             sb.append("(");
296             for(int i=0; i<arguments.length; i++) {
297                 if (i>0) sb.append(", ");
298                 sb.append(arguments[i]+"");
299             }
300             sb.append(")");
301         }
302
303         public String toString() {
304             StringBuffer sb = new StringBuffer();
305             sb.append(method.getDeclaringClass() == JSSA.this.method.getDeclaringClass()
306                       ? method.name
307                       : (method.getDeclaringClass() + "." + method.name));
308             args(sb);
309             return sb.toString();
310         }
311     }
312     public class InvokeStatic    extends Invoke  { public InvokeStatic(Type.Class.Method m, Expr[] a) { super(m,a); } }
313     public class InvokeSpecial   extends InvokeVirtual {
314         public InvokeSpecial(Type.Class.Method m, Expr[] a, Expr e) { super(m,a,e); }
315         public String toString() {
316             StringBuffer sb = new StringBuffer();
317             sb.append(method.name.equals("<init>") ? "super" : method.name);
318             args(sb);
319             return sb.toString();
320         }
321     }
322     public class InvokeInterface extends InvokeVirtual{public InvokeInterface(Type.Class.Method m, Expr[] a, Expr e){super(m,a,e);}}
323     public class InvokeVirtual   extends Invoke  {
324         public final Expr instance;
325         public InvokeVirtual(Type.Class.Method m, Expr[] a, Expr e) { super(m, a); instance = e; }
326         public String toString() {
327             StringBuffer sb = new StringBuffer();
328             sb.append(method.name);
329             args(sb);
330             return sb.toString();
331         }
332     }
333
334     public class Constant extends Expr {
335         private final Object o;
336         public Constant(Object o) { this.o = o; }
337         public String toString() { return o.toString(); }
338         public Type getType() {
339             if (o instanceof Byte) return Type.BYTE;
340             if (o instanceof Short) return Type.SHORT;
341             if (o instanceof Character) return Type.CHAR;
342             if (o instanceof Boolean) return Type.BOOLEAN;
343             if (o instanceof Long) return Type.LONG;
344             if (o instanceof Double) return Type.DOUBLE;
345             if (o instanceof Float) return Type.FLOAT;
346             if (o instanceof ConstantPool.Ent) throw new Error("unimplemented");
347             throw new Error("this should not happen");
348         }
349     }
350
351
352     // Implementation //////////////////////////////////////////////////////////////////////////////
353
354     private Object addOp(int op, Object arg) {
355         Number number = null;
356         int i1 = 0;
357         int i2 = 0;
358         if (op==WIDE) {
359             MethodGen.Wide w = (MethodGen.Wide)arg;
360             op = w.op;
361             arg = null;
362             i1 = w.varNum;
363             i2 = w.n;
364         }
365         if (op==IINC) {
366             MethodGen.Pair p = (MethodGen.Pair)arg;
367             arg = null;
368             i1 = p.i1;
369             i2 = p.i2;
370         }
371         if (arg != null && arg instanceof Number) number = (Number)arg;
372         switch(op) {
373
374             case NOP: return null;
375
376                 // Stack manipulations //////////////////////////////////////////////////////////////////////////////
377
378             case ACONST_NULL:                                                      return stack[sp++] = new Constant(null);
379             case ICONST_M1:                                                        return stack[sp++] = new Constant(-1);
380             case ICONST_0: case LCONST_0: case FCONST_0: case DCONST_0:            push(new Constant(0)); return null;
381             case ICONST_1: case LCONST_1: case FCONST_1: case DCONST_1:            push(new Constant(1)); return null;
382             case ICONST_2: case FCONST_2:                                          push(new Constant(2)); return null;
383             case ICONST_3:                                                         push(new Constant(3)); return null;
384             case ICONST_4:                                                         push(new Constant(4)); return null;
385             case ICONST_5:                                                         push(new Constant(5)); return null;
386             case ILOAD:    case LLOAD:    case FLOAD:    case DLOAD:    case ALOAD:    return push(local[i1]);
387             case ILOAD_0:  case LLOAD_0:  case FLOAD_0:  case DLOAD_0:  case ALOAD_0:  return push(local[0]);
388             case ILOAD_1:  case LLOAD_1:  case FLOAD_1:  case DLOAD_1:  case ALOAD_1:  return push(local[1]);
389             case ALOAD_2:  case DLOAD_2:  case FLOAD_2:  case LLOAD_2:  case ILOAD_2:  return push(local[2]);
390             case ILOAD_3:  case LLOAD_3:  case FLOAD_3:  case DLOAD_3:  case ALOAD_3:  return push(local[3]);
391             case ISTORE:   case LSTORE:   case FSTORE:   case DSTORE:   case ASTORE:   local[i1] = pop(); return null;
392             case ISTORE_0: case LSTORE_0: case FSTORE_0: case DSTORE_0: case ASTORE_0: local[0]  = pop(); return null;
393             case ISTORE_1: case LSTORE_1: case FSTORE_1: case DSTORE_1: case ASTORE_1: local[1]  = pop(); return null;
394             case ASTORE_2: case DSTORE_2: case FSTORE_2: case LSTORE_2: case ISTORE_2: local[2]  = pop(); return null;
395             case ISTORE_3: case LSTORE_3: case FSTORE_3: case DSTORE_3: case ASTORE_3: local[3]  = pop(); return null;
396             case POP:      stack[--sp] = null;                    
397             case POP2:     stack[--sp] = null; stack[--sp] = null;   /** fixme: pops a WORD, not an item */
398             case DUP:      stack[sp] = stack[sp-1]; sp++;
399             case DUP2:     stack[sp] = stack[sp-2]; stack[sp+1] = stack[sp-1]; sp+=2;
400
401                 // Conversions //////////////////////////////////////////////////////////////////////////////
402
403                 // coercions are added as-needed when converting from JSSA back to bytecode, so we can
404                 // simply discard them here (assuming the bytecode we're reading in was valid in the first place)
405
406             case I2L: case F2L: case D2L:               push(new Cast(pop(), Type.LONG)); return null;
407             case I2F: case L2F: case D2F:               push(new Cast(pop(), Type.FLOAT)); return null;
408             case I2D: case L2D: case F2D:               push(new Cast(pop(), Type.DOUBLE)); return null;
409             case L2I: case F2I: case D2I:               push(new Cast(pop(), Type.INT)); return null;
410             case I2B:                                   push(new Cast(pop(), Type.BYTE)); return null;
411             case I2C:                                   push(new Cast(pop(), Type.CHAR)); return null;
412             case I2S:                                   push(new Cast(pop(), Type.SHORT)); return null;
413             case SWAP:                                  { Expr e1 = pop(), e2 = pop(); push(e2);  push(e1); return null; }
414
415                 // Math //////////////////////////////////////////////////////////////////////////////
416                    
417             case IADD: case LADD: case FADD: case DADD: push(new Add(pop(), pop())); return null;
418             case ISUB: case LSUB: case FSUB: case DSUB: push(new Sub(pop(), pop())); return null;
419             case IMUL: case LMUL: case FMUL: case DMUL: push(new Mul(pop(), pop())); return null;
420             case IREM: case LREM: case FREM: case DREM: push(new Rem(pop(), pop())); return null;
421                 //case INEG: case LNEG: case FNEG: case DNEG: push(new Neg(pop())); return null;
422             case IDIV: case LDIV: case FDIV: case DDIV: push(new Div(pop(), pop())); return null;
423             case ISHL: case LSHL:                       push(new Shl(pop(), pop())); return null;
424             case ISHR: case LSHR:                       push(new Shr(pop(), pop())); return null;
425             case IUSHR: case LUSHR:                     push(new Ushr(pop(), pop())); return null;
426             case IAND: case LAND:                       push(new And(pop(), pop())); return null;
427             case IOR:  case LOR:                        push(new Or(pop(), pop())); return null;
428             case IXOR: case LXOR:                       push(new Xor(pop(), pop())); return null;
429             case IINC:                                  return local[i1] = new Add(local[i1], new Constant(i2));
430
431                 // Control and branching //////////////////////////////////////////////////////////////////////////////
432
433             case IFNULL:                                return new Branch(new Eq(pop(), new Constant(null)), new Label(i1));
434             case IFNONNULL:                             return new Branch(new Not(new Eq(pop(),new Constant(null))),new Label(i1));
435             case IFEQ:                                  return new Branch(    new Eq(new Constant(0), pop()),  arg);
436             case IFNE:                                  return new Branch(new Not(new Eq(new Constant(0), pop())), arg);
437             case IFLT:                                  return new Branch(    new Lt(new Constant(0), pop()),  arg);
438             case IFGE:                                  return new Branch(new Not(new Lt(new Constant(0), pop())), arg);
439             case IFGT:                                  return new Branch(    new Gt(new Constant(0), pop()),  arg);
440             case IFLE:                                  return new Branch(new Not(new Gt(new Constant(0), pop())), arg);
441             case IF_ICMPEQ:                             return new Branch(    new Eq(pop(), pop()),  arg);
442             case IF_ICMPNE:                             return new Branch(new Not(new Eq(pop(), pop())), arg);
443             case IF_ICMPLT:                             return new Branch(    new Lt(pop(), pop()),  arg);
444             case IF_ICMPGE:                             return new Branch(new Not(new Lt(pop(), pop())), arg);
445             case IF_ICMPGT:                             return new Branch(    new Gt(pop(), pop()),  arg);
446             case IF_ICMPLE:                             return new Branch(new Not(new Gt(pop(), pop())), arg);
447             case IF_ACMPEQ:                             return new Branch(    new Eq(pop(), pop()),  arg);
448             case IF_ACMPNE:                             return new Branch(new Not(new Eq(pop(), pop())), arg);
449             case ATHROW:                                return new Throw(pop());
450             case GOTO:                                  return new Branch(new Label(i1));
451             case JSR:                                   return new JSR(new Label(i1));
452             case RET:                                   return new RET();
453             case RETURN:                                return new Return();
454             case IRETURN: case LRETURN: case FRETURN: case DRETURN: case ARETURN:
455                 return new Return(pop());
456
457                 // Array manipulations //////////////////////////////////////////////////////////////////////////////
458
459             case IALOAD:  case LALOAD:  case FALOAD:  case DALOAD:  case AALOAD:
460             case BALOAD:  case CALOAD:  case SALOAD:                                  push(new ArrayGet(pop(), pop())); return null;
461             case IASTORE: case LASTORE: case FASTORE: case DASTORE: case AASTORE:
462             case BASTORE: case CASTORE: case SASTORE:                                 return new ArrayPut(pop(), pop(), pop());
463
464                 // Invocation //////////////////////////////////////////////////////////////////////////////
465
466             case INVOKEVIRTUAL: case INVOKESPECIAL: case INVOKESTATIC: case INVOKEINTERFACE: {
467                 Type.Class.Method method = (Type.Class.Method)arg;
468                 Expr args[] = new Expr[method.getNumArgs()];
469                 for(int i=0; i<args.length; i++) args[args.length-i-1] = pop();
470                 switch(op) {
471                     case INVOKEVIRTUAL:   return push(new InvokeVirtual(method, args, pop()));
472                     case INVOKEINTERFACE: return push(new InvokeInterface(method, args, pop()));
473                     case INVOKESPECIAL:   return push(new InvokeSpecial(method, args, pop()));
474                     case INVOKESTATIC:    return push(new InvokeStatic(method, args));
475                 }
476             }
477
478                 // Field Access //////////////////////////////////////////////////////////////////////////////
479
480             case GETSTATIC:         push(new Get((Type.Class.Field)arg, null)); return null;
481             case PUTSTATIC:         return new Put((Type.Class.Field)arg, pop(), null);
482             case GETFIELD:          push(new Get((Type.Class.Field)arg, pop())); return null;
483             case PUTFIELD:          return new Put((Type.Class.Field)arg, pop(), pop());
484
485                 // Allocation //////////////////////////////////////////////////////////////////////////////
486
487             case NEW:               push(new Allocate((Type)arg)); return null;
488             case NEWARRAY:          push(new Allocate((Type.Array)arg, pop())); return null;
489             case ANEWARRAY:         push(new Allocate(Type.OBJECT.makeArray(), pop())); return null;
490             case MULTIANEWARRAY:    push(new Allocate(Type.OBJECT.makeArray(i2), null /* FIXME */)); return null;
491             case ARRAYLENGTH:       push(new ArrayLength(pop())); return null;
492
493                 // Runtime Type information //////////////////////////////////////////////////////////////////////////////
494
495             case CHECKCAST:         push(new Cast(pop(), (Type)arg)); return null;
496             case INSTANCEOF:        push(new InstanceOf(pop(), (Type)arg)); return null;
497
498             case LDC: case LDC_W: case LDC2_W: push(new Constant(arg)); return null;
499
500             case BIPUSH:    push(new Constant(i1));  // FIXME return null;
501             case SIPUSH:    push(new Constant(i1));  // FIXME return null;
502
503             case TABLESWITCH:    new Branch((MethodGen.Switch)arg);
504             case LOOKUPSWITCH:   new Branch((MethodGen.Switch)arg);
505
506                 /*
507             case MONITORENTER:   Op.monitorEnter(pop());
508             case MONITOREXIT:    Op.monitorExit(pop());
509                 */
510
511             case DUP_X1:         throw new Error("unimplemented");
512             case DUP_X2:         throw new Error("unimplemented");
513             case DUP2_X1:         throw new Error("unimplemented");
514             case DUP2_X2:         throw new Error("unimplemented");
515             case LCMP:         throw new Error("unimplemented");
516             case FCMPL:         throw new Error("unimplemented");
517             case FCMPG:         throw new Error("unimplemented");
518             case DCMPL:         throw new Error("unimplemented");
519             case DCMPG:         throw new Error("unimplemented");
520             case GOTO_W:         throw new Error("unimplemented");
521             case JSR_W:         throw new Error("unimplemented");
522             default:          throw new Error("unhandled");
523         }
524     }
525
526     public static void main(String[] args) throws Exception {
527         InputStream is = Class.forName(args[0]).getClassLoader().getResourceAsStream(args[0].replace('.', '/')+".class");
528         System.out.println(new ClassFile(new DataInputStream(is), true).debugToString());
529     }
530 }