de.fub.bytecode.generic
Class BranchInstruction

java.lang.Object
  |
  +--de.fub.bytecode.generic.Instruction
        |
        +--de.fub.bytecode.generic.BranchInstruction
All Implemented Interfaces:
java.lang.Cloneable, InstructionTargeter, java.io.Serializable
Direct Known Subclasses:
GotoInstruction, IfInstruction, JsrInstruction, Select

public abstract class BranchInstruction
extends Instruction
implements InstructionTargeter

Abstract super class for branching instructions like GOTO, IFEQ, etc.. Branch instructions may have a variable length, namely GOTO, JSR, LOOKUPSWITCH and TABLESWITCH.

Version:
$Id: BranchInstruction.java,v 1.4 2001/07/03 08:20:18 dahm Exp $
Author:
M. Dahm
See Also:
InstructionList, Serialized Form

Field Summary
protected  int index
           
protected  int position
           
protected  InstructionHandle target
           
 
Fields inherited from class de.fub.bytecode.generic.Instruction
length, opcode
 
Constructor Summary
protected BranchInstruction(short opcode, InstructionHandle target)
          Common super constructor
 
Method Summary
 boolean containsTarget(InstructionHandle ih)
           
 void dump(java.io.DataOutputStream out)
          Dump instruction as byte code to stream out.
 int getIndex()
           
 InstructionHandle getTarget()
           
protected  int getTargetOffset()
           
protected  int getTargetOffset(InstructionHandle target)
           
protected  void initFromFile(ByteSequence bytes, boolean wide)
          Read needed data (e.g.
 void setTarget(InstructionHandle target)
          Set branch target
 java.lang.String toString(boolean verbose)
          Long output format: <position in byte code> <name of opcode> "["<opcode number>"]" "("<length of instruction>")" "<"<target instruction>">" "@"<branch target offset>
protected  int updatePosition(int offset, int max_offset)
          Called by InstructionList.setPositions when setting the position for every instruction.
 void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih)
           
 
Methods inherited from class de.fub.bytecode.generic.Instruction
accept, consumeStack, consumeStack, copy, getLength, getOpcode, getTag, produceStack, produceStack, readInstruction, toString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

index

protected int index

target

protected InstructionHandle target

position

protected int position
Constructor Detail

BranchInstruction

protected BranchInstruction(short opcode,
                            InstructionHandle target)
Common super constructor
Parameters:
opcodee - Instruction opcode
target - instruction to branch to
Method Detail

dump

public void dump(java.io.DataOutputStream out)
          throws java.io.IOException
Dump instruction as byte code to stream out.
Overrides:
dump in class Instruction
Parameters:
out - Output stream

getTargetOffset

protected int getTargetOffset(InstructionHandle target)
Parameters:
target - branch target
Returns:
the offset to `target' relative to this instruction

getTargetOffset

protected int getTargetOffset()
Returns:
the offset to this instruction's target

updatePosition

protected int updatePosition(int offset,
                             int max_offset)
Called by InstructionList.setPositions when setting the position for every instruction. In the presence of variable length instructions `setPositions' performs multiple passes over the instruction list to calculate the correct (byte) positions and offsets by calling this function.
Parameters:
offset - additional offset caused by preceding (variable length) instructions
max_offset - the maximum offset that may be caused by these instructions
Returns:
additional offset caused by possible change of this instruction's length

toString

public java.lang.String toString(boolean verbose)
Long output format: <position in byte code> <name of opcode> "["<opcode number>"]" "("<length of instruction>")" "<"<target instruction>">" "@"<branch target offset>
Overrides:
toString in class Instruction
Parameters:
verbose - long/short format switch
Returns:
mnemonic for instruction

initFromFile

protected void initFromFile(ByteSequence bytes,
                            boolean wide)
                     throws java.io.IOException
Read needed data (e.g. index) from file. Conversion to a InstructionHandle is done in InstructionList(byte[]).
Overrides:
initFromFile in class Instruction
Parameters:
bytes - input stream
wide - wide prefix?
See Also:
InstructionList

getIndex

public final int getIndex()
Returns:
target offset in byte code

getTarget

public InstructionHandle getTarget()
Returns:
target of branch instruction

setTarget

public void setTarget(InstructionHandle target)
Set branch target
Parameters:
target - branch target

updateTarget

public void updateTarget(InstructionHandle old_ih,
                         InstructionHandle new_ih)
Specified by:
updateTarget in interface InstructionTargeter
Parameters:
old_ih - old target
new_ih - new target

containsTarget

public boolean containsTarget(InstructionHandle ih)
Specified by:
containsTarget in interface InstructionTargeter
Returns:
true, if ih is target of this instruction