001    package AST;
002    
003    import java.util.HashSet;
004    import java.io.File;
005    import java.util.*;
006    import beaver.*;
007    import java.util.ArrayList;
008    import java.util.zip.*;
009    import java.io.*;
010    import java.io.FileNotFoundException;
011    import java.util.Collection;
012    /**
013      * @ast class
014     * 
015     */
016    public class BytecodeDebug extends Bytecode {
017    
018        public static int stackChange(byte b) {
019          int change = 0;
020          switch(b) {
021            // no change
022            case Bytecode.NOP: 
023            case Bytecode.LALOAD:
024            case Bytecode.DALOAD:
025            case Bytecode.SWAP:
026            case Bytecode.IINC:
027            case Bytecode.I2F:
028            case Bytecode.L2D:
029            case Bytecode.F2I:
030            case Bytecode.D2L:
031            case Bytecode.I2B:
032            case Bytecode.I2C:
033            case Bytecode.I2S:
034            case Bytecode.GOTO:
035            case Bytecode.RET:
036            case Bytecode.RETURN:
037            case Bytecode.NEWARRAY:
038            case Bytecode.ANEWARRAY:
039            case Bytecode.ARRAYLENGTH:
040            case Bytecode.CHECKCAST:
041            case Bytecode.INSTANCEOF:
042            case Bytecode.GOTO_W:
043            case Bytecode.BREAKPOINT:
044            case Bytecode.IMPDEP1:
045            case Bytecode.IMPDEP2:
046            case Bytecode.WIDE:
047            case Bytecode.INEG:
048            case Bytecode.FNEG:
049            case Bytecode.LNEG:
050            case Bytecode.DNEG:
051            case Bytecode.JSR:
052            case Bytecode.JSR_W:
053              change = 0;
054              break;
055              // add 1
056            case Bytecode.ACONST_NULL:
057            case Bytecode.ICONST_M1:
058            case Bytecode.ICONST_0:
059            case Bytecode.ICONST_1:
060            case Bytecode.ICONST_2:
061            case Bytecode.ICONST_3:
062            case Bytecode.ICONST_4:
063            case Bytecode.ICONST_5:
064            case Bytecode.FCONST_0:
065            case Bytecode.FCONST_1:
066            case Bytecode.FCONST_2: 
067            case Bytecode.BIPUSH:
068            case Bytecode.SIPUSH:
069            case Bytecode.LDC:
070            case Bytecode.LDC_W:
071            case Bytecode.ILOAD:
072            case Bytecode.FLOAD:
073            case Bytecode.ALOAD:
074            case Bytecode.ILOAD_0:
075            case Bytecode.ILOAD_1:
076            case Bytecode.ILOAD_2:
077            case Bytecode.ILOAD_3:
078            case Bytecode.FLOAD_0:
079            case Bytecode.FLOAD_1:
080            case Bytecode.FLOAD_2:
081            case Bytecode.FLOAD_3:
082            case Bytecode.ALOAD_0:
083            case Bytecode.ALOAD_1:
084            case Bytecode.ALOAD_2:
085            case Bytecode.ALOAD_3:
086            case Bytecode.DUP:
087            case Bytecode.DUP_X1:
088            case Bytecode.DUP_X2:
089            case Bytecode.I2L:
090            case Bytecode.I2D:
091            case Bytecode.F2L:
092            case Bytecode.F2D:
093            case Bytecode.NEW:
094              change = 1;
095              break;
096              // add 2
097            case Bytecode.LCONST_0:
098            case Bytecode.LCONST_1:
099            case Bytecode.DCONST_0:
100            case Bytecode.DCONST_1:
101            case Bytecode.LDC2_W:
102            case Bytecode.LLOAD:
103            case Bytecode.DLOAD:
104            case Bytecode.LLOAD_0:
105            case Bytecode.LLOAD_1:
106            case Bytecode.LLOAD_2:
107            case Bytecode.LLOAD_3:
108            case Bytecode.DLOAD_0:
109            case Bytecode.DLOAD_1:
110            case Bytecode.DLOAD_2:
111            case Bytecode.DLOAD_3:
112            case Bytecode.DUP2:
113            case Bytecode.DUP2_X1:
114            case Bytecode.DUP2_X2:
115              change = 2;
116              break;
117              // sub 1
118            case Bytecode.IALOAD:
119            case Bytecode.FALOAD:
120            case Bytecode.AALOAD:
121            case Bytecode.BALOAD:
122            case Bytecode.CALOAD:
123            case Bytecode.SALOAD:
124            case Bytecode.ISTORE:
125            case Bytecode.FSTORE:
126            case Bytecode.ASTORE:
127            case Bytecode.ISTORE_0:
128            case Bytecode.ISTORE_1:
129            case Bytecode.ISTORE_2:
130            case Bytecode.ISTORE_3:
131            case Bytecode.FSTORE_0:
132            case Bytecode.FSTORE_1:
133            case Bytecode.FSTORE_2:
134            case Bytecode.FSTORE_3:
135            case Bytecode.ASTORE_0:
136            case Bytecode.ASTORE_1:
137            case Bytecode.ASTORE_2:
138            case Bytecode.ASTORE_3:
139            case Bytecode.POP:
140            case Bytecode.IADD:
141            case Bytecode.FADD:
142            case Bytecode.ISUB:
143            case Bytecode.FSUB:
144            case Bytecode.IMUL:
145            case Bytecode.FMUL:
146            case Bytecode.IDIV:
147            case Bytecode.FDIV:
148            case Bytecode.IREM:
149            case Bytecode.FREM:
150            case Bytecode.ISHL:
151            case Bytecode.ISHR:
152            case Bytecode.IUSHR:
153            case Bytecode.LSHL:
154            case Bytecode.LSHR:
155            case Bytecode.LUSHR:
156            case Bytecode.IAND:
157            case Bytecode.IOR:
158            case Bytecode.IXOR:
159            case Bytecode.L2I:
160            case Bytecode.L2F:
161            case Bytecode.D2I:
162            case Bytecode.D2F:
163            case Bytecode.FCMPL:
164            case Bytecode.FCMPG:
165            case Bytecode.IFEQ:
166            case Bytecode.IFNE:
167            case Bytecode.IFLT:
168            case Bytecode.IFGE:
169            case Bytecode.IFGT:
170            case Bytecode.IFLE:
171            case Bytecode.TABLESWITCH:
172            case Bytecode.LOOKUPSWITCH: 
173            case Bytecode.IRETURN:
174            case Bytecode.FRETURN:
175            case Bytecode.ARETURN:
176            case Bytecode.MONITORENTER:
177            case Bytecode.MONITOREXIT:
178            case Bytecode.IFNULL:
179            case Bytecode.IFNONNULL:
180            case Bytecode.ATHROW: // remember to add one to each catch block
181              change = -1;
182              break;
183              // sub 2
184            case Bytecode.DSTORE:
185            case Bytecode.LSTORE:
186            case Bytecode.LSTORE_0:
187            case Bytecode.LSTORE_1:
188            case Bytecode.LSTORE_2:
189            case Bytecode.LSTORE_3:
190            case Bytecode.DSTORE_0:
191            case Bytecode.DSTORE_1:
192            case Bytecode.DSTORE_2:
193            case Bytecode.DSTORE_3:
194            case Bytecode.POP2:
195            case Bytecode.LADD:
196            case Bytecode.DADD:
197            case Bytecode.LSUB:
198            case Bytecode.DSUB:
199            case Bytecode.LMUL:
200            case Bytecode.DMUL:
201            case Bytecode.LDIV:
202            case Bytecode.DDIV:
203            case Bytecode.LREM:
204            case Bytecode.DREM:
205            case Bytecode.LAND:
206            case Bytecode.LOR:
207            case Bytecode.LXOR:
208            case Bytecode.IF_ICMPEQ:
209            case Bytecode.IF_ICMPNE:
210            case Bytecode.IF_ICMPLT:
211            case Bytecode.IF_ICMPGE:
212            case Bytecode.IF_ICMPGT:
213            case Bytecode.IF_ICMPLE:
214            case Bytecode.IF_ACMPEQ:
215            case Bytecode.IF_ACMPNE:
216            case Bytecode.LRETURN:
217            case Bytecode.DRETURN:
218              change = -2;
219              break;
220              // sub 3
221            case Bytecode.IASTORE:
222            case Bytecode.FASTORE:
223            case Bytecode.AASTORE:
224            case Bytecode.BASTORE:
225            case Bytecode.CASTORE:
226            case Bytecode.SASTORE:
227            case Bytecode.LCMP:
228            case Bytecode.DCMPL:
229            case Bytecode.DCMPG:
230              change = -3;
231              break;
232              // sub 4
233            case Bytecode.LASTORE:
234            case Bytecode.DASTORE:
235              change = -4;
236              break;
237    
238            case Bytecode.GETSTATIC:
239            case Bytecode.PUTSTATIC:
240            case Bytecode.GETFIELD:
241            case Bytecode.PUTFIELD:
242            case Bytecode.INVOKEVIRTUAL:
243            case Bytecode.INVOKESPECIAL:
244            case Bytecode.INVOKESTATIC:
245            case Bytecode.INVOKEINTERFACE:
246    
247            case Bytecode.MULTIANEWARRAY:
248    
249            default:
250              throw new Error("Can not compute stack change for bytecode: " + b);
251          }
252          return change;
253        }
254    
255    
256    
257        public static String toString(byte code) {
258          String res = "";
259          switch(code) 
260          {
261            case NOP: res = "nop";break;
262            case ACONST_NULL: res = "aconst_null";break;
263            case ICONST_M1: res = "iconst_m1";break;
264            case ICONST_0: res = "iconst_0";break;
265            case ICONST_1: res = "iconst_1";break;
266            case ICONST_2: res = "iconst_2";break;
267            case ICONST_3: res = "iconst_3";break;
268            case ICONST_4: res = "iconst_4";break;
269            case ICONST_5: res = "iconst_5";break;
270            case LCONST_0: res = "lconst_0";break;
271            case LCONST_1: res = "lconst_1";break;
272            case FCONST_0: res = "fconst_0";break;
273            case FCONST_1: res = "fconst_1";break;
274            case FCONST_2: res = "fconst_2";break;
275            case DCONST_0: res = "dconst_0";break;
276            case DCONST_1: res = "dconst_1";break;
277            case BIPUSH: res = "bipush";break;
278            case SIPUSH: res = "sipush";break;
279            case LDC: res = "ldc";break;
280            case LDC_W: res = "ldc_w";break;
281            case LDC2_W: res = "ldc2_w";break;
282            case ILOAD: res = "iload";break;
283            case LLOAD: res = "lload";break;
284            case FLOAD: res = "fload";break;
285            case DLOAD: res = "dload";break;
286            case ALOAD: res = "aload";break;
287            case ILOAD_0: res = "iload_0";break;
288            case ILOAD_1: res = "iload_1";break;
289            case ILOAD_2: res = "iload_2";break;
290            case ILOAD_3: res = "iload_3";break;
291            case LLOAD_0: res = "lload_0";break;
292            case LLOAD_1: res = "lload_1";break;
293            case LLOAD_2: res = "lload_2";break;
294            case LLOAD_3: res = "lload_3";break;
295            case FLOAD_0: res = "fload_0";break;
296            case FLOAD_1: res = "fload_1";break;
297            case FLOAD_2: res = "fload_2";break;
298            case FLOAD_3: res = "fload_3";break;
299            case DLOAD_0: res = "dload_0";break;
300            case DLOAD_1: res = "dload_1";break;
301            case DLOAD_2: res = "dload_2";break;
302            case DLOAD_3: res = "dload_3";break;
303            case ALOAD_0: res = "aload_0";break;
304            case ALOAD_1: res = "aload_1";break;
305            case ALOAD_2: res = "aload_2";break;
306            case ALOAD_3: res = "aload_3";break;
307            case IALOAD: res = "iaload";break;
308            case LALOAD: res = "laload";break;
309            case FALOAD: res = "faload";break;
310            case DALOAD: res = "daload";break;
311            case AALOAD: res = "aaload";break;
312            case BALOAD: res = "baload";break;
313            case CALOAD: res = "caload";break;
314            case SALOAD: res = "saload";break;
315            case ISTORE: res = "istore";break;
316            case LSTORE: res = "lstore";break;
317            case FSTORE: res = "fstore";break;
318            case DSTORE: res = "dstore";break;
319            case ASTORE: res = "astore";break;
320            case ISTORE_0: res = "istore_0";break;
321            case ISTORE_1: res = "istore_1";break;
322            case ISTORE_2: res = "istore_2";break;
323            case ISTORE_3: res = "istore_3";break;
324            case LSTORE_0: res = "lstore_0";break;
325            case LSTORE_1: res = "lstore_1";break;
326            case LSTORE_2: res = "lstore_2";break;
327            case LSTORE_3: res = "lstore_3";break;
328            case FSTORE_0: res = "fstore_0";break;
329            case FSTORE_1: res = "fstore_1";break;
330            case FSTORE_2: res = "fstore_2";break;
331            case FSTORE_3: res = "fstore_3";break;
332            case DSTORE_0: res = "dstore_0";break;
333            case DSTORE_1: res = "dstore_1";break;
334            case DSTORE_2: res = "dstore_2";break;
335            case DSTORE_3: res = "dstore_3";break;
336            case ASTORE_0: res = "astore_0";break;
337            case ASTORE_1: res = "astore_1";break;
338            case ASTORE_2: res = "astore_2";break;
339            case ASTORE_3: res = "astore_3";break;
340            case IASTORE: res = "iastore";break;
341            case LASTORE: res = "lastore";break;
342            case FASTORE: res = "fastore";break;
343            case DASTORE: res = "dastore";break;
344            case AASTORE: res = "aastore";break;
345            case BASTORE: res = "bastore";break;
346            case CASTORE: res = "castore";break;
347            case SASTORE: res = "sastore";break;
348            case POP: res = "pop";break;
349            case POP2: res = "pop2";break;
350            case DUP: res = "dup";break;
351            case DUP_X1: res = "dup_x1";break;
352            case DUP_X2: res = "dup_x2";break;
353            case DUP2: res = "dup2";break;
354            case DUP2_X1: res = "dup2_x1";break;
355            case DUP2_X2: res = "dup2_x2" ;break;
356            case SWAP: res = "swap";break;
357            case IADD: res = "iadd";break;
358            case LADD: res = "ladd";break;
359            case FADD: res = "fadd";break;
360            case DADD: res = "dadd";break;
361            case ISUB: res = "isub";break;
362            case LSUB: res = "lsub";break;
363            case FSUB: res = "fsub";break;
364            case DSUB: res = "dsub";break;
365            case IMUL: res = "imul";break;
366            case LMUL: res = "lmul";break;
367            case FMUL: res = "fmul";break;
368            case DMUL: res = "dmul";break;
369            case IDIV: res = "idiv";break;
370            case LDIV: res = "ldiv";break;
371            case FDIV: res = "fdiv";break;
372            case DDIV: res = "ddiv";break;
373            case IREM: res = "irem";break;
374            case LREM: res = "lrem";break;
375            case FREM: res = "frem";break;
376            case DREM: res = "drem";break;
377            case INEG: res = "ineg";break;
378            case LNEG: res = "lneg";break;
379            case FNEG: res = "fneg";break;
380            case DNEG: res = "dneg";break;
381            case ISHL: res = "ishl";break;
382            case LSHL: res = "lshl";break;
383            case ISHR: res = "ishr";break;
384            case LSHR: res = "lshr";break;
385            case IUSHR: res = "iushr";break;
386            case LUSHR: res = "lushr";break;
387            case IAND: res = "iand";break;
388            case LAND: res = "land";break;
389            case IOR: res = "ior";break;
390            case LOR: res = "lor";break;
391            case IXOR: res = "ixor";break;
392            case LXOR: res = "lxor";break;
393            case IINC: res = "iinc";break;
394            case I2L: res = "i2l";break;
395            case I2F: res = "i2f";break;
396            case I2D: res = "i2d";break;
397            case L2I: res = "l2i";break;
398            case L2F: res = "l2f";break;
399            case L2D: res = "l2d";break;
400            case F2I: res = "f2i";break;
401            case F2L: res = "f2l";break;
402            case F2D: res = "f2d";break;
403            case D2I: res = "d2i";break;
404            case D2L: res = "d2l";break;
405            case D2F: res = "d2f";break;
406            case I2B: res = "i2b";break;
407            case I2C: res = "i2c";break;
408            case I2S: res = "i2s";break;
409            case LCMP: res = "lcmp";break;
410            case FCMPL: res = "fcmpl";break;
411            case FCMPG: res = "fcmpg";break;
412            case DCMPL: res = "dcmpl";break;
413            case DCMPG: res = "dcmpg";break;
414            case IFEQ: res = "ifeq";break;
415            case IFNE: res = "ifne";break;
416            case IFLT: res = "iflt";break;
417            case IFGE: res = "ifge";break;
418            case IFGT: res = "ifgt";break;
419            case IFLE: res = "ifle";break;
420            case IF_ICMPEQ: res = "if_icmpeq";break;
421            case IF_ICMPNE: res = "if_icmpne";break;
422            case IF_ICMPLT: res = "if_icmplt";break;
423            case IF_ICMPGE: res = "if_icmpge";break;
424            case IF_ICMPGT: res = "if_icmpgt";break;
425            case IF_ICMPLE: res = "if_icmple";break;
426            case IF_ACMPEQ: res = "if_acmpeq";break;
427            case IF_ACMPNE: res = "if_acmpne";break;
428            case GOTO: res = "goto";break;
429            case JSR: res = "jsr";break;
430            case RET: res = "ret";break;
431            case TABLESWITCH: res = "tableswitch";break;
432            case LOOKUPSWITCH: res = "lookupswitch";break;
433            case IRETURN: res = "ireturn";break;
434            case LRETURN: res = "lreturn";break;
435            case FRETURN: res = "freturn" ;break;
436            case DRETURN: res = "dreturn";break;
437            case ARETURN: res = "areturn";break;
438            case RETURN: res = "return";break;
439            case GETSTATIC: res = "getstatic" ;break;
440            case PUTSTATIC: res = "putstatic";break;
441            case GETFIELD: res = "getfield";break;
442            case PUTFIELD: res = "putfield";break;
443            case INVOKEVIRTUAL: res = "invokevirtual";break;
444            case INVOKESPECIAL: res = "invokespecial";break;
445            case INVOKESTATIC: res = "invokestatic";break;
446            case INVOKEINTERFACE: res = "invokeinterface";break;
447            case NEW: res = "new";break;
448            case NEWARRAY: res = "newarray";break;
449            case ANEWARRAY: res = "anewarray";break;
450            case ARRAYLENGTH: res = "arraylength";break;
451            case ATHROW: res = "athrow";break;
452            case CHECKCAST: res = "checkcast";break;
453            case INSTANCEOF: res = "instanceof";break;
454            case MONITORENTER: res = "monitorenter";break;
455            case MONITOREXIT: res = "monitorexit";break;
456            case WIDE: res = "wide";break;
457            case MULTIANEWARRAY: res = "multianewarray";break;
458            case IFNULL: res = "ifnull";break;
459            case IFNONNULL: res = "ifnonnull";break;
460            case GOTO_W: res = "goto_w";break;
461            case JSR_W: res = "jsr_w";break;
462            case BREAKPOINT: res = "breakpoint";break;
463            case IMPDEP1: res = "impdep1";break;
464            case IMPDEP2: res = "impdep2";break;
465            default: res = "<UNKNOWN BYTECODE:"+code+">";
466          }
467          return res;
468        }
469    
470    
471    
472        private static String getByteOperand(byte[] codes, int index) {
473          return Integer.toString((int)codes[index]);
474        }
475    
476    
477        
478        private static String getCharOperand(byte[] codes, int index) {
479          int hi = ((codes[index + 0]       ) << 8);
480          int lo = ((codes[index + 1] & 0xff) << 0);
481          return Integer.toString(hi + lo);
482        }
483    
484    
485        
486        private static String getIntOperand(byte[] codes, int index) {
487          int hh = ((codes[index + 0]       ) << 24);
488          int hl = ((codes[index + 1] & 0xff) << 16);
489          int lh = ((codes[index + 2] & 0xff) << 8);
490          int ll = ((codes[index + 3] & 0xff) << 0);
491          return Integer.toString(hh + hl + lh + ll);
492        }
493    
494    
495        
496        public static String getOperands(byte[] codes, int index) {
497          String res = "";
498          switch(codes[index]) 
499          {
500            case NOP: break;
501            case ACONST_NULL:break;
502            case ICONST_M1:break;
503            case ICONST_0: break;
504            case ICONST_1: break;
505            case ICONST_2: break;
506            case ICONST_3: break;
507            case ICONST_4: break;
508            case ICONST_5: break;
509            case LCONST_0: break;
510            case LCONST_1: break;
511            case FCONST_0: break;
512            case FCONST_1: break;
513            case FCONST_2: break;
514            case DCONST_0: break;
515            case DCONST_1: break;
516            case BIPUSH: res = getByteOperand(codes, index+1);break;
517            case SIPUSH: res = getCharOperand(codes, index+1);break;
518            case LDC: res = getByteOperand(codes, index+1);break;
519            case LDC_W: res = getCharOperand(codes, index+1);break;
520            case LDC2_W: res = getCharOperand(codes, index+1);break;
521            case ILOAD: res = getByteOperand(codes, index+1);break;
522            case LLOAD: res = getByteOperand(codes, index+1);break;
523            case FLOAD: res = getByteOperand(codes, index+1);break;
524            case DLOAD: res = getByteOperand(codes, index+1);break;
525            case ALOAD: res = getByteOperand(codes, index+1);break;
526            case ILOAD_0: break;
527            case ILOAD_1: break;
528            case ILOAD_2: break;
529            case ILOAD_3: break;
530            case LLOAD_0: break;
531            case LLOAD_1: break;
532            case LLOAD_2: break;
533            case LLOAD_3: break;
534            case FLOAD_0: break;
535            case FLOAD_1: break;
536            case FLOAD_2: break;
537            case FLOAD_3: break;
538            case DLOAD_0: break;
539            case DLOAD_1: break;
540            case DLOAD_2: break;
541            case DLOAD_3: break;
542            case ALOAD_0: break;
543            case ALOAD_1: break;
544            case ALOAD_2: break;
545            case ALOAD_3: break;
546            case IALOAD: break;
547            case LALOAD: break;
548            case FALOAD: break;
549            case DALOAD: break;
550            case AALOAD: break;
551            case BALOAD: break;
552            case CALOAD: break;
553            case SALOAD: break;
554            case ISTORE: res = getByteOperand(codes, index+1);break;
555            case LSTORE: res = getByteOperand(codes, index+1);break;
556            case FSTORE: res = getByteOperand(codes, index+1);break;
557            case DSTORE: res = getByteOperand(codes, index+1);break;
558            case ASTORE: res = getByteOperand(codes, index+1);break;
559            case ISTORE_0: break;
560            case ISTORE_1: break;
561            case ISTORE_2: break;
562            case ISTORE_3: break;
563            case LSTORE_0: break;
564            case LSTORE_1: break;
565            case LSTORE_2: break;
566            case LSTORE_3: break;
567            case FSTORE_0: break;
568            case FSTORE_1: break;
569            case FSTORE_2: break;
570            case FSTORE_3: break;
571            case DSTORE_0: break;
572            case DSTORE_1: break;
573            case DSTORE_2: break;
574            case DSTORE_3: break;
575            case ASTORE_0: break;
576            case ASTORE_1: break;
577            case ASTORE_2: break;
578            case ASTORE_3: break;
579            case IASTORE: break;
580            case LASTORE: break;
581            case FASTORE: break;
582            case DASTORE: break;
583            case AASTORE: break;
584            case BASTORE: break;
585            case CASTORE: break;
586            case SASTORE: break;
587            case POP: break;
588            case POP2: break;
589            case DUP: break;
590            case DUP_X1: break;
591            case DUP_X2: break;
592            case DUP2: break;
593            case DUP2_X1: break;
594            case DUP2_X2:break;
595            case SWAP: break;
596            case IADD: break;
597            case LADD: break;
598            case FADD: break;
599            case DADD: break;
600            case ISUB: break;
601            case LSUB: break;
602            case FSUB: break;
603            case DSUB: break;
604            case IMUL: break;
605            case LMUL: break;
606            case FMUL: break;
607            case DMUL: break;
608            case IDIV: break;
609            case LDIV: break;
610            case FDIV: break;
611            case DDIV: break;
612            case IREM: break;
613            case LREM: break;
614            case FREM: break;
615            case DREM: break;
616            case INEG: break;
617            case LNEG: break;
618            case FNEG: break;
619            case DNEG: break;
620            case ISHL: break;
621            case LSHL: break;
622            case ISHR: break;
623            case LSHR: break;
624            case IUSHR: break;
625            case LUSHR: break;
626            case IAND: break;
627            case LAND: break;
628            case IOR: break;
629            case LOR: break;
630            case IXOR: break;
631            case LXOR: break;
632            case IINC: res = getByteOperand(codes, index+1) + " " + getByteOperand(codes, index+2); break;
633            case I2L: break;
634            case I2F: break;
635            case I2D: break;
636            case L2I: break;
637            case L2F: break;
638            case L2D: break;
639            case F2I: break;
640            case F2L: break;
641            case F2D: break;
642            case D2I: break;
643            case D2L: break;
644            case D2F: break;
645            case I2B: break;
646            case I2C: break;
647            case I2S: break;
648            case LCMP: break;
649            case FCMPL: break;
650            case FCMPG: break;
651            case DCMPL: break;
652            case DCMPG: break;
653            case IFEQ: res = getCharOperand(codes, index+1);break;
654            case IFNE: res = getCharOperand(codes, index+1);break;
655            case IFLT: res = getCharOperand(codes, index+1);break;
656            case IFGE: res = getCharOperand(codes, index+1);break;
657            case IFGT: res = getCharOperand(codes, index+1);break;
658            case IFLE: res = getCharOperand(codes, index+1);break;
659            case IF_ICMPEQ: res = getCharOperand(codes, index+1);break;
660            case IF_ICMPNE: res = getCharOperand(codes, index+1);break;
661            case IF_ICMPLT: res = getCharOperand(codes, index+1);break;
662            case IF_ICMPGE: res = getCharOperand(codes, index+1);break;
663            case IF_ICMPGT: res = getCharOperand(codes, index+1);break;
664            case IF_ICMPLE: res = getCharOperand(codes, index+1);break;
665            case IF_ACMPEQ: res = getCharOperand(codes, index+1);break;
666            case IF_ACMPNE: res = getCharOperand(codes, index+1);break;
667            case GOTO: res = getCharOperand(codes, index+1);break;
668            case JSR: res = getCharOperand(codes, index+1);break;
669            case RET: res = getByteOperand(codes, index+1);break;
670            case TABLESWITCH:
671                      {
672                        int db = ((index + 4) / 4) * 4; // Align-4, step to defaultbytes
673                        int val = fourByteToInt(codes, db);
674                        db+=4;
675                        res = "defaultbytes:" + val;
676                        int low = fourByteToInt(codes, db);
677                        db+=4;
678                        res += ", low:" + low;
679                        int high = fourByteToInt(codes, db);
680                        db+=4;
681                        res += ", high:" + high;
682                        for(int i = 0; i < (high-low+1); i++)
683                          res += "\n\t" + "offset:" + fourByteToInt(codes, db + i * 4);
684                      }
685                      break;
686            case LOOKUPSWITCH: 
687                      {
688                        int db = ((index + 4) / 4) * 4; // Align-4, step to defaultbytes
689                        int val = fourByteToInt(codes, db);
690                        db+=4;
691                        res = "defaultbytes:" + val;
692                        int npairs = fourByteToInt(codes, db);
693                        db+=4;
694                        res += ", npairs:" + npairs;
695                        for(int i = 0; i < npairs; i++)
696                          res += "\n\t" + "match:" + fourByteToInt(codes, db + i * 8) + ", offset:" + fourByteToInt(codes, db + i * 8 + 4);
697                      }
698                      break;
699            case IRETURN: break;
700            case LRETURN: break;
701            case FRETURN: break;
702            case DRETURN: break;
703            case ARETURN: break;
704            case RETURN: break;
705            case GETSTATIC: res = getCharOperand(codes, index+1);break;
706            case PUTSTATIC: res = getCharOperand(codes, index+1);break;
707            case GETFIELD: res = getCharOperand(codes, index+1);break;
708            case PUTFIELD: res = getCharOperand(codes, index+1);break;
709            case INVOKEVIRTUAL: res = getCharOperand(codes, index+1);break;
710            case INVOKESPECIAL: res = getCharOperand(codes, index+1);break;
711            case INVOKESTATIC: res = getCharOperand(codes, index+1);break;
712            case INVOKEINTERFACE: res = getCharOperand(codes, index+1)+" "+getByteOperand(codes, index+3);break;
713            case NEW: res = getCharOperand(codes, index+1);break;
714            case NEWARRAY: res = getByteOperand(codes, index+1);break;
715            case ANEWARRAY: res = getCharOperand(codes, index+1);break;
716            case ARRAYLENGTH: break;
717            case ATHROW: break;
718            case CHECKCAST: res = getCharOperand(codes, index+1);;break;
719            case INSTANCEOF: res = getCharOperand(codes, index+1);;break;
720            case MONITORENTER: break;
721            case MONITOREXIT: break;
722            case WIDE: res = "XXX";break;
723            case MULTIANEWARRAY: res = getCharOperand(codes, index+1)+" "+getByteOperand(codes, index+3);break;
724            case IFNULL: res = getCharOperand(codes, index+1);break;
725            case IFNONNULL: res = getCharOperand(codes, index+1);break;
726            case GOTO_W: res = getIntOperand(codes, index+1);break;
727            case JSR_W: res = getIntOperand(codes, index+1);break;
728            case BREAKPOINT: break;
729            case IMPDEP1: break;
730            case IMPDEP2: break;
731            default: res = "<UNKNOWN BYTECODE:"+codes[index]+">";
732          }
733          return res;
734        }
735    
736    
737    
738        public static int fourByteToInt(byte[] codes, int pos) {
739          int b1 = (int)codes[pos + 0];
740          int b2 = (int)codes[pos + 1];
741          int b3 = (int)codes[pos + 2];
742          int b4 = (int)codes[pos + 3];
743          int val = b1 << 24 | b2 << 16 | b3 << 8 | b4; 
744          return val; 
745        }
746    
747    
748    
749        public static int stepBytecode(byte[] codes, int index)
750        {
751          int res = 0;
752    
753          switch (codes[index]) {
754            case NOP:res++;break;
755            case ACONST_NULL:res++;break;
756            case LDC2_W:
757            case LDC_W:res+=3;break;
758            case LDC:res+=2;break;
759            case DCONST_0:
760            case DCONST_1:
761            case LCONST_0:
762            case LCONST_1:res++;break;
763            case BIPUSH:res+=2;break;
764            case SIPUSH:res+=3;break;
765            case FCONST_1:
766            case FCONST_2:
767            case FCONST_0:
768            case ICONST_M1:
769            case ICONST_0:
770            case ICONST_1:
771            case ICONST_2:
772            case ICONST_3:
773            case ICONST_4:
774            case ICONST_5:res++;break;
775            case FALOAD:
776            case BALOAD:
777            case CALOAD:
778            case SALOAD:
779            case IALOAD:res++;break;
780            case DALOAD:
781            case LALOAD:res++;break;
782            case AALOAD:res++;break;
783            case FLOAD:
784            case FSTORE:
785            case ILOAD:
786            case ISTORE:res+=2;break;
787            case FLOAD_0:
788            case FSTORE_0:
789            case ILOAD_0:
790            case ISTORE_0:res++;break;
791            case FLOAD_1:
792            case FSTORE_1:
793            case ILOAD_1:
794            case ISTORE_1:res++;break;
795            case FLOAD_2:
796            case FSTORE_2:
797            case ILOAD_2:
798            case ISTORE_2:res++;break;
799            case FLOAD_3:
800            case FSTORE_3:
801            case ILOAD_3:
802            case ISTORE_3:res++;break;
803            case DLOAD:
804            case DSTORE:
805            case LLOAD:
806            case LSTORE:res+=2;break;
807            case DLOAD_0:
808            case DSTORE_0:
809            case LLOAD_0:
810            case LSTORE_0:res++;break;
811            case DLOAD_1:
812            case DSTORE_1:
813            case LLOAD_1:
814            case LSTORE_1:res++;break;
815            case DLOAD_2:
816            case DSTORE_2:
817            case LLOAD_2:
818            case LSTORE_2:res++;break;
819            case DLOAD_3:
820            case DSTORE_3:
821            case LLOAD_3:
822            case LSTORE_3:res++;break;
823            case ALOAD:
824            case ASTORE:res+=2;break;
825            case ALOAD_0:
826            case ASTORE_0:res++;break;
827            case ALOAD_1:
828            case ASTORE_1:res++;break;
829            case ALOAD_2:
830            case ASTORE_2:res++;break;
831            case ALOAD_3:
832            case ASTORE_3:res++;break;
833            case FASTORE:
834            case IASTORE:res++;break;
835            case DASTORE:
836            case LASTORE:res++;break;
837            case AASTORE:res++;break;
838            case BASTORE:res++;break;
839            case CASTORE:
840            case SASTORE:res++;break;
841            case POP:res++;break;
842            case POP2:res++;break;
843            case DUP:res++;break;
844            case DUP_X1:res++;break;
845            case DUP_X2:res++;break;
846            case DUP2:res++;break;
847            case DUP2_X1:res++;break;
848            case DUP2_X2:res++;break;
849            case SWAP:res++;break;
850            case IADD:res++;break;
851            case FADD:res++;break;
852            case DADD:res++;break;
853            case LADD:res++;break;
854            case ISUB:res++;break;
855            case FSUB:res++;break;
856            case DSUB:res++;break;
857            case LSUB:res++;break;
858            case IMUL:res++;break;
859            case LMUL:res++;break;
860            case DMUL:res++;break;
861            case FMUL:res++;break;
862            case IDIV:res++;break;
863            case LDIV:res++;break;
864            case DDIV:res++;break;
865            case FDIV:res++;break;
866            case IREM:res++;break;
867            case LREM:res++;break;
868            case DREM:res++;break;
869            case FREM:res++;break;
870            case INEG:res++;break;
871            case LNEG:res++;break;
872            case DNEG:res++;break;
873            case FNEG:res++;break;
874            case ISHL:res++;break;
875            case LSHL:res++;break;
876            case ISHR:res++;break;
877            case LSHR:res++;break;
878            case IUSHR:res++;break;
879            case LUSHR:res++;break;
880            case IAND:res++;break;
881            case LAND:res++;break;
882            case IOR:res++;break;
883            case LOR:res++;break;
884            case IXOR:res++;break;
885            case LXOR:res++;break;
886            case IINC:res+=3;break;
887            case I2L:res++;break;
888            case I2F:res++;break;
889            case I2D:res++;break;
890            case L2I:res++;break;
891            case L2F:res++;break;
892            case L2D:res++;break;
893            case F2I:res++;break;
894            case F2L:res++;break;
895            case F2D:res++;break;
896            case D2I:res++;break;
897            case D2L:res++;break;
898            case D2F:res++;break;
899            case I2B:res++;break;
900            case I2C:res++;break;
901            case I2S:res++;break;
902            case LCMP:res++;break;
903            case FCMPL:res++;break;
904            case FCMPG:res++;break;
905            case DCMPL:res++;break;
906            case DCMPG:res++;break;
907            case IFEQ:res+=3;break;
908            case IFNE:res+=3;break;
909            case IFLT:res+=3;break;
910            case IFGE:res+=3;break;
911            case IFGT:res+=3;break;
912            case IFLE:res+=3;break;
913            case IF_ICMPEQ:res+=3;break;
914            case IF_ICMPNE:res+=3;break;
915            case IF_ICMPLT:res+=3;break;
916            case IF_ICMPGE:res+=3;break;
917            case IF_ICMPGT:res+=3;break;
918            case IF_ICMPLE:res+=3;break;
919            case IF_ACMPEQ:res+=3;break;
920            case IF_ACMPNE:res+=3;break;
921            case GOTO:res+=3;break;
922            case JSR:res+=3;break;
923            case RET:res+=2;break;
924            case TABLESWITCH:
925                     {
926                       int db = ((index + 4) / 4) * 4; // Align-4, step to defaultbytes
927                       db += 4;
928                       int low = fourByteToInt(codes, db);
929                       db += 4;
930                       int high = fourByteToInt(codes, db);
931                       db += 4;
932                       db += (high-low+1)*4;
933                       res = db;
934                     }
935                     break;
936            case LOOKUPSWITCH:
937                     {
938                       int db = ((index + 4) / 4) * 4; // Align-4, step to defaultbytes
939                       db += 4;
940                       int np = fourByteToInt(codes, db);
941                       db += 4;
942                       db += np * 8;
943                       res = db;
944                     }
945                     break;
946            case FRETURN:
947            case IRETURN:res++;break;
948            case LRETURN:
949            case DRETURN:res++;break;
950            case ARETURN:res++;break;
951            case RETURN:res++;break;
952            case GETSTATIC:
953            case PUTSTATIC:
954            case GETFIELD:
955            case PUTFIELD:res+=3;break;
956            case INVOKEVIRTUAL:res+=3;break;
957            case INVOKESPECIAL:res+=3;break;
958            case INVOKESTATIC:res+=3;break;
959            case INVOKEINTERFACE:res+=5;break;
960            case NEW:res+=3; break;
961            case NEWARRAY:res+=2;break;
962            case ANEWARRAY:res+=3;break;
963            case ARRAYLENGTH:res++;break;
964            case ATHROW:res++;break;
965            case CHECKCAST:res+=3;break;
966            case INSTANCEOF:res+=3;break;
967            case MONITORENTER:res++;break;
968            case MONITOREXIT:res++;break;
969            case WIDE:
970                             switch (codes[index+1])
971                             {
972                               case ILOAD:res+=4;break;
973                               case FLOAD:res+=4;break;
974                               case ALOAD:res+=4;break;
975                               case LLOAD:res+=4;break;
976                               case DLOAD:res+=4;break;
977                               case ISTORE:res+=4;break;
978                               case FSTORE:res+=4;break;
979                               case ASTORE:res+=4;break;
980                               case LSTORE:res+=4;break;
981                               case DSTORE:res+=4;break;
982                               case RET:res+=4;break;
983                               case IINC:res+=6;break;
984                               default:System.err.println("ERROR_INVALID_OPCODE in stepBytecode (wide)");break;
985                             }
986                             break;
987            case MULTIANEWARRAY:res+=4;break;
988            case IFNULL:res+=3;break;
989            case IFNONNULL:res+=3;break;
990            case GOTO_W:res+=5;break;
991            case JSR_W:res+=5;break;
992                       //        case BREAKPOINT: res++;break;
993                       //        case IMPDEP1: res++;break;
994                       //        case IMPDEP2: res++;break;
995            default:res++;System.err.println("INVALID BYTECODE " + codes[index] + " IN stepBytecode");
996          }
997          return res;
998        }
999    
1000    
1001    
1002        public static void printBytecode(PrintStream p, byte[] codes, int index) {
1003          p.print(toString(codes[index])+" "+getOperands(codes, index));
1004        }
1005    
1006     
1007    
1008        public static void printBytecodes(PrintStream p, byte[] codes) {
1009          for (int i=0,cnt=1; i<codes.length; i+=stepBytecode(codes,i),cnt++) {
1010            p.print("\t"+i+"\t"+cnt+"\t");
1011            printBytecode(p, codes, i);
1012            p.println();
1013          }
1014        }
1015    
1016    
1017    
1018        public static void appendBytecodes(StringBuffer p, byte[] codes) {
1019          for(int i = 0, cnt = 1; i < codes.length; i += stepBytecode(codes,i), cnt++) {
1020            p.append(" " + i + " " + cnt + "\t");
1021            p.append(toString(codes[i])+" "+getOperands(codes, i));
1022            p.append("\n");
1023          }
1024        }
1025    
1026    
1027    }