View Javadoc
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   * @deprecated (since 6.0) Do not use. Use InstructionConst instead.
37   */
38  @Deprecated
39  public interface InstructionConstants {
40  
41      /** Predefined instruction objects
42       */
43      /*
44       * NOTE these are not currently immutable, because Instruction
45       * has mutable protected fields opcode and length.
46       */
47      Instruction NOPneric/NOP.html#NOP">NOP = new NOP();
48      Instruction ACONST_NULLONST_NULL.html#ACONST_NULL">ACONST_NULL = new ACONST_NULL();
49      Instruction ICONST_M1 = new ICONST(-1);
50      Instruction ICONST_0 = new ICONST(0);
51      Instruction ICONST_1 = new ICONST(1);
52      Instruction ICONST_2 = new ICONST(2);
53      Instruction ICONST_3 = new ICONST(3);
54      Instruction ICONST_4 = new ICONST(4);
55      Instruction ICONST_5 = new ICONST(5);
56      Instruction LCONST_0 = new LCONST(0);
57      Instruction LCONST_1 = new LCONST(1);
58      Instruction FCONST_0 = new FCONST(0);
59      Instruction FCONST_1 = new FCONST(1);
60      Instruction FCONST_2 = new FCONST(2);
61      Instruction DCONST_0 = new DCONST(0);
62      Instruction DCONST_1 = new DCONST(1);
63      ArrayInstruction IALOADic/IALOAD.html#IALOAD">IALOAD = new IALOAD();
64      ArrayInstruction LALOADic/LALOAD.html#LALOAD">LALOAD = new LALOAD();
65      ArrayInstruction FALOADic/FALOAD.html#FALOAD">FALOAD = new FALOAD();
66      ArrayInstruction DALOADic/DALOAD.html#DALOAD">DALOAD = new DALOAD();
67      ArrayInstruction AALOADic/AALOAD.html#AALOAD">AALOAD = new AALOAD();
68      ArrayInstruction BALOADic/BALOAD.html#BALOAD">BALOAD = new BALOAD();
69      ArrayInstruction CALOADic/CALOAD.html#CALOAD">CALOAD = new CALOAD();
70      ArrayInstruction SALOADic/SALOAD.html#SALOAD">SALOAD = new SALOAD();
71      ArrayInstruction IASTOREc/IASTORE.html#IASTORE">IASTORE = new IASTORE();
72      ArrayInstruction LASTOREc/LASTORE.html#LASTORE">LASTORE = new LASTORE();
73      ArrayInstruction FASTOREc/FASTORE.html#FASTORE">FASTORE = new FASTORE();
74      ArrayInstruction DASTOREc/DASTORE.html#DASTORE">DASTORE = new DASTORE();
75      ArrayInstruction AASTOREc/AASTORE.html#AASTORE">AASTORE = new AASTORE();
76      ArrayInstruction BASTOREc/BASTORE.html#BASTORE">BASTORE = new BASTORE();
77      ArrayInstruction CASTOREc/CASTORE.html#CASTORE">CASTORE = new CASTORE();
78      ArrayInstruction SASTOREc/SASTORE.html#SASTORE">SASTORE = new SASTORE();
79      StackInstruction POPneric/POP.html#POP">POP = new POP();
80      StackInstruction POP2eric/POP2.html#POP2">POP2 = new POP2();
81      StackInstruction DUPneric/DUP.html#DUP">DUP = new DUP();
82      StackInstruction DUP_X1ic/DUP_X1.html#DUP_X1">DUP_X1 = new DUP_X1();
83      StackInstruction DUP_X2ic/DUP_X2.html#DUP_X2">DUP_X2 = new DUP_X2();
84      StackInstruction DUP2eric/DUP2.html#DUP2">DUP2 = new DUP2();
85      StackInstruction DUP2_X1c/DUP2_X1.html#DUP2_X1">DUP2_X1 = new DUP2_X1();
86      StackInstruction DUP2_X2c/DUP2_X2.html#DUP2_X2">DUP2_X2 = new DUP2_X2();
87      StackInstruction SWAPeric/SWAP.html#SWAP">SWAP = new SWAP();
88      ArithmeticInstruction IADDeric/IADD.html#IADD">IADD = new IADD();
89      ArithmeticInstruction LADDeric/LADD.html#LADD">LADD = new LADD();
90      ArithmeticInstruction FADDeric/FADD.html#FADD">FADD = new FADD();
91      ArithmeticInstruction DADDeric/DADD.html#DADD">DADD = new DADD();
92      ArithmeticInstruction ISUBeric/ISUB.html#ISUB">ISUB = new ISUB();
93      ArithmeticInstruction LSUBeric/LSUB.html#LSUB">LSUB = new LSUB();
94      ArithmeticInstruction FSUBeric/FSUB.html#FSUB">FSUB = new FSUB();
95      ArithmeticInstruction DSUBeric/DSUB.html#DSUB">DSUB = new DSUB();
96      ArithmeticInstruction IMULeric/IMUL.html#IMUL">IMUL = new IMUL();
97      ArithmeticInstruction LMULeric/LMUL.html#LMUL">LMUL = new LMUL();
98      ArithmeticInstruction FMULeric/FMUL.html#FMUL">FMUL = new FMUL();
99      ArithmeticInstruction DMULeric/DMUL.html#DMUL">DMUL = new DMUL();
100     ArithmeticInstruction IDIVeric/IDIV.html#IDIV">IDIV = new IDIV();
101     ArithmeticInstruction LDIVeric/LDIV.html#LDIV">LDIV = new LDIV();
102     ArithmeticInstruction FDIVeric/FDIV.html#FDIV">FDIV = new FDIV();
103     ArithmeticInstruction DDIVeric/DDIV.html#DDIV">DDIV = new DDIV();
104     ArithmeticInstruction IREMeric/IREM.html#IREM">IREM = new IREM();
105     ArithmeticInstruction LREMeric/LREM.html#LREM">LREM = new LREM();
106     ArithmeticInstruction FREMeric/FREM.html#FREM">FREM = new FREM();
107     ArithmeticInstruction DREMeric/DREM.html#DREM">DREM = new DREM();
108     ArithmeticInstruction INEGeric/INEG.html#INEG">INEG = new INEG();
109     ArithmeticInstruction LNEGeric/LNEG.html#LNEG">LNEG = new LNEG();
110     ArithmeticInstruction FNEGeric/FNEG.html#FNEG">FNEG = new FNEG();
111     ArithmeticInstruction DNEGeric/DNEG.html#DNEG">DNEG = new DNEG();
112     ArithmeticInstruction ISHLeric/ISHL.html#ISHL">ISHL = new ISHL();
113     ArithmeticInstruction LSHLeric/LSHL.html#LSHL">LSHL = new LSHL();
114     ArithmeticInstruction ISHReric/ISHR.html#ISHR">ISHR = new ISHR();
115     ArithmeticInstruction LSHReric/LSHR.html#LSHR">LSHR = new LSHR();
116     ArithmeticInstruction IUSHRric/IUSHR.html#IUSHR">IUSHR = new IUSHR();
117     ArithmeticInstruction LUSHRric/LUSHR.html#LUSHR">LUSHR = new LUSHR();
118     ArithmeticInstruction IANDeric/IAND.html#IAND">IAND = new IAND();
119     ArithmeticInstruction LANDeric/LAND.html#LAND">LAND = new LAND();
120     ArithmeticInstruction IORneric/IOR.html#IOR">IOR = new IOR();
121     ArithmeticInstruction LORneric/LOR.html#LOR">LOR = new LOR();
122     ArithmeticInstruction IXOReric/IXOR.html#IXOR">IXOR = new IXOR();
123     ArithmeticInstruction LXOReric/LXOR.html#LXOR">LXOR = new LXOR();
124     ConversionInstruction I2Lneric/I2L.html#I2L">I2L = new I2L();
125     ConversionInstruction I2Fneric/I2F.html#I2F">I2F = new I2F();
126     ConversionInstruction I2Dneric/I2D.html#I2D">I2D = new I2D();
127     ConversionInstruction L2Ineric/L2I.html#L2I">L2I = new L2I();
128     ConversionInstruction L2Fneric/L2F.html#L2F">L2F = new L2F();
129     ConversionInstruction L2Dneric/L2D.html#L2D">L2D = new L2D();
130     ConversionInstruction F2Ineric/F2I.html#F2I">F2I = new F2I();
131     ConversionInstruction F2Lneric/F2L.html#F2L">F2L = new F2L();
132     ConversionInstruction F2Dneric/F2D.html#F2D">F2D = new F2D();
133     ConversionInstruction D2Ineric/D2I.html#D2I">D2I = new D2I();
134     ConversionInstruction D2Lneric/D2L.html#D2L">D2L = new D2L();
135     ConversionInstruction D2Fneric/D2F.html#D2F">D2F = new D2F();
136     ConversionInstruction I2Bneric/I2B.html#I2B">I2B = new I2B();
137     ConversionInstruction I2Cneric/I2C.html#I2C">I2C = new I2C();
138     ConversionInstruction I2Sneric/I2S.html#I2S">I2S = new I2S();
139     Instruction LCMPeric/LCMP.html#LCMP">LCMP = new LCMP();
140     Instruction FCMPLric/FCMPL.html#FCMPL">FCMPL = new FCMPL();
141     Instruction FCMPGric/FCMPG.html#FCMPG">FCMPG = new FCMPG();
142     Instruction DCMPLric/DCMPL.html#DCMPL">DCMPL = new DCMPL();
143     Instruction DCMPGric/DCMPG.html#DCMPG">DCMPG = new DCMPG();
144     ReturnInstruction IRETURNc/IRETURN.html#IRETURN">IRETURN = new IRETURN();
145     ReturnInstruction LRETURNc/LRETURN.html#LRETURN">LRETURN = new LRETURN();
146     ReturnInstruction FRETURNc/FRETURN.html#FRETURN">FRETURN = new FRETURN();
147     ReturnInstruction DRETURNc/DRETURN.html#DRETURN">DRETURN = new DRETURN();
148     ReturnInstruction ARETURNc/ARETURN.html#ARETURN">ARETURN = new ARETURN();
149     ReturnInstruction RETURNic/RETURN.html#RETURN">RETURN = new RETURN();
150     Instruction ARRAYLENGTHRAYLENGTH.html#ARRAYLENGTH">ARRAYLENGTH = new ARRAYLENGTH();
151     Instruction ATHROWic/ATHROW.html#ATHROW">ATHROW = new ATHROW();
152     Instruction MONITORENTERITORENTER.html#MONITORENTER">MONITORENTER = new MONITORENTER();
153     Instruction MONITOREXITNITOREXIT.html#MONITOREXIT">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     InstructionInstruction">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 }