1 cananian 1.1.2.1 // Uop.java, created Thu Feb 4 22:13:12 1999 by cananian 2 cananian 1.1.2.1 // Copyright (C) 1999 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.Tree; 5 cananian 1.1.2.1 6 cananian 1.1.2.1 /** 7 cananian 1.1.2.1 * <code>Uop</code> is an enumerated type for <code>UNOP</code>s. 8 cananian 1.1.2.1 * Operations are typed: pointer (P), integer (I), long (L), float (F) or 9 cananian 1.1.2.1 * double (D). 10 cananian 1.1.2.2 * <p> 11 cananian 1.1.2.2 * See <code>Bop</code> for basic rationale. We provide full set of 12 cananian 1.1.2.2 * conversion operations and both negation and bitwise-not. Some of 13 pnkfelix 1.1.2.4 * these <code>Uop</code>s are not in <code>harpoon.IR.Quads.Qop</code> 14 cananian 1.1.2.2 * and thus will require pattern-matching during translation for 15 cananian 1.1.2.2 * proper generation. This could also be done in a peephole optimization. 16 cananian 1.1.2.1 * 17 cananian 1.1.2.1 * @author C. Scott Ananian <cananian@alumni.princeton.edu> 18 cananian 1.2 * @version $Id: Uop.java,v 1.2 2002/02/25 21:05:42 cananian Exp $ 19 cananian 1.1.2.1 */ 20 cananian 1.1.2.1 public class Uop { 21 pnkfelix 1.1.2.3 22 cananian 1.1.2.5 /** Negation (<code>-</code>). */ 23 pnkfelix 1.1.2.3 public final static int NEG=0; 24 cananian 1.1.2.5 /** Bit-wise NOT (<code>~</code>). */ 25 pnkfelix 1.1.2.3 public final static int NOT=1; 26 pnkfelix 1.1.2.3 27 cananian 1.1.2.1 // int conversion 28 pnkfelix 1.1.2.3 29 pnkfelix 1.1.2.3 /** Converts an int to a byte. Result is still int type, but it 30 pnkfelix 1.1.2.3 is truncated to 8 bits, then sign extended. 31 pnkfelix 1.1.2.3 */ 32 cananian 1.1.2.6 public final static int I2B=2; 33 pnkfelix 1.1.2.3 34 pnkfelix 1.1.2.3 /** Converts an int to a character. Result is still int type, but 35 pnkfelix 1.1.2.3 is truncated to 16 bits. No sign extension. 36 pnkfelix 1.1.2.3 */ 37 cananian 1.1.2.6 public final static int I2C=3; 38 pnkfelix 1.1.2.3 39 pnkfelix 1.1.2.3 /** Converts an int to a short. Result is still int type, but is 40 pnkfelix 1.1.2.3 truncated to 16 bits, then sign extended. 41 pnkfelix 1.1.2.3 */ 42 cananian 1.1.2.6 public final static int I2S=4; 43 pnkfelix 1.1.2.3 44 cananian 1.1.2.1 // general conversion 45 pnkfelix 1.1.2.3 /** Converts to int. */ 46 pnkfelix 1.1.2.3 public final static int _2I=5; 47 pnkfelix 1.1.2.3 /** Converts to long. */ 48 pnkfelix 1.1.2.3 public final static int _2L=6; 49 pnkfelix 1.1.2.3 /** Converts to float. */ 50 pnkfelix 1.1.2.3 public final static int _2F=7; 51 pnkfelix 1.1.2.3 /** Converts to double. */ 52 pnkfelix 1.1.2.3 public final static int _2D=8; 53 cananian 1.1.2.1 54 cananian 1.1.2.1 /** Determines if the given <code>Uop</code> value is valid. */ 55 cananian 1.1.2.1 public static boolean isValid(int op) { 56 cananian 1.1.2.1 switch (op) { 57 cananian 1.1.2.1 case NEG: 58 cananian 1.1.2.1 case NOT: 59 cananian 1.1.2.6 case I2B: case I2C: case I2S: 60 cananian 1.1.2.1 case _2I: case _2L: case _2F: case _2D: 61 cananian 1.1.2.1 return true; 62 cananian 1.1.2.1 default: 63 cananian 1.1.2.1 return false; 64 cananian 1.1.2.1 } 65 cananian 1.1.2.1 } 66 cananian 1.1.2.1 67 cananian 1.1.2.1 /** Converts the enumerated <code>Uop</code> value to 68 cananian 1.1.2.1 * a human-readable string. */ 69 cananian 1.1.2.1 public static String toString(int op) { 70 cananian 1.1.2.1 switch (op) { 71 cananian 1.1.2.1 case NEG: return "neg"; 72 cananian 1.1.2.1 case NOT: return "not"; 73 cananian 1.1.2.6 case I2B: return "i2b"; 74 cananian 1.1.2.6 case I2C: return "i2c"; 75 cananian 1.1.2.6 case I2S: return "i2s"; 76 cananian 1.1.2.1 case _2I: return "_2i"; 77 cananian 1.1.2.1 case _2L: return "_2l"; 78 cananian 1.1.2.1 case _2F: return "_2f"; 79 cananian 1.1.2.1 case _2D: return "_2d"; 80 cananian 1.1.2.1 default: throw new RuntimeException("Unknown Uop type: "+op); 81 cananian 1.1.2.1 } 82 cananian 1.1.2.1 } 83 cananian 1.2 }