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     */
018    package org.apache.bcel.generic;
019    
020    import org.apache.bcel.Constants;
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: InstructionConstants.java 947879 2010-05-25 00:48:30Z sebb $
037     * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
038     */
039    public interface InstructionConstants {
040    
041        /** Predefined instruction objects
042         */
043        public static final Instruction NOP = new NOP();
044        public static final Instruction ACONST_NULL = new ACONST_NULL();
045        public static final Instruction ICONST_M1 = new ICONST(-1);
046        public static final Instruction ICONST_0 = new ICONST(0);
047        public static final Instruction ICONST_1 = new ICONST(1);
048        public static final Instruction ICONST_2 = new ICONST(2);
049        public static final Instruction ICONST_3 = new ICONST(3);
050        public static final Instruction ICONST_4 = new ICONST(4);
051        public static final Instruction ICONST_5 = new ICONST(5);
052        public static final Instruction LCONST_0 = new LCONST(0);
053        public static final Instruction LCONST_1 = new LCONST(1);
054        public static final Instruction FCONST_0 = new FCONST(0);
055        public static final Instruction FCONST_1 = new FCONST(1);
056        public static final Instruction FCONST_2 = new FCONST(2);
057        public static final Instruction DCONST_0 = new DCONST(0);
058        public static final Instruction DCONST_1 = new DCONST(1);
059        public static final ArrayInstruction IALOAD = new IALOAD();
060        public static final ArrayInstruction LALOAD = new LALOAD();
061        public static final ArrayInstruction FALOAD = new FALOAD();
062        public static final ArrayInstruction DALOAD = new DALOAD();
063        public static final ArrayInstruction AALOAD = new AALOAD();
064        public static final ArrayInstruction BALOAD = new BALOAD();
065        public static final ArrayInstruction CALOAD = new CALOAD();
066        public static final ArrayInstruction SALOAD = new SALOAD();
067        public static final ArrayInstruction IASTORE = new IASTORE();
068        public static final ArrayInstruction LASTORE = new LASTORE();
069        public static final ArrayInstruction FASTORE = new FASTORE();
070        public static final ArrayInstruction DASTORE = new DASTORE();
071        public static final ArrayInstruction AASTORE = new AASTORE();
072        public static final ArrayInstruction BASTORE = new BASTORE();
073        public static final ArrayInstruction CASTORE = new CASTORE();
074        public static final ArrayInstruction SASTORE = new SASTORE();
075        public static final StackInstruction POP = new POP();
076        public static final StackInstruction POP2 = new POP2();
077        public static final StackInstruction DUP = new DUP();
078        public static final StackInstruction DUP_X1 = new DUP_X1();
079        public static final StackInstruction DUP_X2 = new DUP_X2();
080        public static final StackInstruction DUP2 = new DUP2();
081        public static final StackInstruction DUP2_X1 = new DUP2_X1();
082        public static final StackInstruction DUP2_X2 = new DUP2_X2();
083        public static final StackInstruction SWAP = new SWAP();
084        public static final ArithmeticInstruction IADD = new IADD();
085        public static final ArithmeticInstruction LADD = new LADD();
086        public static final ArithmeticInstruction FADD = new FADD();
087        public static final ArithmeticInstruction DADD = new DADD();
088        public static final ArithmeticInstruction ISUB = new ISUB();
089        public static final ArithmeticInstruction LSUB = new LSUB();
090        public static final ArithmeticInstruction FSUB = new FSUB();
091        public static final ArithmeticInstruction DSUB = new DSUB();
092        public static final ArithmeticInstruction IMUL = new IMUL();
093        public static final ArithmeticInstruction LMUL = new LMUL();
094        public static final ArithmeticInstruction FMUL = new FMUL();
095        public static final ArithmeticInstruction DMUL = new DMUL();
096        public static final ArithmeticInstruction IDIV = new IDIV();
097        public static final ArithmeticInstruction LDIV = new LDIV();
098        public static final ArithmeticInstruction FDIV = new FDIV();
099        public static final ArithmeticInstruction DDIV = new DDIV();
100        public static final ArithmeticInstruction IREM = new IREM();
101        public static final ArithmeticInstruction LREM = new LREM();
102        public static final ArithmeticInstruction FREM = new FREM();
103        public static final ArithmeticInstruction DREM = new DREM();
104        public static final ArithmeticInstruction INEG = new INEG();
105        public static final ArithmeticInstruction LNEG = new LNEG();
106        public static final ArithmeticInstruction FNEG = new FNEG();
107        public static final ArithmeticInstruction DNEG = new DNEG();
108        public static final ArithmeticInstruction ISHL = new ISHL();
109        public static final ArithmeticInstruction LSHL = new LSHL();
110        public static final ArithmeticInstruction ISHR = new ISHR();
111        public static final ArithmeticInstruction LSHR = new LSHR();
112        public static final ArithmeticInstruction IUSHR = new IUSHR();
113        public static final ArithmeticInstruction LUSHR = new LUSHR();
114        public static final ArithmeticInstruction IAND = new IAND();
115        public static final ArithmeticInstruction LAND = new LAND();
116        public static final ArithmeticInstruction IOR = new IOR();
117        public static final ArithmeticInstruction LOR = new LOR();
118        public static final ArithmeticInstruction IXOR = new IXOR();
119        public static final ArithmeticInstruction LXOR = new LXOR();
120        public static final ConversionInstruction I2L = new I2L();
121        public static final ConversionInstruction I2F = new I2F();
122        public static final ConversionInstruction I2D = new I2D();
123        public static final ConversionInstruction L2I = new L2I();
124        public static final ConversionInstruction L2F = new L2F();
125        public static final ConversionInstruction L2D = new L2D();
126        public static final ConversionInstruction F2I = new F2I();
127        public static final ConversionInstruction F2L = new F2L();
128        public static final ConversionInstruction F2D = new F2D();
129        public static final ConversionInstruction D2I = new D2I();
130        public static final ConversionInstruction D2L = new D2L();
131        public static final ConversionInstruction D2F = new D2F();
132        public static final ConversionInstruction I2B = new I2B();
133        public static final ConversionInstruction I2C = new I2C();
134        public static final ConversionInstruction I2S = new I2S();
135        public static final Instruction LCMP = new LCMP();
136        public static final Instruction FCMPL = new FCMPL();
137        public static final Instruction FCMPG = new FCMPG();
138        public static final Instruction DCMPL = new DCMPL();
139        public static final Instruction DCMPG = new DCMPG();
140        public static final ReturnInstruction IRETURN = new IRETURN();
141        public static final ReturnInstruction LRETURN = new LRETURN();
142        public static final ReturnInstruction FRETURN = new FRETURN();
143        public static final ReturnInstruction DRETURN = new DRETURN();
144        public static final ReturnInstruction ARETURN = new ARETURN();
145        public static final ReturnInstruction RETURN = new RETURN();
146        public static final Instruction ARRAYLENGTH = new ARRAYLENGTH();
147        public static final Instruction ATHROW = new ATHROW();
148        public static final Instruction MONITORENTER = new MONITORENTER();
149        public static final Instruction MONITOREXIT = new MONITOREXIT();
150        /** You can use these constants in multiple places safely, if you can guarantee
151         * that you will never alter their internal values, e.g. call setIndex().
152         */
153        public static final LocalVariableInstruction THIS = new ALOAD(0);
154        public static final LocalVariableInstruction ALOAD_0 = THIS;
155        public static final LocalVariableInstruction ALOAD_1 = new ALOAD(1);
156        public static final LocalVariableInstruction ALOAD_2 = new ALOAD(2);
157        public static final LocalVariableInstruction ILOAD_0 = new ILOAD(0);
158        public static final LocalVariableInstruction ILOAD_1 = new ILOAD(1);
159        public static final LocalVariableInstruction ILOAD_2 = new ILOAD(2);
160        public static final LocalVariableInstruction ASTORE_0 = new ASTORE(0);
161        public static final LocalVariableInstruction ASTORE_1 = new ASTORE(1);
162        public static final LocalVariableInstruction ASTORE_2 = new ASTORE(2);
163        public static final LocalVariableInstruction ISTORE_0 = new ISTORE(0);
164        public static final LocalVariableInstruction ISTORE_1 = new ISTORE(1);
165        public static final LocalVariableInstruction ISTORE_2 = new ISTORE(2);
166        /** Get object via its opcode, for immutable instructions like
167         * branch instructions entries are set to null.
168         */
169        public static final Instruction[] INSTRUCTIONS = new Instruction[256];
170        /** Interfaces may have no static initializers, so we simulate this
171         * with an inner class.
172         */
173        static final Clinit bla = new Clinit();
174    
175        static class Clinit {
176    
177            Clinit() {
178                INSTRUCTIONS[Constants.NOP] = NOP;
179                INSTRUCTIONS[Constants.ACONST_NULL] = ACONST_NULL;
180                INSTRUCTIONS[Constants.ICONST_M1] = ICONST_M1;
181                INSTRUCTIONS[Constants.ICONST_0] = ICONST_0;
182                INSTRUCTIONS[Constants.ICONST_1] = ICONST_1;
183                INSTRUCTIONS[Constants.ICONST_2] = ICONST_2;
184                INSTRUCTIONS[Constants.ICONST_3] = ICONST_3;
185                INSTRUCTIONS[Constants.ICONST_4] = ICONST_4;
186                INSTRUCTIONS[Constants.ICONST_5] = ICONST_5;
187                INSTRUCTIONS[Constants.LCONST_0] = LCONST_0;
188                INSTRUCTIONS[Constants.LCONST_1] = LCONST_1;
189                INSTRUCTIONS[Constants.FCONST_0] = FCONST_0;
190                INSTRUCTIONS[Constants.FCONST_1] = FCONST_1;
191                INSTRUCTIONS[Constants.FCONST_2] = FCONST_2;
192                INSTRUCTIONS[Constants.DCONST_0] = DCONST_0;
193                INSTRUCTIONS[Constants.DCONST_1] = DCONST_1;
194                INSTRUCTIONS[Constants.IALOAD] = IALOAD;
195                INSTRUCTIONS[Constants.LALOAD] = LALOAD;
196                INSTRUCTIONS[Constants.FALOAD] = FALOAD;
197                INSTRUCTIONS[Constants.DALOAD] = DALOAD;
198                INSTRUCTIONS[Constants.AALOAD] = AALOAD;
199                INSTRUCTIONS[Constants.BALOAD] = BALOAD;
200                INSTRUCTIONS[Constants.CALOAD] = CALOAD;
201                INSTRUCTIONS[Constants.SALOAD] = SALOAD;
202                INSTRUCTIONS[Constants.IASTORE] = IASTORE;
203                INSTRUCTIONS[Constants.LASTORE] = LASTORE;
204                INSTRUCTIONS[Constants.FASTORE] = FASTORE;
205                INSTRUCTIONS[Constants.DASTORE] = DASTORE;
206                INSTRUCTIONS[Constants.AASTORE] = AASTORE;
207                INSTRUCTIONS[Constants.BASTORE] = BASTORE;
208                INSTRUCTIONS[Constants.CASTORE] = CASTORE;
209                INSTRUCTIONS[Constants.SASTORE] = SASTORE;
210                INSTRUCTIONS[Constants.POP] = POP;
211                INSTRUCTIONS[Constants.POP2] = POP2;
212                INSTRUCTIONS[Constants.DUP] = DUP;
213                INSTRUCTIONS[Constants.DUP_X1] = DUP_X1;
214                INSTRUCTIONS[Constants.DUP_X2] = DUP_X2;
215                INSTRUCTIONS[Constants.DUP2] = DUP2;
216                INSTRUCTIONS[Constants.DUP2_X1] = DUP2_X1;
217                INSTRUCTIONS[Constants.DUP2_X2] = DUP2_X2;
218                INSTRUCTIONS[Constants.SWAP] = SWAP;
219                INSTRUCTIONS[Constants.IADD] = IADD;
220                INSTRUCTIONS[Constants.LADD] = LADD;
221                INSTRUCTIONS[Constants.FADD] = FADD;
222                INSTRUCTIONS[Constants.DADD] = DADD;
223                INSTRUCTIONS[Constants.ISUB] = ISUB;
224                INSTRUCTIONS[Constants.LSUB] = LSUB;
225                INSTRUCTIONS[Constants.FSUB] = FSUB;
226                INSTRUCTIONS[Constants.DSUB] = DSUB;
227                INSTRUCTIONS[Constants.IMUL] = IMUL;
228                INSTRUCTIONS[Constants.LMUL] = LMUL;
229                INSTRUCTIONS[Constants.FMUL] = FMUL;
230                INSTRUCTIONS[Constants.DMUL] = DMUL;
231                INSTRUCTIONS[Constants.IDIV] = IDIV;
232                INSTRUCTIONS[Constants.LDIV] = LDIV;
233                INSTRUCTIONS[Constants.FDIV] = FDIV;
234                INSTRUCTIONS[Constants.DDIV] = DDIV;
235                INSTRUCTIONS[Constants.IREM] = IREM;
236                INSTRUCTIONS[Constants.LREM] = LREM;
237                INSTRUCTIONS[Constants.FREM] = FREM;
238                INSTRUCTIONS[Constants.DREM] = DREM;
239                INSTRUCTIONS[Constants.INEG] = INEG;
240                INSTRUCTIONS[Constants.LNEG] = LNEG;
241                INSTRUCTIONS[Constants.FNEG] = FNEG;
242                INSTRUCTIONS[Constants.DNEG] = DNEG;
243                INSTRUCTIONS[Constants.ISHL] = ISHL;
244                INSTRUCTIONS[Constants.LSHL] = LSHL;
245                INSTRUCTIONS[Constants.ISHR] = ISHR;
246                INSTRUCTIONS[Constants.LSHR] = LSHR;
247                INSTRUCTIONS[Constants.IUSHR] = IUSHR;
248                INSTRUCTIONS[Constants.LUSHR] = LUSHR;
249                INSTRUCTIONS[Constants.IAND] = IAND;
250                INSTRUCTIONS[Constants.LAND] = LAND;
251                INSTRUCTIONS[Constants.IOR] = IOR;
252                INSTRUCTIONS[Constants.LOR] = LOR;
253                INSTRUCTIONS[Constants.IXOR] = IXOR;
254                INSTRUCTIONS[Constants.LXOR] = LXOR;
255                INSTRUCTIONS[Constants.I2L] = I2L;
256                INSTRUCTIONS[Constants.I2F] = I2F;
257                INSTRUCTIONS[Constants.I2D] = I2D;
258                INSTRUCTIONS[Constants.L2I] = L2I;
259                INSTRUCTIONS[Constants.L2F] = L2F;
260                INSTRUCTIONS[Constants.L2D] = L2D;
261                INSTRUCTIONS[Constants.F2I] = F2I;
262                INSTRUCTIONS[Constants.F2L] = F2L;
263                INSTRUCTIONS[Constants.F2D] = F2D;
264                INSTRUCTIONS[Constants.D2I] = D2I;
265                INSTRUCTIONS[Constants.D2L] = D2L;
266                INSTRUCTIONS[Constants.D2F] = D2F;
267                INSTRUCTIONS[Constants.I2B] = I2B;
268                INSTRUCTIONS[Constants.I2C] = I2C;
269                INSTRUCTIONS[Constants.I2S] = I2S;
270                INSTRUCTIONS[Constants.LCMP] = LCMP;
271                INSTRUCTIONS[Constants.FCMPL] = FCMPL;
272                INSTRUCTIONS[Constants.FCMPG] = FCMPG;
273                INSTRUCTIONS[Constants.DCMPL] = DCMPL;
274                INSTRUCTIONS[Constants.DCMPG] = DCMPG;
275                INSTRUCTIONS[Constants.IRETURN] = IRETURN;
276                INSTRUCTIONS[Constants.LRETURN] = LRETURN;
277                INSTRUCTIONS[Constants.FRETURN] = FRETURN;
278                INSTRUCTIONS[Constants.DRETURN] = DRETURN;
279                INSTRUCTIONS[Constants.ARETURN] = ARETURN;
280                INSTRUCTIONS[Constants.RETURN] = RETURN;
281                INSTRUCTIONS[Constants.ARRAYLENGTH] = ARRAYLENGTH;
282                INSTRUCTIONS[Constants.ATHROW] = ATHROW;
283                INSTRUCTIONS[Constants.MONITORENTER] = MONITORENTER;
284                INSTRUCTIONS[Constants.MONITOREXIT] = MONITOREXIT;
285            }
286        }
287    }