    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 * @version $Id$
    037 * @deprecated (since 6.0) Do not use. Use InstructionConst instead.
    038 */
    039@Deprecated
    040public interface InstructionConstants {
    041
    042    /** Predefined instruction objects
    043     */
    044    /*
    045     * NOTE these are not currently immutable, because Instruction
    046     * has mutable protected fields opcode and length.
    047     */
    048    Instruction NOP = new NOP();
    049    Instruction ACONST_NULL = new ACONST_NULL();
    050    Instruction ICONST_M1 = new ICONST(-1);
    051    Instruction ICONST_0 = new ICONST(0);
    052    Instruction ICONST_1 = new ICONST(1);
    053    Instruction ICONST_2 = new ICONST(2);
    054    Instruction ICONST_3 = new ICONST(3);
    055    Instruction ICONST_4 = new ICONST(4);
    056    Instruction ICONST_5 = new ICONST(5);
    057    Instruction LCONST_0 = new LCONST(0);
    058    Instruction LCONST_1 = new LCONST(1);
    059    Instruction FCONST_0 = new FCONST(0);
    060    Instruction FCONST_1 = new FCONST(1);
    061    Instruction FCONST_2 = new FCONST(2);
    062    Instruction DCONST_0 = new DCONST(0);
    063    Instruction DCONST_1 = new DCONST(1);
    064    ArrayInstruction IALOAD = new IALOAD();
    065    ArrayInstruction LALOAD = new LALOAD();
    066    ArrayInstruction FALOAD = new FALOAD();
    067    ArrayInstruction DALOAD = new DALOAD();
    068    ArrayInstruction AALOAD = new AALOAD();
    069    ArrayInstruction BALOAD = new BALOAD();
    070    ArrayInstruction CALOAD = new CALOAD();
    071    ArrayInstruction SALOAD = new SALOAD();
    072    ArrayInstruction IASTORE = new IASTORE();
    073    ArrayInstruction LASTORE = new LASTORE();
    074    ArrayInstruction FASTORE = new FASTORE();
    075    ArrayInstruction DASTORE = new DASTORE();
    076    ArrayInstruction AASTORE = new AASTORE();
    077    ArrayInstruction BASTORE = new BASTORE();
    078    ArrayInstruction CASTORE = new CASTORE();
    079    ArrayInstruction SASTORE = new SASTORE();
    080    StackInstruction POP = new POP();
    081    StackInstruction POP2 = new POP2();
    082    StackInstruction DUP = new DUP();
    083    StackInstruction DUP_X1 = new DUP_X1();
    084    StackInstruction DUP_X2 = new DUP_X2();
    085    StackInstruction DUP2 = new DUP2();
    086    StackInstruction DUP2_X1 = new DUP2_X1();
    087    StackInstruction DUP2_X2 = new DUP2_X2();
    088    StackInstruction SWAP = new SWAP();
    089    ArithmeticInstruction IADD = new IADD();
    090    ArithmeticInstruction LADD = new LADD();
    091    ArithmeticInstruction FADD = new FADD();
    092    ArithmeticInstruction DADD = new DADD();
    093    ArithmeticInstruction ISUB = new ISUB();
    094    ArithmeticInstruction LSUB = new LSUB();
    095    ArithmeticInstruction FSUB = new FSUB();
    096    ArithmeticInstruction DSUB = new DSUB();
    097    ArithmeticInstruction IMUL = new IMUL();
    098    ArithmeticInstruction LMUL = new LMUL();
    099    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}