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