1 cananian 1.1.2.1  // Qop.java, created Mon Nov  9 22:36:21 1998 by cananian
  2 cananian 1.1.2.1  // Copyright (C) 1998 C. Scott Ananian <cananian@alumni.princeton.edu>
  3 cananian 1.1.2.1  // Licensed under the terms of the GNU GPL; see COPYING for details.
  4 cananian 1.1.2.1  package harpoon.IR.Quads;
  5 cananian 1.1.2.1  
  6 cananian 1.1.2.5  import harpoon.ClassFile.HClass;
  7 cananian 1.1.2.1  /**
  8 cananian 1.1.2.1   * <code>Qop</code> is an enumerated type for the various kinds of
  9 cananian 1.1.2.10  * <code>OPER</code> opcodes.  The basic rationale is to use a
 10 cananian 1.1.2.10  * minimal set of opcodes to simplify later analysis.
 11 cananian 1.1.2.8   * <p>
 12 cananian 1.1.2.8   * Note that (x - y) is uniformly expressed as (x + (-y)), and that
 13 cananian 1.1.2.9   * (~x) is typically expressed (compiler-dependent) as (x ^ (-1)).
 14 cananian 1.1.2.8   * There is also a minimal set of comparison operations; all other
 15 cananian 1.1.2.8   * comparisons can be synthesized from the ones present.  Note that
 16 cananian 1.1.2.8   * floating-point (float/double) comparisons have special behaviors
 17 cananian 1.1.2.8   * when NaN is an operand.  Note also that one each of IAND/IOR and
 18 cananian 1.1.2.8   * LAND/LOR could be removed, but the translation involved too many
 19 cananian 1.1.2.8   * steps to be deemed worthwhile.
 20 cananian 1.1.2.1   * 
 21 cananian 1.1.2.14  * @author  C. Scott Ananian <cananian@alumni.princeton.edu>
 22 cananian 1.2       * @version $Id: Qop.java,v 1.2 2002/02/25 21:05:12 cananian Exp $
 23 cananian 1.1.2.1   */
 24 cananian 1.1.2.1  public abstract class Qop  {
 25 cananian 1.1.2.6      /** Compares references for equality. */
 26 cananian 1.1.2.1      public final static int ACMPEQ = 0;
 27 cananian 1.1.2.6      /** Converts a double to a float. */
 28 cananian 1.1.2.1      public final static int D2F = 1;
 29 cananian 1.1.2.6      /** Converts a double to an int. */
 30 cananian 1.1.2.1      public final static int D2I = 2;
 31 cananian 1.1.2.6      /** Converts a double to a long. */
 32 cananian 1.1.2.1      public final static int D2L = 3;
 33 cananian 1.1.2.6      /** Computes the sum of two double values. */
 34 cananian 1.1.2.1      public final static int DADD = 4;
 35 cananian 1.1.2.6      /** Evaluates to true if double values are equal and neither is NaN, 
 36 cananian 1.1.2.6       *  or false otherwise. */
 37 cananian 1.1.2.1      public final static int DCMPEQ = 5;
 38 cananian 1.1.2.6      /** Evaluates to true if first double value is greater than or
 39 cananian 1.1.2.6       *  equal to the second double value and neither is NaN, or false
 40 cananian 1.1.2.6       *  otherwise. */
 41 cananian 1.1.2.1      public final static int DCMPGE = 6;
 42 cananian 1.1.2.6      /** Evaluates to true if first double value is greater than the
 43 cananian 1.1.2.6       *  second double value and neither is NaN, or false otherwise. */
 44 cananian 1.1.2.1      public final static int DCMPGT = 7;
 45 cananian 1.1.2.6      /** Computes the quotient of two double values. */
 46 cananian 1.1.2.1      public final static int DDIV = 8;
 47 cananian 1.1.2.6      /** Computes the product of two double values. */
 48 cananian 1.1.2.1      public final static int DMUL = 9;
 49 cananian 1.1.2.6      /** Computes the negation of a double value. */
 50 cananian 1.1.2.1      public final static int DNEG = 10;
 51 cananian 1.1.2.6      /** Computes the remainder of two double values. */
 52 cananian 1.1.2.1      public final static int DREM = 11;
 53 cananian 1.1.2.6      /** Converts a float to a double. */
 54 cananian 1.1.2.1      public final static int F2D = 13;
 55 cananian 1.1.2.6      /** Converts a float to an int. */
 56 cananian 1.1.2.1      public final static int F2I = 14;
 57 cananian 1.1.2.6      /** Converts a float to a long. */
 58 cananian 1.1.2.1      public final static int F2L = 15;
 59 cananian 1.1.2.6      /** Computes the sum of two float values. */
 60 cananian 1.1.2.1      public final static int FADD = 16;
 61 cananian 1.1.2.13     /** Evaluates to true if the float values are equal and neither is NaN,
 62 cananian 1.1.2.6       *  or false otherwise. */
 63 cananian 1.1.2.1      public final static int FCMPEQ = 17;
 64 cananian 1.1.2.6      /** Evaluates to true if the first float value is greater than or equal
 65 cananian 1.1.2.6       *  to the second float value and neither is NaN, or false otherwise. */
 66 cananian 1.1.2.1      public final static int FCMPGE = 18;
 67 cananian 1.1.2.6      /** Evaluates to true if the first float value is greater than the
 68 cananian 1.1.2.6       *  second float value and neither is NaN, or false otherwise. */
 69 cananian 1.1.2.1      public final static int FCMPGT = 19;
 70 cananian 1.1.2.6      /** Computes the quotient of two float values. */
 71 cananian 1.1.2.1      public final static int FDIV = 20;
 72 cananian 1.1.2.6      /** Computes the product of two float values. */
 73 cananian 1.1.2.1      public final static int FMUL = 21;
 74 cananian 1.1.2.6      /** Computes the negation of a float value. */
 75 cananian 1.1.2.1      public final static int FNEG = 22;
 76 cananian 1.1.2.6      /** Computes the remainder of two float values. */
 77 cananian 1.1.2.1      public final static int FREM = 23;
 78 cananian 1.1.2.6      /** Converts an int to a byte.  Result is still int type, but it is
 79 cananian 1.1.2.6       *  truncated to 8 bits, then sign-extended. */
 80 cananian 1.1.2.1      public final static int I2B = 25;
 81 cananian 1.1.2.6      /** Converts an int to a character.  Result is still int type, but is
 82 cananian 1.1.2.6       *  truncated to 16 bits.  No sign extension. */
 83 cananian 1.1.2.1      public final static int I2C = 26;
 84 cananian 1.1.2.6      /** Converts an int to a double. */
 85 cananian 1.1.2.1      public final static int I2D = 27;
 86 cananian 1.1.2.6      /** Converts an int to a float. */
 87 cananian 1.1.2.1      public final static int I2F = 28;
 88 cananian 1.1.2.6      /** Converts an int to a long. */
 89 cananian 1.1.2.1      public final static int I2L = 29;
 90 cananian 1.1.2.6      /** Converts an int to a short.  Result is still int type, but is
 91 cananian 1.1.2.6       *  truncated to 16 bits, then sign extended. */
 92 cananian 1.1.2.1      public final static int I2S = 30;
 93 cananian 1.1.2.6      /** Computes the sum of two int values. */
 94 cananian 1.1.2.1      public final static int IADD = 31;
 95 cananian 1.1.2.6      /** Computes the binary-AND of two int values. */
 96 cananian 1.1.2.1      public final static int IAND = 32;
 97 cananian 1.1.2.6      /** Evaluates to true if the two int values are equal, or false
 98 cananian 1.1.2.6       *  otherwise. */
 99 cananian 1.1.2.1      public final static int ICMPEQ = 33;
100 cananian 1.1.2.6      /** Evalutates to true if the first int value is greater than the
101 cananian 1.1.2.6       *  second int value, or false otherwise. */
102 cananian 1.1.2.1      public final static int ICMPGT = 35;
103 cananian 1.1.2.6      /** Computes the int quotient of two int values. */
104 cananian 1.1.2.1      public final static int IDIV = 36;
105 cananian 1.1.2.6      /** Computes the product of two int values. */
106 cananian 1.1.2.1      public final static int IMUL = 37;
107 cananian 1.1.2.6      /** Computes the negation of an int value. */
108 cananian 1.1.2.1      public final static int INEG = 38;
109 cananian 1.1.2.6      /** Computes the binary-OR of two int values. */
110 cananian 1.1.2.1      public final static int IOR = 39;
111 cananian 1.1.2.6      /** Computes the remainder of two int values. */
112 cananian 1.1.2.1      public final static int IREM = 40;
113 cananian 1.1.2.6      /** Computes the value of the first int value shifted left by the number
114 cananian 1.1.2.8       *  of bits specified in the low five bits of the second int value.
115 cananian 1.1.2.8       *  That is, <code>( 1 << 34 ) == 4</code>. 
116 cananian 1.1.2.8       *  Also, <code>(x << -1) == (x << 31)</code>.
117 cananian 1.1.2.8       */
118 cananian 1.1.2.1      public final static int ISHL = 41;
119 cananian 1.1.2.8      /** Computes the value of the first int value shifted right with 
120 cananian 1.1.2.8       *  sign extension by the number of bits specified in the low five bits
121 cananian 1.1.2.8       *  of the second int value.
122 cananian 1.1.2.8       *  That is, <code>( -4 >> 33 ) == -2</code>.
123 cananian 1.1.2.8       *  Also, <code>(x >> -1) == (x >> 31)</code>.
124 cananian 1.1.2.8       */
125 cananian 1.1.2.1      public final static int ISHR = 42;
126 cananian 1.1.2.8      /** Computes the value of the first int value shifted right without
127 cananian 1.1.2.8       *  sign extension by the number of bits specified in the low five bits
128 cananian 1.1.2.8       *  of the second int value.
129 cananian 1.1.2.8       *  That is, <code>( -4 >>> 30) == 3</code>.
130 cananian 1.1.2.8       *  Also, <code>(x >>> -1) == (x >>> 31)</code>.
131 cananian 1.1.2.8       */
132 cananian 1.1.2.1      public final static int IUSHR = 44;
133 cananian 1.1.2.6      /** Computes the binary-XOR of two int values. */
134 cananian 1.1.2.1      public final static int IXOR = 45;
135 cananian 1.1.2.6      /** Converts a long to a double. */
136 cananian 1.1.2.1      public final static int L2D = 46;
137 cananian 1.1.2.6      /** Converts a long to a float. */
138 cananian 1.1.2.1      public final static int L2F = 47;
139 cananian 1.1.2.6      /** Converts a long to an int. */
140 cananian 1.1.2.1      public final static int L2I = 48;
141 cananian 1.1.2.6      /** Computes the sum of two long values. */
142 cananian 1.1.2.1      public final static int LADD = 49;
143 cananian 1.1.2.6      /** Computes the binary-AND of two long values. */
144 cananian 1.1.2.1      public final static int LAND = 50;
145 cananian 1.1.2.6      /** Evaluates to true if the two long values are equal, or 
146 cananian 1.1.2.6       *  false otherwise. */
147 cananian 1.1.2.1      public final static int LCMPEQ = 51;
148 cananian 1.1.2.6      /** Evaluates to true if the first long value is greater than the 
149 cananian 1.1.2.6       *  second, or false otherwise. */
150 cananian 1.1.2.1      public final static int LCMPGT = 53;
151 cananian 1.1.2.6      /** Computes the quotient of two long values. */
152 cananian 1.1.2.1      public final static int LDIV = 54;
153 cananian 1.1.2.6      /** Computes the product of two long values. */
154 cananian 1.1.2.1      public final static int LMUL = 55;
155 cananian 1.1.2.6      /** Computes the negation of a long value. */
156 cananian 1.1.2.1      public final static int LNEG = 56;
157 cananian 1.1.2.6      /** Computes the binary-OR of two long values. */
158 cananian 1.1.2.1      public final static int LOR = 57;
159 cananian 1.1.2.6      /** Computes the remainder of two long values. */
160 cananian 1.1.2.1      public final static int LREM = 58;
161 cananian 1.1.2.6      /** Computes the value of the first long value shifted left by the
162 cananian 1.1.2.11      *  number of bits specified in the low six bits of the second 
163 cananian 1.1.2.11      *  <b>int</b> value.
164 cananian 1.1.2.8       *  That is, <code>(1 << 66) == 4</code>.
165 cananian 1.1.2.8       *  Also, <code>(x << -1) == (x << 63)</code>.
166 cananian 1.1.2.8       */
167 cananian 1.1.2.1      public final static int LSHL = 59;
168 cananian 1.1.2.8      /** Computes the value of the first long value shifted right with
169 cananian 1.1.2.8       *  sign extension by the number of bits specified in the low six bits
170 cananian 1.1.2.11      *  of the second <b>int</b> value.
171 cananian 1.1.2.8       *  That is, <code>(-4 >> 65) == -2</code>.
172 cananian 1.1.2.8       *  Also, <code>(x >> -1) == (x >> 63)</code>.
173 cananian 1.1.2.8       */
174 cananian 1.1.2.1      public final static int LSHR = 60;
175 cananian 1.1.2.8      /** Computes the value of the first long value shifted right without
176 cananian 1.1.2.8       *  sign extension by the number of bits specified in the low six bits
177 cananian 1.1.2.11      *  of the second <b>int</b> value.
178 cananian 1.1.2.8       *  That is, <code>(-4 >>> 62) == 3</code>.
179 cananian 1.1.2.8       *  Also, <code>(x >>> -1) == (x >>> 63)</code>.
180 cananian 1.1.2.8       */
181 cananian 1.1.2.1      public final static int LUSHR = 62;
182 cananian 1.1.2.6      /** Computes the binary-XOR of two long values. */
183 cananian 1.1.2.1      public final static int LXOR = 63;
184 cananian 1.1.2.2  
185 cananian 1.1.2.6      /** Determines if a given <code>Qop</code> value is valid. */
186 cananian 1.1.2.2      public static boolean isValid(int v) {
187 cananian 1.1.2.2          return (0<=v) && (v<=LXOR);
188 cananian 1.1.2.2      }
189 cananian 1.1.2.1  
190 cananian 1.1.2.6      /** Converts the enumerated <code>Qop</code> value to a descriptive
191 cananian 1.1.2.6       *  string. */
192 cananian 1.1.2.1      public static String toString(int v) {
193 cananian 1.1.2.1          switch(v) {
194 cananian 1.1.2.1          case ACMPEQ:    return "acmpeq";
195 cananian 1.1.2.1          case D2F:       return "d2f";
196 cananian 1.1.2.1          case D2I:       return "d2i";
197 cananian 1.1.2.1          case D2L:       return "d2l";
198 cananian 1.1.2.1          case DADD:      return "dadd";
199 cananian 1.1.2.1          case DCMPEQ:    return "dcmpeq";
200 cananian 1.1.2.1          case DCMPGE:    return "dcmpge";
201 cananian 1.1.2.1          case DCMPGT:    return "dcmpgt";
202 cananian 1.1.2.1          case DDIV:      return "ddiv";
203 cananian 1.1.2.1          case DMUL:      return "dmul";
204 cananian 1.1.2.1          case DNEG:      return "dneg";
205 cananian 1.1.2.1          case DREM:      return "drem";
206 cananian 1.1.2.1          case F2D:       return "f2d";
207 cananian 1.1.2.1          case F2I:       return "f2i";
208 cananian 1.1.2.1          case F2L:       return "f2l";
209 cananian 1.1.2.1          case FADD:      return "fadd";
210 cananian 1.1.2.1          case FCMPEQ:    return "fcmpeq";
211 cananian 1.1.2.1          case FCMPGE:    return "fcmpge";
212 cananian 1.1.2.1          case FCMPGT:    return "fcmpgt";
213 cananian 1.1.2.1          case FDIV:      return "fdiv";
214 cananian 1.1.2.1          case FMUL:      return "fmul";
215 cananian 1.1.2.1          case FNEG:      return "fneg";
216 cananian 1.1.2.1          case FREM:      return "frem";
217 cananian 1.1.2.1          case I2B:       return "i2b";
218 cananian 1.1.2.1          case I2C:       return "i2c";
219 cananian 1.1.2.1          case I2D:       return "i2d";
220 cananian 1.1.2.1          case I2F:       return "i2f";
221 cananian 1.1.2.1          case I2L:       return "i2l";
222 cananian 1.1.2.1          case I2S:       return "i2s";
223 cananian 1.1.2.1          case IADD:      return "iadd";
224 cananian 1.1.2.1          case IAND:      return "iand";
225 cananian 1.1.2.1          case ICMPEQ:    return "icmpeq";
226 cananian 1.1.2.1          case ICMPGT:    return "icmpgt";
227 cananian 1.1.2.1          case IDIV:      return "idiv";
228 cananian 1.1.2.1          case IMUL:      return "imul";
229 cananian 1.1.2.1          case INEG:      return "ineg";
230 cananian 1.1.2.1          case IOR:       return "ior";
231 cananian 1.1.2.1          case IREM:      return "irem";
232 cananian 1.1.2.1          case ISHL:      return "ishl";
233 cananian 1.1.2.1          case ISHR:      return "ishr";
234 cananian 1.1.2.1          case IUSHR:     return "iushr";
235 cananian 1.1.2.1          case IXOR:      return "ixor";
236 cananian 1.1.2.1          case L2D:       return "l2d";
237 cananian 1.1.2.1          case L2F:       return "l2f";
238 cananian 1.1.2.1          case L2I:       return "l2i";
239 cananian 1.1.2.1          case LADD:      return "ladd";
240 cananian 1.1.2.1          case LAND:      return "land";
241 cananian 1.1.2.1          case LCMPEQ:    return "lcmpeq";
242 cananian 1.1.2.1          case LCMPGT:    return "lcmpgt";
243 cananian 1.1.2.1          case LDIV:      return "ldiv";
244 cananian 1.1.2.1          case LMUL:      return "lmul";
245 cananian 1.1.2.1          case LNEG:      return "lneg";
246 cananian 1.1.2.1          case LOR:       return "lor";
247 cananian 1.1.2.1          case LREM:      return "lrem";
248 cananian 1.1.2.1          case LSHL:      return "lshl";
249 cananian 1.1.2.1          case LSHR:      return "lshr";
250 cananian 1.1.2.1          case LUSHR:     return "lushr";
251 cananian 1.1.2.1          case LXOR:      return "lxor";
252 cananian 1.1.2.6          default:        throw new RuntimeException("Unknown QOp type: "+v);
253 cananian 1.1.2.1          }
254 cananian 1.1.2.1      }
255 cananian 1.1.2.6      /** Returns the enumerated <code>Qop</code> that corresponds to a given
256 cananian 1.1.2.6       *  descriptive string. */
257 cananian 1.1.2.1      public static int forString(String op) {
258 cananian 1.1.2.1          Integer r = (Integer) h.get(op);
259 cananian 1.1.2.6          if (r==null) throw new RuntimeException("Unknown QOp name: "+op);
260 cananian 1.1.2.1          return r.intValue();
261 cananian 1.1.2.1      }
262 cananian 1.1.2.12     private static final java.util.Map h = new java.util.HashMap();
263 cananian 1.1.2.1      static {
264 cananian 1.1.2.1          h.put("acmpeq", new Integer(ACMPEQ));
265 cananian 1.1.2.1          h.put("d2f", new Integer(D2F));
266 cananian 1.1.2.1          h.put("d2i", new Integer(D2I));
267 cananian 1.1.2.1          h.put("d2l", new Integer(D2L));
268 cananian 1.1.2.1          h.put("dadd", new Integer(DADD));
269 cananian 1.1.2.1          h.put("dcmpeq", new Integer(DCMPEQ));
270 cananian 1.1.2.1          h.put("dcmpge", new Integer(DCMPGE));
271 cananian 1.1.2.1          h.put("dcmpgt", new Integer(DCMPGT));
272 cananian 1.1.2.1          h.put("ddiv", new Integer(DDIV));
273 cananian 1.1.2.1          h.put("dmul", new Integer(DMUL));
274 cananian 1.1.2.1          h.put("dneg", new Integer(DNEG));
275 cananian 1.1.2.1          h.put("drem", new Integer(DREM));
276 cananian 1.1.2.1          h.put("f2d", new Integer(F2D));
277 cananian 1.1.2.1          h.put("f2i", new Integer(F2I));
278 cananian 1.1.2.1          h.put("f2l", new Integer(F2L));
279 cananian 1.1.2.1          h.put("fadd", new Integer(FADD));
280 cananian 1.1.2.1          h.put("fcmpeq", new Integer(FCMPEQ));
281 cananian 1.1.2.1          h.put("fcmpge", new Integer(FCMPGE));
282 cananian 1.1.2.1          h.put("fcmpgt", new Integer(FCMPGT));
283 cananian 1.1.2.1          h.put("fdiv", new Integer(FDIV));
284 cananian 1.1.2.1          h.put("fmul", new Integer(FMUL));
285 cananian 1.1.2.1          h.put("fneg", new Integer(FNEG));
286 cananian 1.1.2.1          h.put("frem", new Integer(FREM));
287 cananian 1.1.2.1          h.put("i2b", new Integer(I2B));
288 cananian 1.1.2.1          h.put("i2c", new Integer(I2C));
289 cananian 1.1.2.1          h.put("i2d", new Integer(I2D));
290 cananian 1.1.2.1          h.put("i2f", new Integer(I2F));
291 cananian 1.1.2.1          h.put("i2l", new Integer(I2L));
292 cananian 1.1.2.1          h.put("i2s", new Integer(I2S));
293 cananian 1.1.2.1          h.put("iadd", new Integer(IADD));
294 cananian 1.1.2.1          h.put("iand", new Integer(IAND));
295 cananian 1.1.2.1          h.put("icmpeq", new Integer(ICMPEQ));
296 cananian 1.1.2.1          h.put("icmpgt", new Integer(ICMPGT));
297 cananian 1.1.2.1          h.put("idiv", new Integer(IDIV));
298 cananian 1.1.2.1          h.put("imul", new Integer(IMUL));
299 cananian 1.1.2.1          h.put("ineg", new Integer(INEG));
300 cananian 1.1.2.1          h.put("ior", new Integer(IOR));
301 cananian 1.1.2.1          h.put("irem", new Integer(IREM));
302 cananian 1.1.2.1          h.put("ishl", new Integer(ISHL));
303 cananian 1.1.2.1          h.put("ishr", new Integer(ISHR));
304 cananian 1.1.2.1          h.put("iushr", new Integer(IUSHR));
305 cananian 1.1.2.1          h.put("ixor", new Integer(IXOR));
306 cananian 1.1.2.1          h.put("l2d", new Integer(L2D));
307 cananian 1.1.2.1          h.put("l2f", new Integer(L2F));
308 cananian 1.1.2.1          h.put("l2i", new Integer(L2I));
309 cananian 1.1.2.1          h.put("ladd", new Integer(LADD));
310 cananian 1.1.2.1          h.put("land", new Integer(LAND));
311 cananian 1.1.2.1          h.put("lcmpeq", new Integer(LCMPEQ));
312 cananian 1.1.2.1          h.put("lcmpgt", new Integer(LCMPGT));
313 cananian 1.1.2.1          h.put("ldiv", new Integer(LDIV));
314 cananian 1.1.2.1          h.put("lmul", new Integer(LMUL));
315 cananian 1.1.2.1          h.put("lneg", new Integer(LNEG));
316 cananian 1.1.2.1          h.put("lor", new Integer(LOR));
317 cananian 1.1.2.1          h.put("lrem", new Integer(LREM));
318 cananian 1.1.2.1          h.put("lshl", new Integer(LSHL));
319 cananian 1.1.2.1          h.put("lshr", new Integer(LSHR));
320 cananian 1.1.2.1          h.put("lushr", new Integer(LUSHR));
321 cananian 1.1.2.1          h.put("lxor", new Integer(LXOR));
322 cananian 1.1.2.1      }
323 cananian 1.1.2.5      ///////////////////////////////////
324 cananian 1.1.2.5      // Evaluation functions.
325 cananian 1.1.2.5  
326 cananian 1.1.2.5      /** Determines the result type of an <code>OPER</code>. */
327 cananian 1.1.2.5      public static HClass resultType(int v) {
328 cananian 1.1.2.5          switch(v) {
329 cananian 1.1.2.6              // boolean return type (input to CJMPs):
330 cananian 1.1.2.5          case ACMPEQ:
331 cananian 1.1.2.5          case DCMPEQ:
332 cananian 1.1.2.5          case DCMPGE:
333 cananian 1.1.2.5          case DCMPGT:
334 cananian 1.1.2.5          case FCMPEQ:
335 cananian 1.1.2.5          case FCMPGE:
336 cananian 1.1.2.5          case FCMPGT:
337 cananian 1.1.2.5          case ICMPEQ:
338 cananian 1.1.2.5          case ICMPGT:
339 cananian 1.1.2.5          case LCMPEQ:
340 cananian 1.1.2.5          case LCMPGT:
341 cananian 1.1.2.5              return HClass.Boolean;
342 cananian 1.1.2.6              // float return type:
343 cananian 1.1.2.5          case D2F:
344 cananian 1.1.2.5          case FADD:
345 cananian 1.1.2.5          case FDIV:
346 cananian 1.1.2.5          case FMUL:
347 cananian 1.1.2.5          case FNEG:
348 cananian 1.1.2.5          case FREM:
349 cananian 1.1.2.5          case I2F:
350 cananian 1.1.2.5          case L2F:
351 cananian 1.1.2.5              return HClass.Float;
352 cananian 1.1.2.6              // int return type:
353 cananian 1.1.2.5          case D2I:
354 cananian 1.1.2.5          case F2I:
355 cananian 1.1.2.5          case I2B:
356 cananian 1.1.2.5          case I2C:
357 cananian 1.1.2.5          case I2S:
358 cananian 1.1.2.5          case IADD:
359 cananian 1.1.2.5          case IAND:
360 cananian 1.1.2.5          case IDIV:
361 cananian 1.1.2.5          case IMUL:
362 cananian 1.1.2.5          case INEG:
363 cananian 1.1.2.5          case IOR:
364 cananian 1.1.2.5          case IREM:
365 cananian 1.1.2.5          case ISHL:
366 cananian 1.1.2.5          case ISHR:
367 cananian 1.1.2.5          case IUSHR:
368 cananian 1.1.2.5          case IXOR:
369 cananian 1.1.2.5          case L2I:
370 cananian 1.1.2.5              return HClass.Int;
371 cananian 1.1.2.6              // long return type:
372 cananian 1.1.2.5          case D2L:
373 cananian 1.1.2.5          case F2L:
374 cananian 1.1.2.5          case I2L:
375 cananian 1.1.2.5          case LADD:
376 cananian 1.1.2.5          case LAND:
377 cananian 1.1.2.5          case LDIV:
378 cananian 1.1.2.5          case LMUL:
379 cananian 1.1.2.5          case LNEG:
380 cananian 1.1.2.5          case LOR:
381 cananian 1.1.2.5          case LREM:
382 cananian 1.1.2.5          case LSHL:
383 cananian 1.1.2.5          case LSHR:
384 cananian 1.1.2.5          case LUSHR:
385 cananian 1.1.2.5          case LXOR:
386 cananian 1.1.2.5              return HClass.Long;
387 cananian 1.1.2.6              // double return type:
388 cananian 1.1.2.5          case DADD:
389 cananian 1.1.2.5          case DDIV:
390 cananian 1.1.2.5          case DMUL:
391 cananian 1.1.2.5          case DNEG:
392 cananian 1.1.2.5          case DREM:
393 cananian 1.1.2.5          case F2D:
394 cananian 1.1.2.5          case I2D:
395 cananian 1.1.2.5          case L2D:
396 cananian 1.1.2.5              return HClass.Double;
397 cananian 1.1.2.6          default:        throw new RuntimeException("Unknown QOp type: "+v);
398 cananian 1.1.2.5          }
399 cananian 1.1.2.5      }
400 cananian 1.1.2.5      /** Evaluates a constant value for the result of an <code>OPER</code>, 
401 cananian 1.1.2.5       *  given constant values for the operands. */
402 cananian 1.1.2.5      public static Object evaluate(int opc, Object[] opd) {
403 cananian 1.1.2.5          switch(opc) {
404 cananian 1.1.2.5          case ACMPEQ:    return _b( Eval.acmpeq  (opd[0], opd[1]));
405 cananian 1.1.2.5          case D2F:       return _f( Eval.d2f     (_d(opd[0])));
406 cananian 1.1.2.5          case D2I:       return _i( Eval.d2i     (_d(opd[0])));
407 cananian 1.1.2.5          case D2L:       return _l( Eval.d2l     (_d(opd[0])));
408 cananian 1.1.2.5          case DADD:      return _d( Eval.dadd    (_d(opd[0]), _d(opd[1])));
409 cananian 1.1.2.5          case DCMPEQ:    return _b( Eval.dcmpeq  (_d(opd[0]), _d(opd[1])));
410 cananian 1.1.2.5          case DCMPGE:    return _b( Eval.dcmpge  (_d(opd[0]), _d(opd[1])));
411 cananian 1.1.2.5          case DCMPGT:    return _b( Eval.dcmpgt  (_d(opd[0]), _d(opd[1])));
412 cananian 1.1.2.5          case DDIV:      return _d( Eval.ddiv    (_d(opd[0]), _d(opd[1])));
413 cananian 1.1.2.5          case DMUL:      return _d( Eval.dmul    (_d(opd[0]), _d(opd[1])));
414 cananian 1.1.2.5          case DNEG:      return _d( Eval.dneg    (_d(opd[0])));
415 cananian 1.1.2.5          case DREM:      return _d( Eval.drem    (_d(opd[0]), _d(opd[1])));
416 cananian 1.1.2.5          case F2D:       return _d( Eval.f2d     (_f(opd[0])));
417 cananian 1.1.2.5          case F2I:       return _i( Eval.f2i     (_f(opd[0])));
418 cananian 1.1.2.5          case F2L:       return _l( Eval.f2l     (_f(opd[0])));
419 cananian 1.1.2.5          case FADD:      return _f( Eval.fadd    (_f(opd[0]), _f(opd[1])));
420 cananian 1.1.2.5          case FCMPEQ:    return _b( Eval.fcmpeq  (_f(opd[0]), _f(opd[1])));
421 cananian 1.1.2.5          case FCMPGE:    return _b( Eval.fcmpge  (_f(opd[0]), _f(opd[1])));
422 cananian 1.1.2.5          case FCMPGT:    return _b( Eval.fcmpgt  (_f(opd[0]), _f(opd[1])));
423 cananian 1.1.2.5          case FDIV:      return _f( Eval.fdiv    (_f(opd[0]), _f(opd[1])));
424 cananian 1.1.2.5          case FMUL:      return _f( Eval.fmul    (_f(opd[0]), _f(opd[1])));
425 cananian 1.1.2.5          case FNEG:      return _f( Eval.fneg    (_f(opd[0])));
426 cananian 1.1.2.5          case FREM:      return _f( Eval.frem    (_f(opd[0]), _f(opd[1])));
427 cananian 1.1.2.5          case I2B:       return _i( Eval.i2b     (_i(opd[0])));
428 cananian 1.1.2.5          case I2C:       return _i( Eval.i2c     (_i(opd[0])));
429 cananian 1.1.2.5          case I2D:       return _d( Eval.i2d     (_i(opd[0])));
430 cananian 1.1.2.5          case I2F:       return _f( Eval.i2f     (_i(opd[0])));
431 cananian 1.1.2.5          case I2L:       return _l( Eval.i2l     (_i(opd[0])));
432 cananian 1.1.2.5          case I2S:       return _i( Eval.i2s     (_i(opd[0])));
433 cananian 1.1.2.5          case IADD:      return _i( Eval.iadd    (_i(opd[0]), _i(opd[1])));
434 cananian 1.1.2.5          case IAND:      return _i( Eval.iand    (_i(opd[0]), _i(opd[1])));
435 cananian 1.1.2.5          case ICMPEQ:    return _b( Eval.icmpeq  (_i(opd[0]), _i(opd[1])));
436 cananian 1.1.2.5          case ICMPGT:    return _b( Eval.icmpgt  (_i(opd[0]), _i(opd[1])));
437 cananian 1.1.2.5          case IDIV:      return _i( Eval.idiv    (_i(opd[0]), _i(opd[1])));
438 cananian 1.1.2.5          case IMUL:      return _i( Eval.imul    (_i(opd[0]), _i(opd[1])));
439 cananian 1.1.2.5          case INEG:      return _i( Eval.ineg    (_i(opd[0])));
440 cananian 1.1.2.5          case IOR:       return _i( Eval.ior     (_i(opd[0]), _i(opd[1])));
441 cananian 1.1.2.5          case IREM:      return _i( Eval.irem    (_i(opd[0]), _i(opd[1])));
442 cananian 1.1.2.5          case ISHL:      return _i( Eval.ishl    (_i(opd[0]), _i(opd[1])));
443 cananian 1.1.2.5          case ISHR:      return _i( Eval.ishr    (_i(opd[0]), _i(opd[1])));
444 cananian 1.1.2.5          case IUSHR:     return _i( Eval.iushr   (_i(opd[0]), _i(opd[1])));
445 cananian 1.1.2.5          case IXOR:      return _i( Eval.ixor    (_i(opd[0]), _i(opd[1])));
446 cananian 1.1.2.5          case L2D:       return _d( Eval.l2d     (_l(opd[0])));
447 cananian 1.1.2.5          case L2F:       return _f( Eval.l2f     (_l(opd[0])));
448 cananian 1.1.2.5          case L2I:       return _i( Eval.l2i     (_l(opd[0])));
449 cananian 1.1.2.5          case LADD:      return _l( Eval.ladd    (_l(opd[0]), _l(opd[1])));
450 cananian 1.1.2.5          case LAND:      return _l( Eval.land    (_l(opd[0]), _l(opd[1])));
451 cananian 1.1.2.5          case LCMPEQ:    return _b( Eval.lcmpeq  (_l(opd[0]), _l(opd[1])));
452 cananian 1.1.2.5          case LCMPGT:    return _b( Eval.lcmpgt  (_l(opd[0]), _l(opd[1])));
453 cananian 1.1.2.5          case LDIV:      return _l( Eval.ldiv    (_l(opd[0]), _l(opd[1])));
454 cananian 1.1.2.5          case LMUL:      return _l( Eval.lmul    (_l(opd[0]), _l(opd[1])));
455 cananian 1.1.2.5          case LNEG:      return _l( Eval.lneg    (_l(opd[0])));
456 cananian 1.1.2.5          case LOR:       return _l( Eval.lor     (_l(opd[0]), _l(opd[1])));
457 cananian 1.1.2.5          case LREM:      return _l( Eval.lrem    (_l(opd[0]), _l(opd[1])));
458 cananian 1.1.2.5          case LSHL:      return _l( Eval.lshl    (_l(opd[0]), _i(opd[1])));
459 cananian 1.1.2.5          case LSHR:      return _l( Eval.lshr    (_l(opd[0]), _i(opd[1])));
460 cananian 1.1.2.5          case LUSHR:     return _l( Eval.lushr   (_l(opd[0]), _i(opd[1])));
461 cananian 1.1.2.5          case LXOR:      return _l( Eval.lxor    (_l(opd[0]), _l(opd[1])));
462 cananian 1.1.2.5          default:        throw new RuntimeException("Unknown Op type: "+opc);
463 cananian 1.1.2.5          }
464 cananian 1.1.2.5      }
465 cananian 1.1.2.6      // wrapper functions.
466 cananian 1.1.2.5      private static Integer _i(int i)     { return new Integer(i); }
467 cananian 1.1.2.5      private static Long    _l(long l)    { return new Long(l);    }
468 cananian 1.1.2.5      private static Float   _f(float f)   { return new Float(f);   }
469 cananian 1.1.2.5      private static Double  _d(double d)  { return new Double(d);  }
470 cananian 1.1.2.5      private static Boolean _b(boolean b) { return new Boolean(b); }
471 cananian 1.1.2.6      // unwrapper functions.
472 cananian 1.1.2.5      private static int    _i(Object o) { return ((Integer)o).intValue(); }
473 cananian 1.1.2.5      private static long   _l(Object o) { return ((Long)o)   .longValue(); }
474 cananian 1.1.2.5      private static float  _f(Object o) { return ((Float)o)  .floatValue(); }
475 cananian 1.1.2.5      private static double _d(Object o) { return ((Double)o) .doubleValue(); }
476 cananian 1.2      }