    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 *  Unless required by applicable law or agreed to in writing, software
    012 *  distributed under the License is distributed on an "AS IS" BASIS,
    013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 *  See the License for the specific language governing permissions and
    015 *  limitations under the License.
    016 *
    017 */
    018package org.apache.bcel.generic;
    019
    020import org.apache.bcel.Const;
    021
    022/**
    023 * This interface contains shareable instruction objects.
    024 *
    025 * In order to save memory you can use some instructions multiply,
    026 * since they have an immutable state and are directly derived from
    027 * Instruction.  I.e. they have no instance fields that could be
    028 * changed. Since some of these instructions like ICONST_0 occur
    029 * very frequently this can save a lot of time and space. This
    030 * feature is an adaptation of the FlyWeight design pattern, we
    031 * just use an array instead of a factory.
    032 *
    033 * The Instructions can also accessed directly under their names, so
    034 * it's possible to write il.append(Instruction.ICONST_0);
    035 *
    036 * @deprecated (since 6.0) Do not use. Use InstructionConst instead.
    037 */
    038@Deprecated
    039public interface InstructionConstants {
    040
    041    /** Predefined instruction objects
    042     */
    043    /*
    044     * NOTE these are not currently immutable, because Instruction
    045     * has mutable protected fields opcode and length.
    046     */
    047    Instruction NOP = new NOP();
    048    Instruction ACONST_NULL = new ACONST_NULL();
    049    Instruction ICONST_M1 = new ICONST(-1);
    050    Instruction ICONST_0 = new ICONST(0);
    051    Instruction ICONST_1 = new ICONST(1);
    052    Instruction ICONST_2 = new ICONST(2);
    053    Instruction ICONST_3 = new ICONST(3);
    054    Instruction ICONST_4 = new ICONST(4);
    055    Instruction ICONST_5 = new ICONST(5);
    056    Instruction LCONST_0 = new LCONST(0);
    057    Instruction LCONST_1 = new LCONST(1);
    058    Instruction FCONST_0 = new FCONST(0);
    059    Instruction FCONST_1 = new FCONST(1);
    060    Instruction FCONST_2 = new FCONST(2);
    061    Instruction DCONST_0 = new DCONST(0);
    062    Instruction DCONST_1 = new DCONST(1);
    063    ArrayInstruction IALOAD = new IALOAD();
    064    ArrayInstruction LALOAD = new LALOAD();
    065    ArrayInstruction FALOAD = new FALOAD();
    066    ArrayInstruction DALOAD = new DALOAD();
    067    ArrayInstruction AALOAD = new AALOAD();
    068    ArrayInstruction BALOAD = new BALOAD();
    069    ArrayInstruction CALOAD = new CALOAD();
    070    ArrayInstruction SALOAD = new SALOAD();
    071    ArrayInstruction IASTORE = new IASTORE();
    072    ArrayInstruction LASTORE = new LASTORE();
    073    ArrayInstruction FASTORE = new FASTORE();
    074    ArrayInstruction DASTORE = new DASTORE();
    075    ArrayInstruction AASTORE = new AASTORE();
    076    ArrayInstruction BASTORE = new BASTORE();
    077    ArrayInstruction CASTORE = new CASTORE();
    078    ArrayInstruction SASTORE = new SASTORE();
    079    StackInstruction POP = new POP();
    080    StackInstruction POP2 = new POP2();
    081    StackInstruction DUP = new DUP();
    082    StackInstruction DUP_X1 = new DUP_X1();
    083    StackInstruction DUP_X2 = new DUP_X2();
    084    StackInstruction DUP2 = new DUP2();
    085    StackInstruction DUP2_X1 = new DUP2_X1();
    086    StackInstruction DUP2_X2 = new DUP2_X2();
    087    StackInstruction SWAP = new SWAP();
    088    ArithmeticInstruction IADD = new IADD();
    089    ArithmeticInstruction LADD = new LADD();
    090    ArithmeticInstruction FADD = new FADD();
    091    ArithmeticInstruction DADD = new DADD();
    092    ArithmeticInstruction ISUB = new ISUB();
    093    ArithmeticInstruction LSUB = new LSUB();
    094    ArithmeticInstruction FSUB = new FSUB();
    095    ArithmeticInstruction DSUB = new DSUB();
    096    ArithmeticInstruction IMUL = new IMUL();
    097    ArithmeticInstruction LMUL = new LMUL();
    098    ArithmeticInstruction FMUL = new FMUL();
    099    ArithmeticInstruction DMUL = new DMUL();
    100    ArithmeticInstruction IDIV = new IDIV();
    101    ArithmeticInstruction LDIV = new LDIV();
    102    ArithmeticInstruction FDIV = new FDIV();
    103    ArithmeticInstruction DDIV = new DDIV();
    104    ArithmeticInstruction IREM = new IREM();
    105    ArithmeticInstruction LREM = new LREM();
    106    ArithmeticInstruction FREM = new FREM();
    107    ArithmeticInstruction DREM = new DREM();
    108    ArithmeticInstruction INEG = new INEG();
    109    ArithmeticInstruction LNEG = new LNEG();
    110    ArithmeticInstruction FNEG = new FNEG();
    111    ArithmeticInstruction DNEG = new DNEG();
    112    ArithmeticInstruction ISHL = new ISHL();
    113    ArithmeticInstruction LSHL = new LSHL();
    114    ArithmeticInstruction ISHR = new ISHR();
    115    ArithmeticInstruction LSHR = new LSHR();
    116    ArithmeticInstruction IUSHR = new IUSHR();
    117    ArithmeticInstruction LUSHR = new LUSHR();
    118    ArithmeticInstruction IAND = new IAND();
    119    ArithmeticInstruction LAND = new LAND();
    120    ArithmeticInstruction IOR = new IOR();
    121    ArithmeticInstruction LOR = new LOR();
    122    ArithmeticInstruction IXOR = new IXOR();
    123    ArithmeticInstruction LXOR = new LXOR();
    124    ConversionInstruction I2L = new I2L();
    125    ConversionInstruction I2F = new I2F();
    126    ConversionInstruction I2D = new I2D();
    127    ConversionInstruction L2I = new L2I();
    128    ConversionInstruction L2F = new L2F();
    129    ConversionInstruction L2D = new L2D();
    130    ConversionInstruction F2I = new F2I();
    131    ConversionInstruction F2L = new F2L();
    132    ConversionInstruction F2D = new F2D();
    133    ConversionInstruction D2I = new D2I();
    134    ConversionInstruction D2L = new D2L();
    135    ConversionInstruction D2F = new D2F();
    136    ConversionInstruction I2B = new I2B();
    137    ConversionInstruction I2C = new I2C();
    138    ConversionInstruction I2S = new I2S();
    139    Instruction LCMP = new LCMP();
    140    Instruction FCMPL = new FCMPL();
    141    Instruction FCMPG = new FCMPG();
    142    Instruction DCMPL = new DCMPL();
    143    Instruction DCMPG = new DCMPG();
    144    ReturnInstruction IRETURN = new IRETURN();
    145    ReturnInstruction LRETURN = new LRETURN();
    146    ReturnInstruction FRETURN = new FRETURN();
    147    ReturnInstruction DRETURN = new DRETURN();
    148    ReturnInstruction ARETURN = new ARETURN();
    149    ReturnInstruction RETURN = new RETURN();
    150    Instruction ARRAYLENGTH = new ARRAYLENGTH();
    151    Instruction ATHROW = new ATHROW();
    152    Instruction MONITORENTER = new MONITORENTER();
    153    Instruction MONITOREXIT = new MONITOREXIT();
    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    LocalVariableInstruction THIS = new ALOAD(0);
    158    LocalVariableInstruction ALOAD_0 = THIS;
    159    LocalVariableInstruction ALOAD_1 = new ALOAD(1);
    160    LocalVariableInstruction ALOAD_2 = new ALOAD(2);
    161    LocalVariableInstruction ILOAD_0 = new ILOAD(0);
    162    LocalVariableInstruction ILOAD_1 = new ILOAD(1);
    163    LocalVariableInstruction ILOAD_2 = new ILOAD(2);
    164    LocalVariableInstruction ASTORE_0 = new ASTORE(0);
    165    LocalVariableInstruction ASTORE_1 = new ASTORE(1);
    166    LocalVariableInstruction ASTORE_2 = new ASTORE(2);
    167    LocalVariableInstruction ISTORE_0 = new ISTORE(0);
    168    LocalVariableInstruction ISTORE_1 = new ISTORE(1);
    169    LocalVariableInstruction ISTORE_2 = new ISTORE(2);
    170    /** Get object via its opcode, for immutable instructions like
    171     * branch instructions entries are set to null.
    172     */
    173    Instruction[] INSTRUCTIONS = new Instruction[256];
    174    /** Interfaces may have no static initializers, so we simulate this
    175     * with an inner class.
    176     */
    177    Clinit bla = new Clinit();
    178
    179    class Clinit {
    180
    181        Clinit() {
    182            INSTRUCTIONS[Const.NOP] = NOP;
    183            INSTRUCTIONS[Const.ACONST_NULL] = ACONST_NULL;
    184            INSTRUCTIONS[Const.ICONST_M1] = ICONST_M1;
    185            INSTRUCTIONS[Const.ICONST_0] = ICONST_0;
    186            INSTRUCTIONS[Const.ICONST_1] = ICONST_1;
    187            INSTRUCTIONS[Const.ICONST_2] = ICONST_2;
    188            INSTRUCTIONS[Const.ICONST_3] = ICONST_3;
    189            INSTRUCTIONS[Const.ICONST_4] = ICONST_4;
    190            INSTRUCTIONS[Const.ICONST_5] = ICONST_5;
    191            INSTRUCTIONS[Const.LCONST_0] = LCONST_0;
    192            INSTRUCTIONS[Const.LCONST_1] = LCONST_1;
    193            INSTRUCTIONS[Const.FCONST_0] = FCONST_0;
    194            INSTRUCTIONS[Const.FCONST_1] = FCONST_1;
    195            INSTRUCTIONS[Const.FCONST_2] = FCONST_2;
    196            INSTRUCTIONS[Const.DCONST_0] = DCONST_0;
    197            INSTRUCTIONS[Const.DCONST_1] = DCONST_1;
    198            INSTRUCTIONS[Const.IALOAD] = IALOAD;
    199            INSTRUCTIONS[Const.LALOAD] = LALOAD;
    200            INSTRUCTIONS[Const.FALOAD] = FALOAD;
    201            INSTRUCTIONS[Const.DALOAD] = DALOAD;
    202            INSTRUCTIONS[Const.AALOAD] = AALOAD;
    203            INSTRUCTIONS[Const.BALOAD] = BALOAD;
    204            INSTRUCTIONS[Const.CALOAD] = CALOAD;
    205            INSTRUCTIONS[Const.SALOAD] = SALOAD;
    206            INSTRUCTIONS[Const.IASTORE] = IASTORE;
    207            INSTRUCTIONS[Const.LASTORE] = LASTORE;
    208            INSTRUCTIONS[Const.FASTORE] = FASTORE;
    209            INSTRUCTIONS[Const.DASTORE] = DASTORE;
    210            INSTRUCTIONS[Const.AASTORE] = AASTORE;
    211            INSTRUCTIONS[Const.BASTORE] = BASTORE;
    212            INSTRUCTIONS[Const.CASTORE] = CASTORE;
    213            INSTRUCTIONS[Const.SASTORE] = SASTORE;
    214            INSTRUCTIONS[Const.POP] = POP;
    215            INSTRUCTIONS[Const.POP2] = POP2;
    216            INSTRUCTIONS[Const.DUP] = DUP;
    217            INSTRUCTIONS[Const.DUP_X1] = DUP_X1;
    218            INSTRUCTIONS[Const.DUP_X2] = DUP_X2;
    219            INSTRUCTIONS[Const.DUP2] = DUP2;
    220            INSTRUCTIONS[Const.DUP2_X1] = DUP2_X1;
    221            INSTRUCTIONS[Const.DUP2_X2] = DUP2_X2;
    222            INSTRUCTIONS[Const.SWAP] = SWAP;
    223            INSTRUCTIONS[Const.IADD] = IADD;
    224            INSTRUCTIONS[Const.LADD] = LADD;
    225            INSTRUCTIONS[Const.FADD] = FADD;
    226            INSTRUCTIONS[Const.DADD] = DADD;
    227            INSTRUCTIONS[Const.ISUB] = ISUB;
    228            INSTRUCTIONS[Const.LSUB] = LSUB;
    229            INSTRUCTIONS[Const.FSUB] = FSUB;
    230            INSTRUCTIONS[Const.DSUB] = DSUB;
    231            INSTRUCTIONS[Const.IMUL] = IMUL;
    232            INSTRUCTIONS[Const.LMUL] = LMUL;
    233            INSTRUCTIONS[Const.FMUL] = FMUL;
    234            INSTRUCTIONS[Const.DMUL] = DMUL;
    235            INSTRUCTIONS[Const.IDIV] = IDIV;
    236            INSTRUCTIONS[Const.LDIV] = LDIV;
    237            INSTRUCTIONS[Const.FDIV] = FDIV;
    238            INSTRUCTIONS[Const.DDIV] = DDIV;
    239            INSTRUCTIONS[Const.IREM] = IREM;
    240            INSTRUCTIONS[Const.LREM] = LREM;
    241            INSTRUCTIONS[Const.FREM] = FREM;
    242            INSTRUCTIONS[Const.DREM] = DREM;
    243            INSTRUCTIONS[Const.INEG] = INEG;
    244            INSTRUCTIONS[Const.LNEG] = LNEG;
    245            INSTRUCTIONS[Const.FNEG] = FNEG;
    246            INSTRUCTIONS[Const.DNEG] = DNEG;
    247            INSTRUCTIONS[Const.ISHL] = ISHL;
    248            INSTRUCTIONS[Const.LSHL] = LSHL;
    249            INSTRUCTIONS[Const.ISHR] = ISHR;
    250            INSTRUCTIONS[Const.LSHR] = LSHR;
    251            INSTRUCTIONS[Const.IUSHR] = IUSHR;
    252            INSTRUCTIONS[Const.LUSHR] = LUSHR;
    253            INSTRUCTIONS[Const.IAND] = IAND;
    254            INSTRUCTIONS[Const.LAND] = LAND;
    255            INSTRUCTIONS[Const.IOR] = IOR;
    256            INSTRUCTIONS[Const.LOR] = LOR;
    257            INSTRUCTIONS[Const.IXOR] = IXOR;
    258            INSTRUCTIONS[Const.LXOR] = LXOR;
    259            INSTRUCTIONS[Const.I2L] = I2L;
    260            INSTRUCTIONS[Const.I2F] = I2F;
    261            INSTRUCTIONS[Const.I2D] = I2D;
    262            INSTRUCTIONS[Const.L2I] = L2I;
    263            INSTRUCTIONS[Const.L2F] = L2F;
    264            INSTRUCTIONS[Const.L2D] = L2D;
    265            INSTRUCTIONS[Const.F2I] = F2I;
    266            INSTRUCTIONS[Const.F2L] = F2L;
    267            INSTRUCTIONS[Const.F2D] = F2D;
    268            INSTRUCTIONS[Const.D2I] = D2I;
    269            INSTRUCTIONS[Const.D2L] = D2L;
    270            INSTRUCTIONS[Const.D2F] = D2F;
    271            INSTRUCTIONS[Const.I2B] = I2B;
    272            INSTRUCTIONS[Const.I2C] = I2C;
    273            INSTRUCTIONS[Const.I2S] = I2S;
    274            INSTRUCTIONS[Const.LCMP] = LCMP;
    275            INSTRUCTIONS[Const.FCMPL] = FCMPL;
    276            INSTRUCTIONS[Const.FCMPG] = FCMPG;
    277            INSTRUCTIONS[Const.DCMPL] = DCMPL;
    278            INSTRUCTIONS[Const.DCMPG] = DCMPG;
    279            INSTRUCTIONS[Const.IRETURN] = IRETURN;
    280            INSTRUCTIONS[Const.LRETURN] = LRETURN;
    281            INSTRUCTIONS[Const.FRETURN] = FRETURN;
    282            INSTRUCTIONS[Const.DRETURN] = DRETURN;
    283            INSTRUCTIONS[Const.ARETURN] = ARETURN;
    284            INSTRUCTIONS[Const.RETURN] = RETURN;
    285            INSTRUCTIONS[Const.ARRAYLENGTH] = ARRAYLENGTH;
    286            INSTRUCTIONS[Const.ATHROW] = ATHROW;
    287            INSTRUCTIONS[Const.MONITORENTER] = MONITORENTER;
    288            INSTRUCTIONS[Const.MONITOREXIT] = MONITOREXIT;
    289        }
    290    }
    291}