1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.bcel.internal.generic;
  23 
  24 
  25 import com.sun.org.apache.bcel.internal.Constants;
  26 
  27 /**
  28  * This interface contains shareable instruction objects.
  29  *
  30  * In order to save memory you can use some instructions multiply,
  31  * since they have an immutable state and are directly derived from
  32  * Instruction.  I.e. they have no instance fields that could be
  33  * changed. Since some of these instructions like ICONST_0 occur
  34  * very frequently this can save a lot of time and space. This
  35  * feature is an adaptation of the FlyWeight design pattern, we
  36  * just use an array instead of a factory.
  37  *
  38  * The Instructions can also accessed directly under their names, so
  39  * it's possible to write il.append(Instruction.ICONST_0);
  40  *
  41  * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
  42  */
  43 public interface InstructionConstants {
  44   /** Predefined instruction objects
  45    */
  46   public static final Instruction           NOP          = new NOP();
  47   public static final Instruction           ACONST_NULL  = new ACONST_NULL();
  48   public static final Instruction           ICONST_M1    = new ICONST(-1);
  49   public static final Instruction           ICONST_0     = new ICONST(0);
  50   public static final Instruction           ICONST_1     = new ICONST(1);
  51   public static final Instruction           ICONST_2     = new ICONST(2);
  52   public static final Instruction           ICONST_3     = new ICONST(3);
  53   public static final Instruction           ICONST_4     = new ICONST(4);
  54   public static final Instruction           ICONST_5     = new ICONST(5);
  55   public static final Instruction           LCONST_0     = new LCONST(0);
  56   public static final Instruction           LCONST_1     = new LCONST(1);
  57   public static final Instruction           FCONST_0     = new FCONST(0);
  58   public static final Instruction           FCONST_1     = new FCONST(1);
  59   public static final Instruction           FCONST_2     = new FCONST(2);
  60   public static final Instruction           DCONST_0     = new DCONST(0);
  61   public static final Instruction           DCONST_1     = new DCONST(1);
  62   public static final ArrayInstruction      IALOAD       = new IALOAD();
  63   public static final ArrayInstruction      LALOAD       = new LALOAD();
  64   public static final ArrayInstruction      FALOAD       = new FALOAD();
  65   public static final ArrayInstruction      DALOAD       = new DALOAD();
  66   public static final ArrayInstruction      AALOAD       = new AALOAD();
  67   public static final ArrayInstruction      BALOAD       = new BALOAD();
  68   public static final ArrayInstruction      CALOAD       = new CALOAD();
  69   public static final ArrayInstruction      SALOAD       = new SALOAD();
  70   public static final ArrayInstruction      IASTORE      = new IASTORE();
  71   public static final ArrayInstruction      LASTORE      = new LASTORE();
  72   public static final ArrayInstruction      FASTORE      = new FASTORE();
  73   public static final ArrayInstruction      DASTORE      = new DASTORE();
  74   public static final ArrayInstruction      AASTORE      = new AASTORE();
  75   public static final ArrayInstruction      BASTORE      = new BASTORE();
  76   public static final ArrayInstruction      CASTORE      = new CASTORE();
  77   public static final ArrayInstruction      SASTORE      = new SASTORE();
  78   public static final StackInstruction      POP          = new POP();
  79   public static final StackInstruction      POP2         = new POP2();
  80   public static final StackInstruction      DUP          = new DUP();
  81   public static final StackInstruction      DUP_X1       = new DUP_X1();
  82   public static final StackInstruction      DUP_X2       = new DUP_X2();
  83   public static final StackInstruction      DUP2         = new DUP2();
  84   public static final StackInstruction      DUP2_X1      = new DUP2_X1();
  85   public static final StackInstruction      DUP2_X2      = new DUP2_X2();
  86   public static final StackInstruction      SWAP         = new SWAP();
  87   public static final ArithmeticInstruction IADD         = new IADD();
  88   public static final ArithmeticInstruction LADD         = new LADD();
  89   public static final ArithmeticInstruction FADD         = new FADD();
  90   public static final ArithmeticInstruction DADD         = new DADD();
  91   public static final ArithmeticInstruction ISUB         = new ISUB();
  92   public static final ArithmeticInstruction LSUB         = new LSUB();
  93   public static final ArithmeticInstruction FSUB         = new FSUB();
  94   public static final ArithmeticInstruction DSUB         = new DSUB();
  95   public static final ArithmeticInstruction IMUL         = new IMUL();
  96   public static final ArithmeticInstruction LMUL         = new LMUL();
  97   public static final ArithmeticInstruction FMUL         = new FMUL();
  98   public static final ArithmeticInstruction DMUL         = new DMUL();
  99   public static final ArithmeticInstruction IDIV         = new IDIV();
 100   public static final ArithmeticInstruction LDIV         = new LDIV();
 101   public static final ArithmeticInstruction FDIV         = new FDIV();
 102   public static final ArithmeticInstruction DDIV         = new DDIV();
 103   public static final ArithmeticInstruction IREM         = new IREM();
 104   public static final ArithmeticInstruction LREM         = new LREM();
 105   public static final ArithmeticInstruction FREM         = new FREM();
 106   public static final ArithmeticInstruction DREM         = new DREM();
 107   public static final ArithmeticInstruction INEG         = new INEG();
 108   public static final ArithmeticInstruction LNEG         = new LNEG();
 109   public static final ArithmeticInstruction FNEG         = new FNEG();
 110   public static final ArithmeticInstruction DNEG         = new DNEG();
 111   public static final ArithmeticInstruction ISHL         = new ISHL();
 112   public static final ArithmeticInstruction LSHL         = new LSHL();
 113   public static final ArithmeticInstruction ISHR         = new ISHR();
 114   public static final ArithmeticInstruction LSHR         = new LSHR();
 115   public static final ArithmeticInstruction IUSHR        = new IUSHR();
 116   public static final ArithmeticInstruction LUSHR        = new LUSHR();
 117   public static final ArithmeticInstruction IAND         = new IAND();
 118   public static final ArithmeticInstruction LAND         = new LAND();
 119   public static final ArithmeticInstruction IOR          = new IOR();
 120   public static final ArithmeticInstruction LOR          = new LOR();
 121   public static final ArithmeticInstruction IXOR         = new IXOR();
 122   public static final ArithmeticInstruction LXOR         = new LXOR();
 123   public static final ConversionInstruction I2L          = new I2L();
 124   public static final ConversionInstruction I2F          = new I2F();
 125   public static final ConversionInstruction I2D          = new I2D();
 126   public static final ConversionInstruction L2I          = new L2I();
 127   public static final ConversionInstruction L2F          = new L2F();
 128   public static final ConversionInstruction L2D          = new L2D();
 129   public static final ConversionInstruction F2I          = new F2I();
 130   public static final ConversionInstruction F2L          = new F2L();
 131   public static final ConversionInstruction F2D          = new F2D();
 132   public static final ConversionInstruction D2I          = new D2I();
 133   public static final ConversionInstruction D2L          = new D2L();
 134   public static final ConversionInstruction D2F          = new D2F();
 135   public static final ConversionInstruction I2B          = new I2B();
 136   public static final ConversionInstruction I2C          = new I2C();
 137   public static final ConversionInstruction I2S          = new I2S();
 138   public static final Instruction           LCMP         = new LCMP();
 139   public static final Instruction           FCMPL        = new FCMPL();
 140   public static final Instruction           FCMPG        = new FCMPG();
 141   public static final Instruction           DCMPL        = new DCMPL();
 142   public static final Instruction           DCMPG        = new DCMPG();
 143   public static final ReturnInstruction     IRETURN      = new IRETURN();
 144   public static final ReturnInstruction     LRETURN      = new LRETURN();
 145   public static final ReturnInstruction     FRETURN      = new FRETURN();
 146   public static final ReturnInstruction     DRETURN      = new DRETURN();
 147   public static final ReturnInstruction     ARETURN      = new ARETURN();
 148   public static final ReturnInstruction     RETURN       = new RETURN();
 149   public static final Instruction           ARRAYLENGTH  = new ARRAYLENGTH();
 150   public static final Instruction           ATHROW       = new ATHROW();
 151   public static final Instruction           MONITORENTER = new MONITORENTER();
 152   public static final Instruction           MONITOREXIT  = new MONITOREXIT();
 153 
 154   /** You can use these constants in multiple places safely, if you can guarantee
 155    * that you will never alter their internal values, e.g. call setIndex().
 156    */
 157   public static final LocalVariableInstruction THIS    = new ALOAD(0);
 158   public static final LocalVariableInstruction ALOAD_0 = THIS;
 159   public static final LocalVariableInstruction ALOAD_1 = new ALOAD(1);
 160   public static final LocalVariableInstruction ALOAD_2 = new ALOAD(2);
 161   public static final LocalVariableInstruction ILOAD_0 = new ILOAD(0);
 162   public static final LocalVariableInstruction ILOAD_1 = new ILOAD(1);
 163   public static final LocalVariableInstruction ILOAD_2 = new ILOAD(2);
 164   public static final LocalVariableInstruction ASTORE_0 = new ASTORE(0);
 165   public static final LocalVariableInstruction ASTORE_1 = new ASTORE(1);
 166   public static final LocalVariableInstruction ASTORE_2 = new ASTORE(2);
 167   public static final LocalVariableInstruction ISTORE_0 = new ISTORE(0);
 168   public static final LocalVariableInstruction ISTORE_1 = new ISTORE(1);
 169   public static final LocalVariableInstruction ISTORE_2 = new ISTORE(2);
 170 
 171 
 172   /** Get object via its opcode, for immutable instructions like
 173    * branch instructions entries are set to null.
 174    */
 175   public static final Instruction[] INSTRUCTIONS = new Instruction[256];
 176 
 177   /** Interfaces may have no static initializers, so we simulate this
 178    * with an inner class.
 179    */
 180   static final Clinit bla = new Clinit();
 181 
 182   static class Clinit {
 183     Clinit() {
 184       INSTRUCTIONS[Constants.NOP] = NOP;
 185       INSTRUCTIONS[Constants.ACONST_NULL] = ACONST_NULL;
 186       INSTRUCTIONS[Constants.ICONST_M1] = ICONST_M1;
 187       INSTRUCTIONS[Constants.ICONST_0] = ICONST_0;
 188       INSTRUCTIONS[Constants.ICONST_1] = ICONST_1;
 189       INSTRUCTIONS[Constants.ICONST_2] = ICONST_2;
 190       INSTRUCTIONS[Constants.ICONST_3] = ICONST_3;
 191       INSTRUCTIONS[Constants.ICONST_4] = ICONST_4;
 192       INSTRUCTIONS[Constants.ICONST_5] = ICONST_5;
 193       INSTRUCTIONS[Constants.LCONST_0] = LCONST_0;
 194       INSTRUCTIONS[Constants.LCONST_1] = LCONST_1;
 195       INSTRUCTIONS[Constants.FCONST_0] = FCONST_0;
 196       INSTRUCTIONS[Constants.FCONST_1] = FCONST_1;
 197       INSTRUCTIONS[Constants.FCONST_2] = FCONST_2;
 198       INSTRUCTIONS[Constants.DCONST_0] = DCONST_0;
 199       INSTRUCTIONS[Constants.DCONST_1] = DCONST_1;
 200       INSTRUCTIONS[Constants.IALOAD] = IALOAD;
 201       INSTRUCTIONS[Constants.LALOAD] = LALOAD;
 202       INSTRUCTIONS[Constants.FALOAD] = FALOAD;
 203       INSTRUCTIONS[Constants.DALOAD] = DALOAD;
 204       INSTRUCTIONS[Constants.AALOAD] = AALOAD;
 205       INSTRUCTIONS[Constants.BALOAD] = BALOAD;
 206       INSTRUCTIONS[Constants.CALOAD] = CALOAD;
 207       INSTRUCTIONS[Constants.SALOAD] = SALOAD;
 208       INSTRUCTIONS[Constants.IASTORE] = IASTORE;
 209       INSTRUCTIONS[Constants.LASTORE] = LASTORE;
 210       INSTRUCTIONS[Constants.FASTORE] = FASTORE;
 211       INSTRUCTIONS[Constants.DASTORE] = DASTORE;
 212       INSTRUCTIONS[Constants.AASTORE] = AASTORE;
 213       INSTRUCTIONS[Constants.BASTORE] = BASTORE;
 214       INSTRUCTIONS[Constants.CASTORE] = CASTORE;
 215       INSTRUCTIONS[Constants.SASTORE] = SASTORE;
 216       INSTRUCTIONS[Constants.POP] = POP;
 217       INSTRUCTIONS[Constants.POP2] = POP2;
 218       INSTRUCTIONS[Constants.DUP] = DUP;
 219       INSTRUCTIONS[Constants.DUP_X1] = DUP_X1;
 220       INSTRUCTIONS[Constants.DUP_X2] = DUP_X2;
 221       INSTRUCTIONS[Constants.DUP2] = DUP2;
 222       INSTRUCTIONS[Constants.DUP2_X1] = DUP2_X1;
 223       INSTRUCTIONS[Constants.DUP2_X2] = DUP2_X2;
 224       INSTRUCTIONS[Constants.SWAP] = SWAP;
 225       INSTRUCTIONS[Constants.IADD] = IADD;
 226       INSTRUCTIONS[Constants.LADD] = LADD;
 227       INSTRUCTIONS[Constants.FADD] = FADD;
 228       INSTRUCTIONS[Constants.DADD] = DADD;
 229       INSTRUCTIONS[Constants.ISUB] = ISUB;
 230       INSTRUCTIONS[Constants.LSUB] = LSUB;
 231       INSTRUCTIONS[Constants.FSUB] = FSUB;
 232       INSTRUCTIONS[Constants.DSUB] = DSUB;
 233       INSTRUCTIONS[Constants.IMUL] = IMUL;
 234       INSTRUCTIONS[Constants.LMUL] = LMUL;
 235       INSTRUCTIONS[Constants.FMUL] = FMUL;
 236       INSTRUCTIONS[Constants.DMUL] = DMUL;
 237       INSTRUCTIONS[Constants.IDIV] = IDIV;
 238       INSTRUCTIONS[Constants.LDIV] = LDIV;
 239       INSTRUCTIONS[Constants.FDIV] = FDIV;
 240       INSTRUCTIONS[Constants.DDIV] = DDIV;
 241       INSTRUCTIONS[Constants.IREM] = IREM;
 242       INSTRUCTIONS[Constants.LREM] = LREM;
 243       INSTRUCTIONS[Constants.FREM] = FREM;
 244       INSTRUCTIONS[Constants.DREM] = DREM;
 245       INSTRUCTIONS[Constants.INEG] = INEG;
 246       INSTRUCTIONS[Constants.LNEG] = LNEG;
 247       INSTRUCTIONS[Constants.FNEG] = FNEG;
 248       INSTRUCTIONS[Constants.DNEG] = DNEG;
 249       INSTRUCTIONS[Constants.ISHL] = ISHL;
 250       INSTRUCTIONS[Constants.LSHL] = LSHL;
 251       INSTRUCTIONS[Constants.ISHR] = ISHR;
 252       INSTRUCTIONS[Constants.LSHR] = LSHR;
 253       INSTRUCTIONS[Constants.IUSHR] = IUSHR;
 254       INSTRUCTIONS[Constants.LUSHR] = LUSHR;
 255       INSTRUCTIONS[Constants.IAND] = IAND;
 256       INSTRUCTIONS[Constants.LAND] = LAND;
 257       INSTRUCTIONS[Constants.IOR] = IOR;
 258       INSTRUCTIONS[Constants.LOR] = LOR;
 259       INSTRUCTIONS[Constants.IXOR] = IXOR;
 260       INSTRUCTIONS[Constants.LXOR] = LXOR;
 261       INSTRUCTIONS[Constants.I2L] = I2L;
 262       INSTRUCTIONS[Constants.I2F] = I2F;
 263       INSTRUCTIONS[Constants.I2D] = I2D;
 264       INSTRUCTIONS[Constants.L2I] = L2I;
 265       INSTRUCTIONS[Constants.L2F] = L2F;
 266       INSTRUCTIONS[Constants.L2D] = L2D;
 267       INSTRUCTIONS[Constants.F2I] = F2I;
 268       INSTRUCTIONS[Constants.F2L] = F2L;
 269       INSTRUCTIONS[Constants.F2D] = F2D;
 270       INSTRUCTIONS[Constants.D2I] = D2I;
 271       INSTRUCTIONS[Constants.D2L] = D2L;
 272       INSTRUCTIONS[Constants.D2F] = D2F;
 273       INSTRUCTIONS[Constants.I2B] = I2B;
 274       INSTRUCTIONS[Constants.I2C] = I2C;
 275       INSTRUCTIONS[Constants.I2S] = I2S;
 276       INSTRUCTIONS[Constants.LCMP] = LCMP;
 277       INSTRUCTIONS[Constants.FCMPL] = FCMPL;
 278       INSTRUCTIONS[Constants.FCMPG] = FCMPG;
 279       INSTRUCTIONS[Constants.DCMPL] = DCMPL;
 280       INSTRUCTIONS[Constants.DCMPG] = DCMPG;
 281       INSTRUCTIONS[Constants.IRETURN] = IRETURN;
 282       INSTRUCTIONS[Constants.LRETURN] = LRETURN;
 283       INSTRUCTIONS[Constants.FRETURN] = FRETURN;
 284       INSTRUCTIONS[Constants.DRETURN] = DRETURN;
 285       INSTRUCTIONS[Constants.ARETURN] = ARETURN;
 286       INSTRUCTIONS[Constants.RETURN] = RETURN;
 287       INSTRUCTIONS[Constants.ARRAYLENGTH] = ARRAYLENGTH;
 288       INSTRUCTIONS[Constants.ATHROW] = ATHROW;
 289       INSTRUCTIONS[Constants.MONITORENTER] = MONITORENTER;
 290       INSTRUCTIONS[Constants.MONITOREXIT] = MONITOREXIT;
 291     }
 292   }
 293 }