edu.wisc.cs.java
Class Switch

java.lang.Object
  |
  +--edu.wisc.cs.java.Bytecode
        |
        +--edu.wisc.cs.java.Switch
Direct Known Subclasses:
LookupSwitch, TableSwitch

public abstract class Switch
extends Bytecode

This is the superclass for instructions which imlement multiway branch statements.


Field Summary
protected  CodeLabel default_offset
          The byte offset of the first instruction in the default case.
protected  int pad
          The padding between the opcode and the table from the classfile.
protected  CodeLabel[] targets
          The array of offsets for this jump table.
 
Fields inherited from class edu.wisc.cs.java.Bytecode
opcode, params, wide
 
Constructor Summary
protected Switch(int pad)
          Constructs a new Switch object.
 
Method Summary
 void adjustPad(int pc)
          Given a program counter value for this instruction, adjust the size of the pad accordingly.
 CodeLabel getDefault()
          Returns the label corresponding to the default target of this switch.
 int getNBytes()
          Returns the number of bytes needed to represent this instruction.
 int getNTargets()
          Returns the number of entries in the jump table.
 int getPad()
          Returns the number of pad bytes between the opcode and the table.
abstract  int getParamBytes()
          Abstract method which should be implemented to return the number of bytes required to encode the parameters for this instruction.
 CodeLabel getTarget(int i)
          Returns a label corresponding to a case in the jump table.
abstract  void writeTo(java.io.DataOutputStream out, java.util.HashMap labels, int pc)
          Writes a switch instruction to a stream in the specified format.
 
Methods inherited from class edu.wisc.cs.java.Bytecode
getConstantIndex, getOpcode, isWide, toString, writeTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

default_offset

protected CodeLabel default_offset
The byte offset of the first instruction in the default case.

targets

protected CodeLabel[] targets
The array of offsets for this jump table.

pad

protected int pad
The padding between the opcode and the table from the classfile.
Constructor Detail

Switch

protected Switch(int pad)
Constructs a new Switch object. Note that this class is abstract, and thus this constructor is only able to be called by subclasses.
Parameters:
pad - the number of bytes of padding between the opcode and the table.
Method Detail

getParamBytes

public abstract int getParamBytes()
Abstract method which should be implemented to return the number of bytes required to encode the parameters for this instruction. For switch instructions, this should include the pad, as well as bytes for the jump table.
Overrides:
getParamBytes in class Bytecode
Returns:
the number of bytes needed for this instruction, not including the opcode.

writeTo

public abstract void writeTo(java.io.DataOutputStream out,
                             java.util.HashMap labels,
                             int pc)
                      throws java.io.IOException
Writes a switch instruction to a stream in the specified format. The pad is already expected to have been adjusted to the proper value given the pc.
Parameters:
out - a stream to which to write the data for this instruction.
labels - a map comtaining the labels in the method and their pc's.
pc - the program counter for this instruction.
Throws:
java.io.IOException - if there is a problem writing to the stream.

getDefault

public CodeLabel getDefault()
Returns the label corresponding to the default target of this switch.

adjustPad

public void adjustPad(int pc)
Given a program counter value for this instruction, adjust the size of the pad accordingly.
Parameters:
pc - the program counter value for this instruction.

getPad

public int getPad()
Returns the number of pad bytes between the opcode and the table. This reflects the size of the pad when this instruction was read from the classfile. This may change as instructions are added or deleted from the method, but this value is not dynamically updated.
Returns:
the number of pad bytes between the opcode and the table.

getNTargets

public int getNTargets()
Returns the number of entries in the jump table.
Returns:
the number of entries in the jump table.

getTarget

public CodeLabel getTarget(int i)
Returns a label corresponding to a case in the jump table.
Parameters:
i - the index into the jump table of the desired label.
Returns:
a label corresponding to a case in the jump table.

getNBytes

public int getNBytes()
Returns the number of bytes needed to represent this instruction.
Overrides:
getNBytes in class Bytecode
Returns:
the number of bytes needed to represent this instruction.