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:41:39 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(de.fub.bytecode.Constants.GOTO, target);
00020   }  
00021   /**
00022    * Call corresponding visitor method(s). The order is:
00023    * Call visitor methods of implemented interfaces first, then
00024    * call methods according to the class hierarchy in descending order,
00025    * i.e., the most specific visitXXX() call comes last.
00026    *
00027    * @param v Visitor object
00028    */
00029   public void accept(Visitor v) {
00030     v.visitVariableLengthInstruction(this);
00031     v.visitUnconditionalBranch(this);
00032     v.visitInstructionTargeter(this);
00033     v.visitBranchInstruction(this);
00034     v.visitGOTO(this);
00035   }  
00036   /**
00037    * Dump instruction as byte code to stream out.
00038    * @param out Output stream
00039    */
00040   public void dump(DataOutputStream out) throws IOException {
00041     index = getTargetOffset();
00042     if(tag == de.fub.bytecode.Constants.GOTO)
00043       super.dump(out);
00044     else { // GOTO_W
00045       index = getTargetOffset();
00046       out.writeByte(tag);
00047       out.writeInt(index);
00048     }
00049   }  
00050   /** Called in pass 2 of InstructionList.setPositions() in order to update
00051    * the branch target, that may shift due to variable length instructions.
00052    */
00053   protected int updatePosition(int offset, int max_offset) {
00054     int i = getTargetOffset(); // Depending on old position value
00055 
00056     position += offset; // Position may be shifted by preceding expansions
00057 
00058     if(Math.abs(i) >= (32767 - max_offset)) { // to large for short (estimate)
00059       tag    = de.fub.bytecode.Constants.GOTO_W;
00060       length = 5;
00061       return 2; // 5 - 3
00062     }
00063 
00064     return 0;
00065   }  
00066 }

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