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