Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

ByteCode.java

00001 package ca.mcgill.sable.soot.coffi;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Jimple, a 3-address code Java(TM) bytecode representation.        *
00005  * Copyright (C) 1997, 1998 Raja Vallee-Rai (kor@sable.mcgill.ca)    *
00006  * All rights reserved.                                              *
00007  *                                                                   *
00008  * This work was done as a project of the Sable Research Group,      *
00009  * School of Computer Science, McGill University, Canada             *
00010  * (http://www.sable.mcgill.ca/).  It is understood that any         *
00011  * modification not identified as such is not covered by the         *
00012  * preceding statement.                                              *
00013  *                                                                   *
00014  * This work is free software; you can redistribute it and/or        *
00015  * modify it under the terms of the GNU Library General Public       *
00016  * License as published by the Free Software Foundation; either      *
00017  * version 2 of the License, or (at your option) any later version.  *
00018  *                                                                   *
00019  * This work is distributed in the hope that it will be useful,      *
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00022  * Library General Public License for more details.                  *
00023  *                                                                   *
00024  * You should have received a copy of the GNU Library General Public *
00025  * License along with this library; if not, write to the             *
00026  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00027  * Boston, MA  02111-1307, USA.                                      *
00028  *                                                                   *
00029  * Java is a trademark of Sun Microsystems, Inc.                     *
00030  *                                                                   *
00031  * To submit a bug report, send a comment, or get the latest news on *
00032  * this project and other Sable Research Group projects, please      *
00033  * visit the web site: http://www.sable.mcgill.ca/                   *
00034  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00035 
00036 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00037  * Coffi, a bytecode parser for the Java(TM) language.               *
00038  * Copyright (C) 1996, 1997 Clark Verbrugge (clump@sable.mcgill.ca). *
00039  * All rights reserved.                                              *
00040  *                                                                   *
00041  * This work was done as a project of the Sable Research Group,      *
00042  * School of Computer Science, McGill University, Canada             *
00043  * (http://www.sable.mcgill.ca/).  It is understood that any         *
00044  * modification not identified as such is not covered by the         *
00045  * preceding statement.                                              *
00046  *                                                                   *
00047  * This work is free software; you can redistribute it and/or        *
00048  * modify it under the terms of the GNU Library General Public       *
00049  * License as published by the Free Software Foundation; either      *
00050  * version 2 of the License, or (at your option) any later version.  *
00051  *                                                                   *
00052  * This work is distributed in the hope that it will be useful,      *
00053  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00054  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00055  * Library General Public License for more details.                  *
00056  *                                                                   *
00057  * You should have received a copy of the GNU Library General Public *
00058  * License along with this library; if not, write to the             *
00059  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00060  * Boston, MA  02111-1307, USA.                                      *
00061  *                                                                   *
00062  * Java is a trademark of Sun Microsystems, Inc.                     *
00063  *                                                                   *
00064  * To submit a bug report, send a comment, or get the latest news on *
00065  * this project and other Sable Research Group projects, please      *
00066  * visit the web site: http://www.sable.mcgill.ca/                   *
00067  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00068 
00069 /*
00070  Reference Version
00071  -----------------
00072  This is the latest official version on which this file is based.
00073  The reference version is: $CoffiVersion: 1.1 $
00074                            $SootVersion: 1.beta.4 $
00075 
00076  Change History
00077  --------------
00078  A) Notes:
00079 
00080  Please use the following template.  Most recent changes should
00081  appear at the top of the list.
00082 
00083  - Modified on [date (March 1, 1900)] by [name]. [(*) if appropriate]
00084    [description of modification].
00085 
00086  Any Modification flagged with "(*)" was done as a project of the
00087  Sable Research Group, School of Computer Science,
00088  McGill University, Canada (http://www.sable.mcgill.ca/).
00089 
00090  You should add your copyright, using the following template, at
00091  the top of this file, along with other copyrights.
00092 
00093  *                                                                   *
00094  * Modifications by [name] are                                       *
00095  * Copyright (C) [year(s)] [your name (or company)].  All rights     *
00096  * reserved.                                                         *
00097  *                                                                   *
00098 
00099  B) Changes:
00100 
00101  - Modified on November 2, 1998 by Raja Vallee-Rai (kor@sable.mcgill.ca) (*)
00102    Repackaged all source files and performed extensive modifications.
00103    First initial release of Soot.
00104 
00105  - Modified on 28-Aug-1998 by Raja Vallee-Rai (kor@sable.mcgill.ca). (*)
00106    Fixed the wide instructions.
00107 
00108  - Modified on 15-Jun-1998 by Raja Vallee-Rai (kor@sable.mcgill.ca). (*)
00109    First internal release (Version 0.1).
00110 */
00111 
00112 /** Procedural code for parsing and otherwise handling bytecode.
00113  * @author Clark Verbrugge
00114  */
00115 class ByteCode {
00116 
00117    public static final int NOP = 0;
00118    public static final int ACONST_NULL = 1;
00119    public static final int ICONST_M1 = 2;
00120    public static final int ICONST_0 = 3;
00121    public static final int ICONST_1 = 4;
00122    public static final int ICONST_2 = 5;
00123    public static final int ICONST_3 = 6;
00124    public static final int ICONST_4 = 7;
00125    public static final int ICONST_5 = 8;
00126    public static final int LCONST_0 = 9;
00127    public static final int LCONST_1 = 10;
00128    public static final int FCONST_0 = 11;
00129    public static final int FCONST_1 = 12;
00130    public static final int FCONST_2 = 13;
00131    public static final int DCONST_0 = 14;
00132    public static final int DCONST_1 = 15;
00133    public static final int BIPUSH = 16;
00134    public static final int SIPUSH = 17;
00135    public static final int LDC1 = 18;
00136    public static final int LDC2 = 19;
00137    public static final int LDC2W = 20;
00138    public static final int ILOAD = 21;
00139    public static final int LLOAD = 22;
00140    public static final int FLOAD = 23;
00141    public static final int DLOAD = 24;
00142    public static final int ALOAD = 25;
00143    public static final int ILOAD_0 = 26;
00144    public static final int ILOAD_1 = 27;
00145    public static final int ILOAD_2 = 28;
00146    public static final int ILOAD_3 = 29;
00147    public static final int LLOAD_0 = 30;
00148    public static final int LLOAD_1 = 31;
00149    public static final int LLOAD_2 = 32;
00150    public static final int LLOAD_3 = 33;
00151    public static final int FLOAD_0 = 34;
00152    public static final int FLOAD_1 = 35;
00153    public static final int FLOAD_2 = 36;
00154    public static final int FLOAD_3 = 37;
00155    public static final int DLOAD_0 = 38;
00156    public static final int DLOAD_1 = 39;
00157    public static final int DLOAD_2 = 40;
00158    public static final int DLOAD_3 = 41;
00159    public static final int ALOAD_0 = 42;
00160    public static final int ALOAD_1 = 43;
00161    public static final int ALOAD_2 = 44;
00162    public static final int ALOAD_3 = 45;
00163    public static final int IALOAD = 46;
00164    public static final int LALOAD = 47;
00165    public static final int FALOAD = 48;
00166    public static final int DALOAD = 49;
00167    public static final int AALOAD = 50;
00168    public static final int BALOAD = 51;
00169    public static final int CALOAD = 52;
00170    public static final int SALOAD = 53;
00171    public static final int ISTORE = 54;
00172    public static final int LSTORE = 55;
00173    public static final int FSTORE = 56;
00174    public static final int DSTORE = 57;
00175    public static final int ASTORE = 58;
00176    public static final int ISTORE_0 = 59;
00177    public static final int ISTORE_1 = 60;
00178    public static final int ISTORE_2 = 61;
00179    public static final int ISTORE_3 = 62;
00180    public static final int LSTORE_0 = 63;
00181    public static final int LSTORE_1 = 64;
00182    public static final int LSTORE_2 = 65;
00183    public static final int LSTORE_3 = 66;
00184    public static final int FSTORE_0 = 67;
00185    public static final int FSTORE_1 = 68;
00186    public static final int FSTORE_2 = 69;
00187    public static final int FSTORE_3 = 70;
00188    public static final int DSTORE_0 = 71;
00189    public static final int DSTORE_1 = 72;
00190    public static final int DSTORE_2 = 73;
00191    public static final int DSTORE_3 = 74;
00192    public static final int ASTORE_0 = 75;
00193    public static final int ASTORE_1 = 76;
00194    public static final int ASTORE_2 = 77;
00195    public static final int ASTORE_3 = 78;
00196    public static final int IASTORE = 79;
00197    public static final int LASTORE = 80;
00198    public static final int FASTORE = 81;
00199    public static final int DASTORE = 82;
00200    public static final int AASTORE = 83;
00201    public static final int BASTORE = 84;
00202    public static final int CASTORE = 85;
00203    public static final int SASTORE = 86;
00204    public static final int POP = 87;
00205    public static final int POP2 = 88;
00206    public static final int DUP = 89;
00207    public static final int DUP_X1 = 90;
00208    public static final int DUP_X2 = 91;
00209    public static final int DUP2 = 92;
00210    public static final int DUP2_X1 = 93;
00211    public static final int DUP2_X2 = 94;
00212    public static final int SWAP = 95;
00213    public static final int IADD = 96;
00214    public static final int LADD = 97;
00215    public static final int FADD = 98;
00216    public static final int DADD = 99;
00217    public static final int ISUB = 100;
00218    public static final int LSUB = 101;
00219    public static final int FSUB = 102;
00220    public static final int DSUB = 103;
00221    public static final int IMUL = 104;
00222    public static final int LMUL = 105;
00223    public static final int FMUL = 106;
00224    public static final int DMUL = 107;
00225    public static final int IDIV = 108;
00226    public static final int LDIV = 109;
00227    public static final int FDIV = 110;
00228    public static final int DDIV = 111;
00229    public static final int IREM = 112;
00230    public static final int LREM = 113;
00231    public static final int FREM = 114;
00232    public static final int DREM = 115;
00233    public static final int INEG = 116;
00234    public static final int LNEG = 117;
00235    public static final int FNEG = 118;
00236    public static final int DNEG = 119;
00237    public static final int ISHL = 120;
00238    public static final int LSHL = 121;
00239    public static final int ISHR = 122;
00240    public static final int LSHR = 123;
00241    public static final int IUSHR = 124;
00242    public static final int LUSHR = 125;
00243    public static final int IAND = 126;
00244    public static final int LAND = 127;
00245    public static final int IOR = 128;
00246    public static final int LOR = 129;
00247    public static final int IXOR = 130;
00248    public static final int LXOR = 131;
00249    public static final int IINC = 132;
00250    public static final int I2L = 133;
00251    public static final int I2F = 134;
00252    public static final int I2D = 135;
00253    public static final int L2I = 136;
00254    public static final int L2F = 137;
00255    public static final int L2D = 138;
00256    public static final int F2I = 139;
00257    public static final int F2L = 140;
00258    public static final int F2D = 141;
00259    public static final int D2I = 142;
00260    public static final int D2L = 143;
00261    public static final int D2F = 144;
00262    public static final int INT2BYTE = 145;
00263    public static final int INT2CHAR = 146;
00264    public static final int INT2SHORT = 147;
00265    public static final int LCMP = 148;
00266    public static final int FCMPL = 149;
00267    public static final int FCMPG = 150;
00268    public static final int DCMPL = 151;
00269    public static final int DCMPG = 152;
00270    public static final int IFEQ = 153;
00271    public static final int IFNE = 154;
00272    public static final int IFLT = 155;
00273    public static final int IFGE = 156;
00274    public static final int IFGT = 157;
00275    public static final int IFLE = 158;
00276    public static final int IF_ICMPEQ = 159;
00277    public static final int IF_ICMPNE = 160;
00278    public static final int IF_ICMPLT = 161;
00279    public static final int IF_ICMPGE = 162;
00280    public static final int IF_ICMPGT = 163;
00281    public static final int IF_ICMPLE = 164;
00282    public static final int IF_ACMPEQ = 165;
00283    public static final int IF_ACMPNE = 166;
00284    public static final int GOTO = 167;
00285    public static final int JSR = 168;
00286    public static final int RET = 169;
00287    public static final int TABLESWITCH = 170;
00288    public static final int LOOKUPSWITCH = 171;
00289    public static final int IRETURN = 172;
00290    public static final int LRETURN = 173;
00291    public static final int FRETURN = 174;
00292    public static final int DRETURN = 175;
00293    public static final int ARETURN = 176;
00294    public static final int RETURN = 177;
00295    public static final int GETSTATIC = 178;
00296    public static final int PUTSTATIC = 179;
00297    public static final int GETFIELD = 180;
00298    public static final int PUTFIELD = 181;
00299    public static final int INVOKEVIRTUAL = 182;
00300    public static final int INVOKENONVIRTUAL = 183;
00301    public static final int INVOKESTATIC = 184;
00302    public static final int INVOKEINTERFACE = 185;
00303    /*    public static final int  = 186;*/
00304    public static final int NEW = 187;
00305    public static final int NEWARRAY = 188;
00306    public static final int ANEWARRAY = 189;
00307    public static final int ARRAYLENGTH = 190;
00308    public static final int ATHROW = 191;
00309    public static final int CHECKCAST = 192;
00310    public static final int INSTANCEOF = 193;
00311    public static final int MONITORENTER = 194;
00312    public static final int MONITOREXIT = 195;
00313    public static final int WIDE = 196;
00314    public static final int MULTIANEWARRAY = 197;
00315    public static final int IFNULL = 198;
00316    public static final int IFNONNULL = 199;
00317    public static final int GOTO_W = 200;
00318    public static final int JSR_W = 201;
00319    public static final int BREAKPOINT = 202;
00320    /*    public static final int  = 203;
00321         public static final int  = 204;
00322         public static final int  = 205;
00323         public static final int  = 206;
00324         public static final int  = 207;
00325         public static final int  = 208;*/
00326    public static final int RET_W = 209;
00327    /*    public static final int  = 210;
00328         public static final int  = 211;
00329         public static final int  = 212;
00330         public static final int  = 213;
00331         public static final int  = 214;
00332         public static final int  = 215;
00333         public static final int  = 216;
00334         public static final int  = 217;
00335         public static final int  = 218;
00336         public static final int  = 219;
00337         public static final int  = 220;
00338         public static final int  = 221;
00339         public static final int  = 222;
00340         public static final int  = 223;
00341         public static final int  = 224;
00342         public static final int  = 225;
00343         public static final int  = 226;
00344         public static final int  = 227;
00345         public static final int  = 228;
00346         public static final int  = 229;
00347         public static final int  = 230;
00348         public static final int  = 231;
00349         public static final int  = 232;
00350         public static final int  = 233;
00351         public static final int  = 234;
00352         public static final int  = 235;
00353         public static final int  = 236;
00354         public static final int  = 237;
00355         public static final int  = 238;
00356         public static final int  = 239;
00357         public static final int  = 240;
00358         public static final int  = 241;
00359         public static final int  = 242;
00360         public static final int  = 243;
00361         public static final int  = 244;
00362         public static final int  = 245;
00363         public static final int  = 246;
00364         public static final int  = 247;
00365         public static final int  = 248;
00366         public static final int  = 249;
00367         public static final int  = 250;
00368         public static final int  = 251;
00369         public static final int  = 252;
00370         public static final int  = 253;
00371         public static final int  = 254;
00372         public static final int  = 255;*/
00373 
00374    private int icount;
00375    private Instruction instructions[];
00376 
00377    /** Constructor---does nothing. */
00378    ByteCode() {  }   
00379    /** Given a list of Instructions, this method converts all offsets
00380     * to pointers.
00381     * @param insts list of instructions; labels must be accurate.
00382     * @see Instruction#offsetToPointer
00383     * @see ClassFile#parseMethod
00384     * @see ClassFile#relabel
00385     */
00386    public void build(Instruction insts) {
00387       Instruction i,j;
00388       attribute_info ai;
00389       Code_attribute ca;
00390 
00391       i = insts;
00392       // find out how many instructions that is
00393       icount = 0;
00394       while (i != null) {
00395          icount++;
00396          i = i.next;
00397       }
00398       // build array of instructions
00399       if (icount>0) {
00400          instructions = new Instruction[icount];
00401          // and put the instructions into the array
00402          // identify targets of branch instructions. Why build an array
00403          // when we already have a list? In order to be able to locate
00404          // an instruction given its numeric label quickly.
00405          int k;
00406          k = 0;
00407          i = insts;
00408          while (i != null) {
00409             instructions[k] = i;
00410             k++;
00411             i = i.next;
00412          }
00413 
00414          // now convert all offsets to pointers
00415          i = insts;
00416          while (i!=null) {
00417             i.offsetToPointer(this);
00418             i = i.next;
00419          }
00420       }
00421    }   
00422    /** Main entry point for disassembling bytecode into Instructions; this
00423     * method converts the given single bytecode into an Instruction (with
00424     * label set to index).
00425     * @param bc complete array of bytecode.
00426     * @param index offset within bc of the bytecode to parse.
00427     * @return a single Instruction object; note that Instruction references will
00428     * not be filled in (use build to post-process).
00429     * @see ClassFile#parseMethod
00430     * @see Instruction#parse
00431     * @see ByteCode#build
00432     */
00433    public Instruction disassemble_bytecode(byte bc[],int index) {
00434       // returns a string representing the disassembly of the
00435       // bytecode at the given index
00436       byte b = bc[index];
00437       boolean isWide = false;
00438       Instruction i;
00439       int x;
00440 
00441       x = ((int)b)&0xff;
00442 
00443       switch(x) {
00444       case BIPUSH:
00445          i = (Instruction)new Instruction_Bipush();
00446          break;
00447       case SIPUSH:
00448          i = (Instruction)new Instruction_Sipush();
00449          break;
00450       case LDC1:
00451          i = (Instruction)new Instruction_Ldc1();
00452          break;
00453       case LDC2:
00454          i = (Instruction)new Instruction_Ldc2();
00455          break;
00456       case LDC2W:
00457          i = (Instruction)new Instruction_Ldc2w();
00458          break;
00459       case ACONST_NULL:
00460          i = (Instruction)new Instruction_Aconst_null();
00461          break;
00462       case ICONST_M1:
00463          i = (Instruction)new Instruction_Iconst_m1();
00464          break;
00465       case ICONST_0:
00466          i = (Instruction)new Instruction_Iconst_0();
00467          break;
00468       case ICONST_1:
00469          i = (Instruction)new Instruction_Iconst_1();
00470          break;
00471       case ICONST_2:
00472          i = (Instruction)new Instruction_Iconst_2();
00473          break;
00474       case ICONST_3:
00475          i = (Instruction)new Instruction_Iconst_3();
00476          break;
00477       case ICONST_4:
00478          i = (Instruction)new Instruction_Iconst_4();
00479          break;
00480       case ICONST_5:
00481          i = (Instruction)new Instruction_Iconst_5();
00482          break;
00483       case LCONST_0:
00484          i = (Instruction)new Instruction_Lconst_0();
00485          break;
00486       case LCONST_1:
00487          i = (Instruction)new Instruction_Lconst_1();
00488          break;
00489       case FCONST_0:
00490          i = (Instruction)new Instruction_Fconst_0();
00491          break;
00492       case FCONST_1:
00493          i = (Instruction)new Instruction_Fconst_1();
00494          break;
00495       case FCONST_2:
00496          i = (Instruction)new Instruction_Fconst_2();
00497          break;
00498       case DCONST_0:
00499          i = (Instruction)new Instruction_Dconst_0();
00500          break;
00501       case DCONST_1:
00502          i = (Instruction)new Instruction_Dconst_1();
00503          break;
00504       case ILOAD:
00505          i = (Instruction)new Instruction_Iload();
00506          break;
00507       case ILOAD_0:
00508          i = (Instruction)new Instruction_Iload_0();
00509          break;
00510       case ILOAD_1:
00511          i = (Instruction)new Instruction_Iload_1();
00512          break;
00513       case ILOAD_2:
00514          i = (Instruction)new Instruction_Iload_2();
00515          break;
00516       case ILOAD_3:
00517          i = (Instruction)new Instruction_Iload_3();
00518          break;
00519       case LLOAD:
00520          i = (Instruction)new Instruction_Lload();
00521          break;
00522       case LLOAD_0:
00523          i = (Instruction)new Instruction_Lload_0();
00524          break;
00525       case LLOAD_1:
00526          i = (Instruction)new Instruction_Lload_1();
00527          break;
00528       case LLOAD_2:
00529          i = (Instruction)new Instruction_Lload_2();
00530          break;
00531       case LLOAD_3:
00532          i = (Instruction)new Instruction_Lload_3();
00533          break;
00534       case FLOAD:
00535          i = (Instruction)new Instruction_Fload();
00536          break;
00537       case FLOAD_0:
00538          i = (Instruction)new Instruction_Fload_0();
00539          break;
00540       case FLOAD_1:
00541          i = (Instruction)new Instruction_Fload_1();
00542          break;
00543       case FLOAD_2:
00544          i = (Instruction)new Instruction_Fload_2();
00545          break;
00546       case FLOAD_3:
00547          i = (Instruction)new Instruction_Fload_3();
00548          break;
00549       case DLOAD:
00550          i = (Instruction)new Instruction_Dload();
00551          break;
00552       case DLOAD_0:
00553          i = (Instruction)new Instruction_Dload_0();
00554          break;
00555       case DLOAD_1:
00556          i = (Instruction)new Instruction_Dload_1();
00557          break;
00558       case DLOAD_2:
00559          i = (Instruction)new Instruction_Dload_2();
00560          break;
00561       case DLOAD_3:
00562          i = (Instruction)new Instruction_Dload_3();
00563          break;
00564       case ALOAD:
00565          i = (Instruction)new Instruction_Aload();
00566          break;
00567       case ALOAD_0:
00568          i = (Instruction)new Instruction_Aload_0();
00569          break;
00570       case ALOAD_1:
00571          i = (Instruction)new Instruction_Aload_1();
00572          break;
00573       case ALOAD_2:
00574          i = (Instruction)new Instruction_Aload_2();
00575          break;
00576       case ALOAD_3:
00577          i = (Instruction)new Instruction_Aload_3();
00578          break;
00579       case ISTORE:
00580          i = (Instruction)new Instruction_Istore();
00581          break;
00582       case ISTORE_0:
00583          i = (Instruction)new Instruction_Istore_0();
00584          break;
00585       case ISTORE_1:
00586          i = (Instruction)new Instruction_Istore_1();
00587          break;
00588       case ISTORE_2:
00589          i = (Instruction)new Instruction_Istore_2();
00590          break;
00591       case ISTORE_3:
00592          i = (Instruction)new Instruction_Istore_3();
00593          break;
00594       case LSTORE:
00595          i = (Instruction)new Instruction_Lstore();
00596          break;
00597       case LSTORE_0:
00598          i = (Instruction)new Instruction_Lstore_0();
00599          break;
00600       case LSTORE_1:
00601          i = (Instruction)new Instruction_Lstore_1();
00602          break;
00603       case LSTORE_2:
00604          i = (Instruction)new Instruction_Lstore_2();
00605          break;
00606       case LSTORE_3:
00607          i = (Instruction)new Instruction_Lstore_3();
00608          break;
00609       case FSTORE:
00610          i = (Instruction)new Instruction_Fstore();
00611          break;
00612       case FSTORE_0:
00613          i = (Instruction)new Instruction_Fstore_0();
00614          break;
00615       case FSTORE_1:
00616          i = (Instruction)new Instruction_Fstore_1();
00617          break;
00618       case FSTORE_2:
00619          i = (Instruction)new Instruction_Fstore_2();
00620          break;
00621       case FSTORE_3:
00622          i = (Instruction)new Instruction_Fstore_3();
00623          break;
00624       case DSTORE:
00625          i = (Instruction)new Instruction_Dstore();
00626          break;
00627       case DSTORE_0:
00628          i = (Instruction)new Instruction_Dstore_0();
00629          break;
00630       case DSTORE_1:
00631          i = (Instruction)new Instruction_Dstore_1();
00632          break;
00633       case DSTORE_2:
00634          i = (Instruction)new Instruction_Dstore_2();
00635          break;
00636       case DSTORE_3:
00637          i = (Instruction)new Instruction_Dstore_3();
00638          break;
00639       case ASTORE:
00640          i = (Instruction)new Instruction_Astore();
00641          break;
00642       case ASTORE_0:
00643          i = (Instruction)new Instruction_Astore_0();
00644          break;
00645       case ASTORE_1:
00646          i = (Instruction)new Instruction_Astore_1();
00647          break;
00648       case ASTORE_2:
00649          i = (Instruction)new Instruction_Astore_2();
00650          break;
00651       case ASTORE_3:
00652          i = (Instruction)new Instruction_Astore_3();
00653          break;
00654       case IINC:
00655          i = (Instruction)new Instruction_Iinc();
00656          break;
00657       case WIDE:
00658       {
00659          int nextIndex = ((int) bc[index+1]) & 0xff;
00660 
00661          switch(nextIndex)
00662          {
00663             case ILOAD:
00664                 i = new Instruction_Iload();
00665                 break;
00666 
00667             case FLOAD:
00668                 i = new Instruction_Fload();
00669                 break;
00670 
00671             case ALOAD:
00672                 i = new Instruction_Aload();
00673                 break;
00674 
00675             case LLOAD:
00676                 i = new Instruction_Lload();
00677                 break;
00678 
00679             case ISTORE:
00680                 i = new Instruction_Istore();
00681                 break;
00682 
00683             case FSTORE:
00684                 i = new Instruction_Fstore();
00685                 break;
00686 
00687             case ASTORE:
00688                 i = new Instruction_Astore();
00689                 break;
00690 
00691             case LSTORE:
00692                 i = new Instruction_Lstore();
00693                 break;
00694 
00695             case RET:
00696                 i = new Instruction_Ret();
00697                 break;
00698 
00699             case IINC:
00700                 i = new Instruction_Iinc();
00701                 break;
00702 
00703             default:
00704                 throw new RuntimeException("invalid wide instruction: " + nextIndex);
00705          }
00706 
00707          ((Instruction_bytevar) i).isWide = true;
00708          isWide = true;
00709       }
00710 
00711         break;
00712 
00713       case NEWARRAY:
00714          i = (Instruction)new Instruction_Newarray();
00715          break;
00716       case ANEWARRAY:
00717          i = (Instruction)new Instruction_Anewarray();
00718          break;
00719       case MULTIANEWARRAY:
00720          i = (Instruction)new Instruction_Multianewarray();
00721          break;
00722       case ARRAYLENGTH:
00723          i = (Instruction)new Instruction_Arraylength();
00724          break;
00725       case IALOAD:
00726          i = (Instruction)new Instruction_Iaload();
00727          break;
00728       case LALOAD:
00729          i = (Instruction)new Instruction_Laload();
00730          break;
00731       case FALOAD:
00732          i = (Instruction)new Instruction_Faload();
00733          break;
00734       case DALOAD:
00735          i = (Instruction)new Instruction_Daload();
00736          break;
00737       case AALOAD:
00738          i = (Instruction)new Instruction_Aaload();
00739          break;
00740       case BALOAD:
00741          i = (Instruction)new Instruction_Baload();
00742          break;
00743       case CALOAD:
00744          i = (Instruction)new Instruction_Caload();
00745          break;
00746       case SALOAD:
00747          i = (Instruction)new Instruction_Saload();
00748          break;
00749       case IASTORE:
00750          i = (Instruction)new Instruction_Iastore();
00751          break;
00752       case LASTORE:
00753          i = (Instruction)new Instruction_Lastore();
00754          break;
00755       case FASTORE:
00756          i = (Instruction)new Instruction_Fastore();
00757          break;
00758       case DASTORE:
00759          i = (Instruction)new Instruction_Dastore();
00760          break;
00761       case AASTORE:
00762          i = (Instruction)new Instruction_Aastore();
00763          break;
00764       case BASTORE:
00765          i = (Instruction)new Instruction_Bastore();
00766          break;
00767       case CASTORE:
00768          i = (Instruction)new Instruction_Castore();
00769          break;
00770       case SASTORE:
00771          i = (Instruction)new Instruction_Sastore();
00772          break;
00773       case NOP:
00774          i = (Instruction)new Instruction_Nop();
00775          break;
00776       case POP:
00777          i = (Instruction)new Instruction_Pop();
00778          break;
00779       case POP2:
00780          i = (Instruction)new Instruction_Pop2();
00781          break;
00782       case DUP:
00783          i = (Instruction)new Instruction_Dup();
00784          break;
00785       case DUP2:
00786          i = (Instruction)new Instruction_Dup2();
00787          break;
00788       case DUP_X1:
00789          i = (Instruction)new Instruction_Dup_x1();
00790          break;
00791       case DUP_X2:
00792          i = (Instruction)new Instruction_Dup_x2();
00793          break;
00794       case DUP2_X1:
00795          i = (Instruction)new Instruction_Dup2_x1();
00796          break;
00797       case DUP2_X2:
00798          i = (Instruction)new Instruction_Dup2_x2();
00799          break;
00800       case SWAP:
00801          i = (Instruction)new Instruction_Swap();
00802          break;
00803       case IADD:
00804          i = (Instruction)new Instruction_Iadd();
00805          break;
00806       case LADD:
00807          i = (Instruction)new Instruction_Ladd();
00808          break;
00809       case FADD:
00810          i = (Instruction)new Instruction_Fadd();
00811          break;
00812       case DADD:
00813          i = (Instruction)new Instruction_Dadd();
00814          break;
00815       case ISUB:
00816          i = (Instruction)new Instruction_Isub();
00817          break;
00818       case LSUB:
00819          i = (Instruction)new Instruction_Lsub();
00820          break;
00821       case FSUB:
00822          i = (Instruction)new Instruction_Fsub();
00823          break;
00824       case DSUB:
00825          i = (Instruction)new Instruction_Dsub();
00826          break;
00827       case IMUL:
00828          i = (Instruction)new Instruction_Imul();
00829          break;
00830       case LMUL:
00831          i = (Instruction)new Instruction_Lmul();
00832          break;
00833       case FMUL:
00834          i = (Instruction)new Instruction_Fmul();
00835          break;
00836       case DMUL:
00837          i = (Instruction)new Instruction_Dmul();
00838          break;
00839       case IDIV:
00840          i = (Instruction)new Instruction_Idiv();
00841          break;
00842       case LDIV:
00843          i = (Instruction)new Instruction_Ldiv();
00844          break;
00845       case FDIV:
00846          i = (Instruction)new Instruction_Fdiv();
00847          break;
00848       case DDIV:
00849          i = (Instruction)new Instruction_Ddiv();
00850          break;
00851       case IREM:
00852          i = (Instruction)new Instruction_Irem();
00853          break;
00854       case LREM:
00855          i = (Instruction)new Instruction_Lrem();
00856          break;
00857       case FREM:
00858          i = (Instruction)new Instruction_Frem();
00859          break;
00860       case DREM:
00861          i = (Instruction)new Instruction_Drem();
00862          break;
00863       case INEG:
00864          i = (Instruction)new Instruction_Ineg();
00865          break;
00866       case LNEG:
00867          i = (Instruction)new Instruction_Lneg();
00868          break;
00869       case FNEG:
00870          i = (Instruction)new Instruction_Fneg();
00871          break;
00872       case DNEG:
00873          i = (Instruction)new Instruction_Dneg();
00874          break;
00875       case ISHL:
00876          i = (Instruction)new Instruction_Ishl();
00877          break;
00878       case ISHR:
00879          i = (Instruction)new Instruction_Ishr();
00880          break;
00881       case IUSHR:
00882          i = (Instruction)new Instruction_Iushr();
00883          break;
00884       case LSHL:
00885          i = (Instruction)new Instruction_Lshl();
00886          break;
00887       case LSHR:
00888          i = (Instruction)new Instruction_Lshr();
00889          break;
00890       case LUSHR:
00891          i = (Instruction)new Instruction_Lushr();
00892          break;
00893       case IAND:
00894          i = (Instruction)new Instruction_Iand();
00895          break;
00896       case LAND:
00897          i = (Instruction)new Instruction_Land();
00898          break;
00899       case IOR:
00900          i = (Instruction)new Instruction_Ior();
00901          break;
00902       case LOR:
00903          i = (Instruction)new Instruction_Lor();
00904          break;
00905       case IXOR:
00906          i = (Instruction)new Instruction_Ixor();
00907          break;
00908       case LXOR:
00909          i = (Instruction)new Instruction_Lxor();
00910          break;
00911       case I2L:
00912          i = (Instruction)new Instruction_I2l();
00913          break;
00914       case I2F:
00915          i = (Instruction)new Instruction_I2f();
00916          break;
00917       case I2D:
00918          i = (Instruction)new Instruction_I2d();
00919          break;
00920       case L2I:
00921          i = (Instruction)new Instruction_L2i();
00922          break;
00923       case L2F:
00924          i = (Instruction)new Instruction_L2f();
00925          break;
00926       case L2D:
00927          i = (Instruction)new Instruction_L2d();
00928          break;
00929       case F2I:
00930          i = (Instruction)new Instruction_F2i();
00931          break;
00932       case F2L:
00933          i = (Instruction)new Instruction_F2l();
00934          break;
00935       case F2D:
00936          i = (Instruction)new Instruction_F2d();
00937          break;
00938       case D2I:
00939          i = (Instruction)new Instruction_D2i();
00940          break;
00941       case D2L:
00942          i = (Instruction)new Instruction_D2l();
00943          break;
00944       case D2F:
00945          i = (Instruction)new Instruction_D2f();
00946          break;
00947       case INT2BYTE:
00948          i = (Instruction)new Instruction_Int2byte();
00949          break;
00950       case INT2CHAR:
00951          i = (Instruction)new Instruction_Int2char();
00952          break;
00953       case INT2SHORT:
00954          i = (Instruction)new Instruction_Int2short();
00955          break;
00956       case IFEQ:
00957          i = (Instruction)new Instruction_Ifeq();
00958          break;
00959       case IFNULL:
00960          i = (Instruction)new Instruction_Ifnull();
00961          break;
00962       case IFLT:
00963          i = (Instruction)new Instruction_Iflt();
00964          break;
00965       case IFLE:
00966          i = (Instruction)new Instruction_Ifle();
00967          break;
00968       case IFNE:
00969          i = (Instruction)new Instruction_Ifne();
00970          break;
00971       case IFNONNULL:
00972          i = (Instruction)new Instruction_Ifnonnull();
00973          break;
00974       case IFGT:
00975          i = (Instruction)new Instruction_Ifgt();
00976          break;
00977       case IFGE:
00978          i = (Instruction)new Instruction_Ifge();
00979          break;
00980       case IF_ICMPEQ:
00981          i = (Instruction)new Instruction_If_icmpeq();
00982          break;
00983       case IF_ICMPLT:
00984          i = (Instruction)new Instruction_If_icmplt();
00985          break;
00986       case IF_ICMPLE:
00987          i = (Instruction)new Instruction_If_icmple();
00988          break;
00989       case IF_ICMPNE:
00990          i = (Instruction)new Instruction_If_icmpne();
00991          break;
00992       case IF_ICMPGT:
00993          i = (Instruction)new Instruction_If_icmpgt();
00994          break;
00995       case IF_ICMPGE:
00996          i = (Instruction)new Instruction_If_icmpge();
00997          break;
00998       case LCMP:
00999          i = (Instruction)new Instruction_Lcmp();
01000          break;
01001       case FCMPL:
01002          i = (Instruction)new Instruction_Fcmpl();
01003          break;
01004       case FCMPG:
01005          i = (Instruction)new Instruction_Fcmpg();
01006          break;
01007       case DCMPL:
01008          i = (Instruction)new Instruction_Dcmpl();
01009          break;
01010       case DCMPG:
01011          i = (Instruction)new Instruction_Dcmpg();
01012          break;
01013       case IF_ACMPEQ:
01014          i = (Instruction)new Instruction_If_acmpeq();
01015          break;
01016       case IF_ACMPNE:
01017          i = (Instruction)new Instruction_If_acmpne();
01018          break;
01019       case GOTO:
01020          i = (Instruction)new Instruction_Goto();
01021          break;
01022       case GOTO_W:
01023          i = (Instruction)new Instruction_Goto_w();
01024          break;
01025       case JSR:
01026          i = (Instruction)new Instruction_Jsr();
01027          break;
01028       case JSR_W:
01029          i = (Instruction)new Instruction_Jsr_w();
01030          break;
01031       case RET:
01032          i = (Instruction)new Instruction_Ret();
01033          break;
01034       case RET_W:
01035          i = (Instruction)new Instruction_Ret_w();
01036          break;
01037       case RETURN:
01038          i = (Instruction)new Instruction_Return();
01039          break;
01040       case IRETURN:
01041          i = (Instruction)new Instruction_Ireturn();
01042          break;
01043       case LRETURN:
01044          i = (Instruction)new Instruction_Lreturn();
01045          break;
01046       case FRETURN:
01047          i = (Instruction)new Instruction_Freturn();
01048          break;
01049       case DRETURN:
01050          i = (Instruction)new Instruction_Dreturn();
01051          break;
01052       case ARETURN:
01053          i = (Instruction)new Instruction_Areturn();
01054          break;
01055       case BREAKPOINT:
01056          i = (Instruction)new Instruction_Breakpoint();
01057          break;
01058       case TABLESWITCH:
01059          i = (Instruction)new Instruction_Tableswitch();
01060          break;
01061       case LOOKUPSWITCH:
01062          i = (Instruction)new Instruction_Lookupswitch();
01063          break;
01064       case PUTFIELD:
01065          i = (Instruction)new Instruction_Putfield();
01066          break;
01067       case GETFIELD:
01068          i = (Instruction)new Instruction_Getfield();
01069          break;
01070       case PUTSTATIC:
01071          i = (Instruction)new Instruction_Putstatic();
01072          break;
01073       case GETSTATIC:
01074          i = (Instruction)new Instruction_Getstatic();
01075          break;
01076       case INVOKEVIRTUAL:
01077          i = (Instruction)new Instruction_Invokevirtual();
01078          break;
01079       case INVOKENONVIRTUAL:
01080          i = (Instruction)new Instruction_Invokenonvirtual();
01081          break;
01082       case INVOKESTATIC:
01083          i = (Instruction)new Instruction_Invokestatic();
01084          break;
01085       case INVOKEINTERFACE:
01086          i = (Instruction)new Instruction_Invokeinterface();
01087          break;
01088       case ATHROW:
01089          i = (Instruction)new Instruction_Athrow();
01090          break;
01091       case NEW:
01092          i = (Instruction)new Instruction_New();
01093          break;
01094       case CHECKCAST:
01095          i = (Instruction)new Instruction_Checkcast();
01096          break;
01097       case INSTANCEOF:
01098          i = (Instruction)new Instruction_Instanceof();
01099          break;
01100       case MONITORENTER:
01101          i = (Instruction)new Instruction_Monitorenter();
01102          break;
01103       case MONITOREXIT:
01104          i = (Instruction)new Instruction_Monitorexit();
01105          break;
01106       default:
01107          //int j;
01108          //j = ((int)b)&0xff;
01109          //System.out.println("Unknown instruction op=" + j +
01110          //                   " at offset " + index);
01111          i = (Instruction)new Instruction_Unknown(b);
01112          break;
01113       }
01114 
01115       i.label = index;
01116 
01117       if(isWide)
01118         i.parse(bc,index+2);
01119       else
01120         i.parse(bc,index+1);
01121 
01122       return i;
01123    }   
01124    /** Locates the Instruction in the list with the given label.
01125     * @param index label of desired instruction
01126     * @return Instruction object wiht that label, or <i>null</i> if not found.
01127     */
01128    // locates the instruction with an index value of the given
01129    public Instruction locateInst(int index) {
01130       return locateInstr(index,0,icount);
01131    }   
01132    /** Performs a binary search of the instructions[] array. */
01133    private Instruction locateInstr(int index,int mini,int maxi) {
01134       int mid = (maxi-mini)/2 + mini;
01135 
01136       if (mini>maxi) return null;
01137       if (instructions[mid].label==index)
01138          return instructions[mid];
01139       if (instructions[mid].label > index)
01140          return locateInstr(index,mini,mid-1);
01141       return locateInstr(index,mid+1,maxi);
01142    }   
01143    /** Displays the code (in the form of Instructions) for the given list
01144     * of Instructions.
01145     * @param inst input list of instructions.
01146     * @param constant_pool constant pool of the ClassFile object.
01147     * @see ByteCode#showCode(Instruction, int, cp_info)
01148     */
01149    public static void showCode(Instruction inst,cp_info constant_pool[]) {
01150       showCode(inst,0,constant_pool);
01151    }   
01152    /** Displays the code (in the form of Instructions) for the given list
01153     * of Instructions.
01154     * @param inst input list of instructions.
01155     * @param startinst index of the label of the instruction at which to begin.
01156     * @param constant_pool constant pool of the ClassFile object.
01157     * @see ByteCode#showCode(Instruction, cp_info)
01158     */
01159    public static void showCode(Instruction inst,int startinst,cp_info constant_pool[]) {
01160       int i;
01161       Instruction j = inst;
01162       String pref;
01163       i = startinst;
01164       while (j!=null) {
01165          if (i>999) pref = "";
01166          else if (i>99) pref = " ";
01167          else if (i>9) pref = "  ";
01168          else pref = "   ";
01169          System.out.print(pref + i + ": ");
01170          System.out.println(j.toString(constant_pool));
01171          i = j.nextOffset(i);
01172          j = j.next;
01173       }
01174    }   
01175 }

Generated at Thu Feb 7 06:41:40 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001