46174
|
1 |
/*
|
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
7 |
* contributor license agreements. See the NOTICE file distributed with
|
|
8 |
* this work for additional information regarding copyright ownership.
|
|
9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
10 |
* (the "License"); you may not use this file except in compliance with
|
|
11 |
* the License. You may obtain a copy of the License at
|
|
12 |
*
|
|
13 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14 |
*
|
|
15 |
* Unless required by applicable law or agreed to in writing, software
|
|
16 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18 |
* See the License for the specific language governing permissions and
|
|
19 |
* limitations under the License.
|
|
20 |
*/
|
|
21 |
|
|
22 |
package com.sun.org.apache.bcel.internal.generic;
|
|
23 |
|
|
24 |
import com.sun.org.apache.bcel.internal.Const;
|
|
25 |
|
|
26 |
/**
|
|
27 |
* This interface contains shareable instruction objects.
|
|
28 |
*
|
|
29 |
* In order to save memory you can use some instructions multiply,
|
|
30 |
* since they have an immutable state and are directly derived from
|
|
31 |
* Instruction. I.e. they have no instance fields that could be
|
|
32 |
* changed. Since some of these instructions like ICONST_0 occur
|
|
33 |
* very frequently this can save a lot of time and space. This
|
|
34 |
* feature is an adaptation of the FlyWeight design pattern, we
|
|
35 |
* just use an array instead of a factory.
|
|
36 |
*
|
|
37 |
* The Instructions can also accessed directly under their names, so
|
|
38 |
* it's possible to write il.append(Instruction.ICONST_0);
|
|
39 |
*
|
55496
|
40 |
* @version $Id: InstructionConstants.java 1695415 2015-08-12 01:02:39Z chas $
|
46174
|
41 |
*/
|
|
42 |
public final class InstructionConst {
|
|
43 |
|
|
44 |
/**
|
|
45 |
* Predefined instruction objects
|
|
46 |
*/
|
|
47 |
/*
|
|
48 |
* NOTE these are not currently immutable, because Instruction
|
|
49 |
* has mutable protected fields opcode and length.
|
|
50 |
*/
|
|
51 |
public static final Instruction NOP = new NOP();
|
|
52 |
public static final Instruction ACONST_NULL = new ACONST_NULL();
|
|
53 |
public static final Instruction ICONST_M1 = new ICONST(-1);
|
|
54 |
public static final Instruction ICONST_0 = new ICONST(0);
|
|
55 |
public static final Instruction ICONST_1 = new ICONST(1);
|
|
56 |
public static final Instruction ICONST_2 = new ICONST(2);
|
|
57 |
public static final Instruction ICONST_3 = new ICONST(3);
|
|
58 |
public static final Instruction ICONST_4 = new ICONST(4);
|
|
59 |
public static final Instruction ICONST_5 = new ICONST(5);
|
|
60 |
public static final Instruction LCONST_0 = new LCONST(0);
|
|
61 |
public static final Instruction LCONST_1 = new LCONST(1);
|
|
62 |
public static final Instruction FCONST_0 = new FCONST(0);
|
|
63 |
public static final Instruction FCONST_1 = new FCONST(1);
|
|
64 |
public static final Instruction FCONST_2 = new FCONST(2);
|
|
65 |
public static final Instruction DCONST_0 = new DCONST(0);
|
|
66 |
public static final Instruction DCONST_1 = new DCONST(1);
|
|
67 |
public static final ArrayInstruction IALOAD = new IALOAD();
|
|
68 |
public static final ArrayInstruction LALOAD = new LALOAD();
|
|
69 |
public static final ArrayInstruction FALOAD = new FALOAD();
|
|
70 |
public static final ArrayInstruction DALOAD = new DALOAD();
|
|
71 |
public static final ArrayInstruction AALOAD = new AALOAD();
|
|
72 |
public static final ArrayInstruction BALOAD = new BALOAD();
|
|
73 |
public static final ArrayInstruction CALOAD = new CALOAD();
|
|
74 |
public static final ArrayInstruction SALOAD = new SALOAD();
|
|
75 |
public static final ArrayInstruction IASTORE = new IASTORE();
|
|
76 |
public static final ArrayInstruction LASTORE = new LASTORE();
|
|
77 |
public static final ArrayInstruction FASTORE = new FASTORE();
|
|
78 |
public static final ArrayInstruction DASTORE = new DASTORE();
|
|
79 |
public static final ArrayInstruction AASTORE = new AASTORE();
|
|
80 |
public static final ArrayInstruction BASTORE = new BASTORE();
|
|
81 |
public static final ArrayInstruction CASTORE = new CASTORE();
|
|
82 |
public static final ArrayInstruction SASTORE = new SASTORE();
|
|
83 |
public static final StackInstruction POP = new POP();
|
|
84 |
public static final StackInstruction POP2 = new POP2();
|
|
85 |
public static final StackInstruction DUP = new DUP();
|
|
86 |
public static final StackInstruction DUP_X1 = new DUP_X1();
|
|
87 |
public static final StackInstruction DUP_X2 = new DUP_X2();
|
|
88 |
public static final StackInstruction DUP2 = new DUP2();
|
|
89 |
public static final StackInstruction DUP2_X1 = new DUP2_X1();
|
|
90 |
public static final StackInstruction DUP2_X2 = new DUP2_X2();
|
|
91 |
public static final StackInstruction SWAP = new SWAP();
|
|
92 |
public static final ArithmeticInstruction IADD = new IADD();
|
|
93 |
public static final ArithmeticInstruction LADD = new LADD();
|
|
94 |
public static final ArithmeticInstruction FADD = new FADD();
|
|
95 |
public static final ArithmeticInstruction DADD = new DADD();
|
|
96 |
public static final ArithmeticInstruction ISUB = new ISUB();
|
|
97 |
public static final ArithmeticInstruction LSUB = new LSUB();
|
|
98 |
public static final ArithmeticInstruction FSUB = new FSUB();
|
|
99 |
public static final ArithmeticInstruction DSUB = new DSUB();
|
|
100 |
public static final ArithmeticInstruction IMUL = new IMUL();
|
|
101 |
public static final ArithmeticInstruction LMUL = new LMUL();
|
|
102 |
public static final ArithmeticInstruction FMUL = new FMUL();
|
|
103 |
public static final ArithmeticInstruction DMUL = new DMUL();
|
|
104 |
public static final ArithmeticInstruction IDIV = new IDIV();
|
|
105 |
public static final ArithmeticInstruction LDIV = new LDIV();
|
|
106 |
public static final ArithmeticInstruction FDIV = new FDIV();
|
|
107 |
public static final ArithmeticInstruction DDIV = new DDIV();
|
|
108 |
public static final ArithmeticInstruction IREM = new IREM();
|
|
109 |
public static final ArithmeticInstruction LREM = new LREM();
|
|
110 |
public static final ArithmeticInstruction FREM = new FREM();
|
|
111 |
public static final ArithmeticInstruction DREM = new DREM();
|
|
112 |
public static final ArithmeticInstruction INEG = new INEG();
|
|
113 |
public static final ArithmeticInstruction LNEG = new LNEG();
|
|
114 |
public static final ArithmeticInstruction FNEG = new FNEG();
|
|
115 |
public static final ArithmeticInstruction DNEG = new DNEG();
|
|
116 |
public static final ArithmeticInstruction ISHL = new ISHL();
|
|
117 |
public static final ArithmeticInstruction LSHL = new LSHL();
|
|
118 |
public static final ArithmeticInstruction ISHR = new ISHR();
|
|
119 |
public static final ArithmeticInstruction LSHR = new LSHR();
|
|
120 |
public static final ArithmeticInstruction IUSHR = new IUSHR();
|
|
121 |
public static final ArithmeticInstruction LUSHR = new LUSHR();
|
|
122 |
public static final ArithmeticInstruction IAND = new IAND();
|
|
123 |
public static final ArithmeticInstruction LAND = new LAND();
|
|
124 |
public static final ArithmeticInstruction IOR = new IOR();
|
|
125 |
public static final ArithmeticInstruction LOR = new LOR();
|
|
126 |
public static final ArithmeticInstruction IXOR = new IXOR();
|
|
127 |
public static final ArithmeticInstruction LXOR = new LXOR();
|
|
128 |
public static final ConversionInstruction I2L = new I2L();
|
|
129 |
public static final ConversionInstruction I2F = new I2F();
|
|
130 |
public static final ConversionInstruction I2D = new I2D();
|
|
131 |
public static final ConversionInstruction L2I = new L2I();
|
|
132 |
public static final ConversionInstruction L2F = new L2F();
|
|
133 |
public static final ConversionInstruction L2D = new L2D();
|
|
134 |
public static final ConversionInstruction F2I = new F2I();
|
|
135 |
public static final ConversionInstruction F2L = new F2L();
|
|
136 |
public static final ConversionInstruction F2D = new F2D();
|
|
137 |
public static final ConversionInstruction D2I = new D2I();
|
|
138 |
public static final ConversionInstruction D2L = new D2L();
|
|
139 |
public static final ConversionInstruction D2F = new D2F();
|
|
140 |
public static final ConversionInstruction I2B = new I2B();
|
|
141 |
public static final ConversionInstruction I2C = new I2C();
|
|
142 |
public static final ConversionInstruction I2S = new I2S();
|
|
143 |
public static final Instruction LCMP = new LCMP();
|
|
144 |
public static final Instruction FCMPL = new FCMPL();
|
|
145 |
public static final Instruction FCMPG = new FCMPG();
|
|
146 |
public static final Instruction DCMPL = new DCMPL();
|
|
147 |
public static final Instruction DCMPG = new DCMPG();
|
|
148 |
public static final ReturnInstruction IRETURN = new IRETURN();
|
|
149 |
public static final ReturnInstruction LRETURN = new LRETURN();
|
|
150 |
public static final ReturnInstruction FRETURN = new FRETURN();
|
|
151 |
public static final ReturnInstruction DRETURN = new DRETURN();
|
|
152 |
public static final ReturnInstruction ARETURN = new ARETURN();
|
|
153 |
public static final ReturnInstruction RETURN = new RETURN();
|
|
154 |
public static final Instruction ARRAYLENGTH = new ARRAYLENGTH();
|
|
155 |
public static final Instruction ATHROW = new ATHROW();
|
|
156 |
public static final Instruction MONITORENTER = new MONITORENTER();
|
|
157 |
public static final Instruction MONITOREXIT = new MONITOREXIT();
|
|
158 |
|
|
159 |
/** You can use these constants in multiple places safely, if you can guarantee
|
|
160 |
* that you will never alter their internal values, e.g. call setIndex().
|
|
161 |
*/
|
|
162 |
public static final LocalVariableInstruction THIS = new ALOAD(0);
|
|
163 |
public static final LocalVariableInstruction ALOAD_0 = THIS;
|
|
164 |
public static final LocalVariableInstruction ALOAD_1 = new ALOAD(1);
|
|
165 |
public static final LocalVariableInstruction ALOAD_2 = new ALOAD(2);
|
|
166 |
public static final LocalVariableInstruction ILOAD_0 = new ILOAD(0);
|
|
167 |
public static final LocalVariableInstruction ILOAD_1 = new ILOAD(1);
|
|
168 |
public static final LocalVariableInstruction ILOAD_2 = new ILOAD(2);
|
|
169 |
public static final LocalVariableInstruction ASTORE_0 = new ASTORE(0);
|
|
170 |
public static final LocalVariableInstruction ASTORE_1 = new ASTORE(1);
|
|
171 |
public static final LocalVariableInstruction ASTORE_2 = new ASTORE(2);
|
|
172 |
public static final LocalVariableInstruction ISTORE_0 = new ISTORE(0);
|
|
173 |
public static final LocalVariableInstruction ISTORE_1 = new ISTORE(1);
|
|
174 |
public static final LocalVariableInstruction ISTORE_2 = new ISTORE(2);
|
|
175 |
|
|
176 |
/** Get object via its opcode, for immutable instructions like
|
|
177 |
* branch instructions entries are set to null.
|
|
178 |
*/
|
|
179 |
private static final Instruction[] INSTRUCTIONS = new Instruction[256];
|
|
180 |
|
|
181 |
static {
|
|
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 |
private InstructionConst() { } // non-instantiable
|
|
292 |
|
|
293 |
/**
|
|
294 |
* Gets the Instruction.
|
|
295 |
* @param index the index, e.g. {@link Const#RETURN}
|
|
296 |
* @return the entry from the private INSTRUCTIONS table
|
|
297 |
*/
|
|
298 |
public static Instruction getInstruction(final int index) {
|
|
299 |
return INSTRUCTIONS[index];
|
|
300 |
}
|
|
301 |
}
|