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 gov.nasa.arc.ase.jpf.*;
00004 import gov.nasa.arc.ase.jpf.jvm.*;
00005 import de.fub.bytecode.classfile.ConstantPool;
00006 import de.fub.bytecode.classfile.Constant;
00007 import de.fub.bytecode.classfile.ConstantFloat;
00008 import de.fub.bytecode.classfile.ConstantString;
00009 import de.fub.bytecode.classfile.ConstantInteger;
00010 import de.fub.bytecode.generic.Type;
00011 import de.fub.bytecode.generic.ConstantPoolGen;
00012 import de.fub.bytecode.generic.InstructionHandle;
00013 import gov.nasa.arc.ase.util.Debug;
00014 
00015 public class LDC extends AbstractInstruction {
00016   private de.fub.bytecode.generic.LDC peer;
00017 
00018   public InstructionHandle execute(SystemState ss, KernelState ks, ThreadInfo th) {
00019     ConstantPoolGen cpg = th.getCPG();
00020     ConstantPool cp = cpg.getConstantPool();
00021     Constant cons = cp.getConstant(peer.getIndex());
00022 
00023     if (peer.getType(cpg) == Type.STRING) {
00024       // loaded the string constant
00025       int index = ((ConstantString)cons).getStringIndex();
00026       Constant c = cp.getConstant(index);
00027       String str =  cp.constantToString(c);
00028 
00029       int objref = ks.dynamic_area.newStringObject(str, th);
00030 
00031       // stores the reference on the stack
00032       th.push(objref);
00033 // ifdef MARK_N_SWEEP
00034       th.setOperandRef();
00035 //#endif MARK_N_SWEEP
00036     } else if (peer.getType(cpg) == Type.INT) {
00037       // loads the constant
00038       int value = ((ConstantInteger)cons).getBytes();
00039 
00040       // pushes the value onto the stack
00041       th.push(value);
00042     } else {
00043       // loads the constant
00044       float value = ((ConstantFloat)cons).getBytes();
00045 
00046       // pushes the value onto the stack
00047       th.push(Types.floatToInt(value));
00048     }
00049     //** warning: there should be an else here to check for errors  **//
00050 
00051     return th.getPC().getNext();
00052   }  
00053   public void setPeer(de.fub.bytecode.generic.Instruction i) {
00054     peer = (de.fub.bytecode.generic.LDC)i;
00055   }  
00056 }

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