Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

LDC.java

00001 package gov.nasa.arc.ase.jpf.jvm.bytecode;
00002 
00003 import de.fub.bytecode.classfile.ConstantFloat;
00004 import de.fub.bytecode.classfile.ConstantInteger;
00005 import de.fub.bytecode.classfile.ConstantPool;
00006 import de.fub.bytecode.classfile.ConstantString;
00007 import de.fub.bytecode.generic.ConstantPoolGen;
00008 import de.fub.bytecode.generic.Type;
00009 import gov.nasa.arc.ase.jpf.InternalErrorException;
00010 import gov.nasa.arc.ase.jpf.jvm.KernelState;
00011 import gov.nasa.arc.ase.jpf.jvm.SystemState;
00012 import gov.nasa.arc.ase.jpf.jvm.ThreadInfo;
00013 import gov.nasa.arc.ase.jpf.jvm.Types;
00014 import gov.nasa.arc.ase.util.Debug;
00015 
00016 public class LDC extends Instruction {
00017   private String string;
00018   private int value;
00019   private boolean isString;
00020 
00021   public Instruction execute(SystemState ss, KernelState ks, ThreadInfo th) {
00022     if(isString)
00023       th.push(ks.da.newString(string, th), true);
00024     else
00025       th.push(value, false);
00026 
00027     return th.getPC().getNext();
00028   }  
00029   public void setPeer(de.fub.bytecode.generic.Instruction i, ConstantPool cp) {
00030     Type type = ((de.fub.bytecode.generic.LDC)i).getType(new ConstantPoolGen(cp));
00031 
00032     if(type == Type.STRING) {
00033       isString = true;
00034       string = cp.constantToString(
00035       cp.getConstant(
00036         ((ConstantString)cp.getConstant(
00037                         ((de.fub.bytecode.generic.LDC)i).getIndex()
00038                        )).getStringIndex()));
00039     } else if(type == Type.INT) {
00040       isString = false;
00041       string = null;
00042       value = ((ConstantInteger)cp.getConstant(
00043         ((de.fub.bytecode.generic.LDC)i).getIndex()
00044                           )).getBytes();
00045     } else if(type == Type.FLOAT) {
00046       isString = false;
00047       string = null;
00048       value = Types.floatToInt(((ConstantFloat)cp.getConstant(
00049         ((de.fub.bytecode.generic.LDC)i).getIndex()
00050                                  )).getBytes());
00051     } else
00052       throw new InternalErrorException("invalid type of constant");
00053   }  
00054 }

Generated at Thu Feb 7 06:49:13 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001