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

RET.java

00001 package de.fub.bytecode.generic;
00002 
00003 import java.io.*;
00004 import de.fub.bytecode.util.ByteSequence;
00005 
00006 /** 
00007  * RET - Return from subroutine
00008  *
00009  * <PRE>Stack: ..., -&gt; ..., address</PRE>
00010  *
00011  * @version $Id: RET.java,v 1.1.1.1 2002/01/24 03:44:05 pserver Exp $
00012  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00013  */
00014 public class RET extends Instruction {
00015   private boolean wide;
00016   private int     index; // index to local variable containg the return address
00017 
00018   /**
00019    * Empty constructor needed for the Class.newInstance() statement in
00020    * Instruction.readInstruction(). Not to be used otherwise.
00021    */
00022   RET() {}  
00023   public RET(int index) {
00024     super(RET, (short)2);
00025     setIndex(index);   // May set wide as side effect
00026   }  
00027   /**
00028    * Dump instruction as byte code to stream out.
00029    * @param out Output stream
00030    */
00031   public void dump(DataOutputStream out) throws IOException {
00032     if(wide)
00033       out.writeByte(WIDE);
00034 
00035     out.writeByte(tag);
00036 
00037     if(wide)
00038       out.writeShort(index);
00039     else
00040       out.writeByte(index);
00041   }  
00042   /**
00043    * @return index of local variable containg the return address
00044    */
00045   public final int getIndex() { return index; }  
00046   /**
00047    * Read needed data (e.g. index) from file.
00048    */
00049   protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
00050   {
00051     this.wide = wide;
00052 
00053     if(wide) {
00054       index  = bytes.readUnsignedShort();
00055       length = 4;
00056     }
00057     else {
00058       index = bytes.readUnsignedByte();
00059       length = 2;
00060     }
00061   }  
00062   /**
00063    * Set index of local variable containg the return address
00064    */
00065   public final void setIndex(int n) { 
00066     if(n < 0)
00067       throw new ClassGenException("Negative index value: " + n);
00068 
00069     index = n;
00070     setWide();
00071   }  
00072   private final void setWide() {
00073     if(wide = index > MAX_BYTE)
00074       length = 4; // Including the wide byte  
00075     else
00076       length = 2;
00077   }  
00078   /**
00079    * @return mnemonic for instruction
00080    */
00081   public String toString(boolean verbose) {
00082     return super.toString(verbose) + " " + index;
00083   }  
00084 }

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