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