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

GOTO.java

00001 package de.fub.bytecode.generic;
00002 
00003 import java.io.*;
00004 
00005 /** 
00006  * GOTO - Branch always (offset, not address)
00007  *
00008  * @version $Id: GOTO.java,v 1.1.1.1 2002/01/24 03:44:03 pserver Exp $
00009  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00010  */
00011 public class GOTO extends BranchInstruction 
00012   implements VariableLengthInstruction, UnconditionalBranch {
00013   /**
00014    * Empty constructor needed for the Class.newInstance() statement in
00015    * Instruction.readInstruction(). Not to be used otherwise.
00016    */
00017   GOTO() {}  
00018   public GOTO(InstructionHandle target) {
00019     super(GOTO, target);
00020   }  
00021   /**
00022    * Dump instruction as byte code to stream out.
00023    * @param out Output stream
00024    */
00025   public void dump(DataOutputStream out) throws IOException {
00026     index = getTargetOffset();
00027     if(tag == GOTO)
00028       super.dump(out);
00029     else { // GOTO_W
00030       index = getTargetOffset();
00031       out.writeByte(tag);
00032       out.writeInt(index);
00033     }
00034   }  
00035   /** Called in pass 2 of InstructionList.setPositions() in order to update
00036    * the branch target, that may shift due to variable length instructions.
00037    */
00038   protected int updatePosition(int offset, int max_offset) {
00039     int i = getTargetOffset(); // Depending on old position value
00040 
00041     position += offset; // Position may be shifted by preceding expansions
00042 
00043     if(Math.abs(i) >= (32767 - max_offset)) { // to large for short (estimate)
00044       tag    = GOTO_W;
00045       length = 5;
00046       return 2; // 5 - 3
00047     }
00048 
00049     return 0;
00050   }  
00051 }

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