1 package gov.nasa.jpf.jvm.bytecode; 20 21 import gov.nasa.jpf.JPFException; 22 import gov.nasa.jpf.jvm.ClassInfo; 23 import gov.nasa.jpf.jvm.KernelState; 24 import gov.nasa.jpf.jvm.SystemState; 25 import gov.nasa.jpf.jvm.ThreadInfo; 26 import gov.nasa.jpf.jvm.Types; 27 28 import org.apache.bcel.Constants; 29 import org.apache.bcel.classfile.ConstantFloat; 30 import org.apache.bcel.classfile.ConstantInteger; 31 import org.apache.bcel.classfile.ConstantPool; 32 import org.apache.bcel.classfile.ConstantString; 33 import org.apache.bcel.generic.ConstantPoolGen; 34 import org.apache.bcel.generic.Type; 35 36 37 41 public class LDC_W extends Instruction { 42 private int value; 43 private String string; 44 Type type; 45 46 private boolean isString; 47 private boolean isClass; 48 49 public void setPeer (org.apache.bcel.generic.Instruction i, ConstantPool cp) { 50 ConstantPoolGen cpg = ClassInfo.getConstantPoolGen(cp); 51 type = ((org.apache.bcel.generic.LDC_W) i).getType(cpg); 52 53 int index = ((org.apache.bcel.generic.LDC_W) i).getIndex(); 54 55 if (type == Type.STRING) { 56 string = cp.constantToString(cp.getConstant( 57 ((ConstantString) cp.getConstant(index)).getStringIndex())); 58 } else if (type == Type.INT) { 59 value = ((ConstantInteger) cp.getConstant(index)).getBytes(); 60 } else if (type == Type.FLOAT) { 61 value = Types.floatToInt(((ConstantFloat) cp.getConstant(index)).getBytes()); 62 63 71 } else if (type.getType() == Constants.T_REFERENCE) { string = cp.constantToString(index, Constants.CONSTANT_Class); 78 } else { 79 throw new JPFException("invalid type of constant"); 80 } 81 } 82 83 public Instruction execute (SystemState ss, KernelState ks, ThreadInfo th) { 84 if (type == Type.STRING) { 85 th.push(ks.da.newConstantString(string), true); 86 } else if (type.getType() == Constants.T_REFERENCE) { ClassInfo ci = ClassInfo.getClassInfo(string); 89 th.push(ci.getClassObjectRef(), true); 90 } else { 91 th.push(value, false); 92 } 93 94 return getNext(th); 95 } 96 97 public int getByteCode () { 98 return 0x13; 99 } 100 } 101 | Popular Tags |