1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.jdo.impl.enhancer.classfile;
19
20 import java.io.PrintStream;
21 import java.util.Stack;
22
23 /***
24 * A java VM instruction which takes no immediate operands.
25 */
26 public class InsnSingle extends Insn {
27
28 public int nStackArgs() {
29 return VMOp.ops[opcode()].nStackArgs();
30 }
31
32 public int nStackResults() {
33 return VMOp.ops[opcode()].nStackResults();
34 }
35
36 /***
37 * What are the types of the stack operands ?
38 */
39 public String argTypes() {
40 return VMOp.ops[opcode()].argTypes();
41 }
42
43 /***
44 * What are the types of the stack results?
45 */
46 public String resultTypes() {
47 return VMOp.ops[opcode()].resultTypes();
48 }
49
50 public boolean branches() {
51 switch (opcode()) {
52 case opc_ireturn:
53 case opc_lreturn:
54 case opc_freturn:
55 case opc_dreturn:
56 case opc_areturn:
57 case opc_return:
58 case opc_athrow:
59 return true;
60 default:
61 return false;
62 }
63 }
64
65 /***
66 * Compares this instance with another for structural equality.
67 */
68
69 public boolean isEqual(Stack msg, Object obj) {
70 if (!(obj instanceof InsnSingle)) {
71 msg.push("obj/obj.getClass() = "
72 + (obj == null ? null : obj.getClass()));
73 msg.push("this.getClass() = "
74 + this.getClass());
75 return false;
76 }
77 InsnSingle other = (InsnSingle)obj;
78
79 if (!super.isEqual(msg, other)) {
80 return false;
81 }
82 return true;
83 }
84
85 /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">
86
87 void print (PrintStream out, int indent) {
88 ClassPrint.spaces(out, indent);
89 out.println(offset() + " " + opName(opcode()));
90 }
91
92 int store(byte[] buf, int index) {
93 buf[index] = (byte) opcode();
94 return index+1;
95 }
96
97 int size() {
98 return 1;
99 }
100
101
102
103
104 InsnSingle(int theOpcode) {
105 this(theOpcode, NO_OFFSET);
106 }
107
108
109
110 InsnSingle(int theOpcode, int theOffset) {
111 super(theOpcode, theOffset);
112
113 switch (theOpcode) {
114 case opc_nop:
115 case opc_aconst_null:
116 case opc_iconst_m1:
117 case opc_iconst_0:
118 case opc_iconst_1:
119 case opc_iconst_2:
120 case opc_iconst_3:
121 case opc_iconst_4:
122 case opc_iconst_5:
123 case opc_lconst_0:
124 case opc_lconst_1:
125 case opc_fconst_0:
126 case opc_fconst_1:
127 case opc_fconst_2:
128 case opc_dconst_0:
129 case opc_dconst_1:
130 case opc_iload_0:
131 case opc_iload_1:
132 case opc_iload_2:
133 case opc_iload_3:
134 case opc_lload_0:
135 case opc_lload_1:
136 case opc_lload_2:
137 case opc_lload_3:
138 case opc_fload_0:
139 case opc_fload_1:
140 case opc_fload_2:
141 case opc_fload_3:
142 case opc_dload_0:
143 case opc_dload_1:
144 case opc_dload_2:
145 case opc_dload_3:
146 case opc_aload_0:
147 case opc_aload_1:
148 case opc_aload_2:
149 case opc_aload_3:
150 case opc_iaload:
151 case opc_laload:
152 case opc_faload:
153 case opc_daload:
154 case opc_aaload:
155 case opc_baload:
156 case opc_caload:
157 case opc_saload:
158 case opc_istore_0:
159 case opc_istore_1:
160 case opc_istore_2:
161 case opc_istore_3:
162 case opc_lstore_0:
163 case opc_lstore_1:
164 case opc_lstore_2:
165 case opc_lstore_3:
166 case opc_fstore_0:
167 case opc_fstore_1:
168 case opc_fstore_2:
169 case opc_fstore_3:
170 case opc_dstore_0:
171 case opc_dstore_1:
172 case opc_dstore_2:
173 case opc_dstore_3:
174 case opc_astore_0:
175 case opc_astore_1:
176 case opc_astore_2:
177 case opc_astore_3:
178 case opc_iastore:
179 case opc_lastore:
180 case opc_fastore:
181 case opc_dastore:
182 case opc_aastore:
183 case opc_bastore:
184 case opc_castore:
185 case opc_sastore:
186 case opc_pop:
187 case opc_pop2:
188 case opc_dup:
189 case opc_dup_x1:
190 case opc_dup_x2:
191 case opc_dup2:
192 case opc_dup2_x1:
193 case opc_dup2_x2:
194 case opc_swap:
195 case opc_iadd:
196 case opc_ladd:
197 case opc_fadd:
198 case opc_dadd:
199 case opc_isub:
200 case opc_lsub:
201 case opc_fsub:
202 case opc_dsub:
203 case opc_imul:
204 case opc_lmul:
205 case opc_fmul:
206 case opc_dmul:
207 case opc_idiv:
208 case opc_ldiv:
209 case opc_fdiv:
210 case opc_ddiv:
211 case opc_irem:
212 case opc_lrem:
213 case opc_frem:
214 case opc_drem:
215 case opc_ineg:
216 case opc_lneg:
217 case opc_fneg:
218 case opc_dneg:
219 case opc_ishl:
220 case opc_lshl:
221 case opc_ishr:
222 case opc_lshr:
223 case opc_iushr:
224 case opc_lushr:
225 case opc_iand:
226 case opc_land:
227 case opc_ior:
228 case opc_lor:
229 case opc_ixor:
230 case opc_lxor:
231 case opc_i2l:
232 case opc_i2f:
233 case opc_i2d:
234 case opc_l2i:
235 case opc_l2f:
236 case opc_l2d:
237 case opc_f2i:
238 case opc_f2l:
239 case opc_f2d:
240 case opc_d2i:
241 case opc_d2l:
242 case opc_d2f:
243 case opc_i2b:
244 case opc_i2c:
245 case opc_i2s:
246 case opc_lcmp:
247 case opc_fcmpl:
248 case opc_fcmpg:
249 case opc_dcmpl:
250 case opc_dcmpg:
251 case opc_ireturn:
252 case opc_lreturn:
253 case opc_freturn:
254 case opc_dreturn:
255 case opc_areturn:
256 case opc_return:
257 case opc_xxxunusedxxx:
258 case opc_arraylength:
259 case opc_athrow:
260 case opc_monitorenter:
261 case opc_monitorexit:
262 break;
263
264 default:
265 throw new InsnError ("attempt to create an " + opName(opcode()) +
266 " without specifying the required operands");
267 }
268 }
269 }