1 23 24 25 package com.sun.jdo.api.persistence.enhancer.classfile; 26 27 import java.io.PrintStream ; 28 29 32 33 public class InsnIntOp extends Insn { 34 35 private int operandValue; 36 37 38 39 public int nStackArgs() { 40 return VMOp.ops[opcode()].nStackArgs(); 41 } 42 43 public int nStackResults() { 44 return VMOp.ops[opcode()].nStackResults(); 45 } 46 47 public String argTypes() { 48 return VMOp.ops[opcode()].argTypes(); 49 } 50 51 public String resultTypes() { 52 return VMOp.ops[opcode()].resultTypes(); 53 } 54 55 public boolean branches() { 56 return opcode() == opc_ret; 57 } 58 59 public int value() { 60 return operandValue; 61 } 62 63 64 65 static String primType(int primIndex) { 66 switch (primIndex) { 67 case T_BOOLEAN: 68 return "boolean"; case T_CHAR: 70 return "char"; case T_FLOAT: 72 return "float"; case T_DOUBLE: 74 return "double"; case T_BYTE: 76 return "byte"; case T_SHORT: 78 return "short"; case T_INT: 80 return "int"; case T_LONG: 82 return "long"; default: 84 throw new InsnError ("Invalid primitive type(" + primIndex + ")"); } 86 } 87 88 void print (PrintStream out, int indent) { 89 ClassPrint.spaces(out, indent); 90 if (opcode() == opc_newarray) 91 out.println(offset() + " opc_newarray " + primType(operandValue)); else 93 out.println(offset() + " " + opName(opcode()) + " " + operandValue); } 95 96 int store(byte[] buf, int index) { 97 if (size() == 4) { 98 99 buf[index++] = (byte) opc_wide; 100 } 101 102 buf[index++] = (byte) opcode(); 103 if (size() > 2) 104 buf[index++] = (byte)(operandValue >> 8); 105 buf[index++] = (byte)(operandValue & 0xff); 106 return index; 107 } 108 109 110 111 112 int size() { 113 switch(opcode()) { 114 case opc_bipush: 115 case opc_newarray: 116 117 return 2; 118 119 case opc_sipush: 120 121 return 3; 122 123 case opc_iload: 124 case opc_lload: 125 case opc_fload: 126 case opc_dload: 127 case opc_aload: 128 case opc_istore: 129 case opc_lstore: 130 case opc_fstore: 131 case opc_dstore: 132 case opc_astore: 133 case opc_ret: 134 137 if (operandValue < 256) 138 return 2; 139 else 140 return 4; 141 142 default: 143 throw new InsnError ("invalid instruction " + opName(opcode()) + " with an integer operand"); } 146 } 147 148 149 InsnIntOp (int theOpcode, int theOperand, int pc) { 150 super(theOpcode, pc); 151 152 operandValue = theOperand; 153 } 154 155 156 InsnIntOp (int theOpcode, int theOperand) { 157 super(theOpcode, NO_OFFSET); 158 159 operandValue = theOperand; 160 switch(theOpcode) { 161 case opc_bipush: 162 case opc_newarray: 163 164 165 case opc_sipush: 166 167 168 case opc_dload: 169 case opc_lload: 170 case opc_iload: 171 case opc_fload: 172 case opc_aload: 173 case opc_istore: 174 case opc_lstore: 175 case opc_fstore: 176 case opc_dstore: 177 case opc_astore: 178 case opc_ret: 179 180 break; 181 182 default: 183 throw new InsnError ("attempt to create an " + opName(theOpcode) + " with an integer operand"); } 186 } 187 } 188 | Popular Tags |