edu.wisc.cs.java
Class Bytecode

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

public class Bytecode
extends java.lang.Object

This class is used to represent all bytecodes which constant lengths and is the superclass of all other classes which represent Java bytecodes.


Field Summary
protected  int opcode
          The opcode of this instruction.
protected  byte[] params
          An array containing bytes which are parameters for this instruction.
protected  boolean wide
          True if this instruction has the wide modifier, false otherwise.
 
Constructor Summary
protected Bytecode()
          Constructs a genaric bytecode for sub-classes.
  Bytecode(boolean w, int op, byte[] p)
          Constructs a new bytecode with the given opcode and parameters.
 
Method Summary
 int getConstantIndex()
          If this bytecode references the constant pool, it returns the index.
 int getNBytes()
          Returns the number of bytes needed to represent this instruction.
 int getOpcode()
          Return the opcode for this instruction.s
 int getParamBytes()
          Returns the number of parameter bytes for this instruction.
 boolean isWide()
          Returns true if the instruction has the wide modifier, false otherwise.
 java.lang.String toString()
          Returns a string representation of this bytecode.
 void writeTo(java.io.DataOutputStream out)
          Writes a bytecode to the specified stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

wide

protected boolean wide
True if this instruction has the wide modifier, false otherwise.

opcode

protected int opcode
The opcode of this instruction.

params

protected byte[] params
An array containing bytes which are parameters for this instruction.
Constructor Detail

Bytecode

protected Bytecode()
Constructs a genaric bytecode for sub-classes. No variable length bytecode may use the wide modifier, so this is initialized.

Bytecode

public Bytecode(boolean w,
                int op,
                byte[] p)
Constructs a new bytecode with the given opcode and parameters.
Parameters:
w - true if this is to be a wide instruction, false otherwise.
op - the opcode for the new instruction.
p - an array of parameter bytes.
Method Detail

writeTo

public void writeTo(java.io.DataOutputStream out)
             throws java.io.IOException
Writes a bytecode to the specified stream.
Parameters:
out - a stream to write the bytecode data to.
Throws:
java.io.IOException - if there is a problem writing to the stream.

getConstantIndex

public int getConstantIndex()
If this bytecode references the constant pool, it returns the index. Otherwise, it returns -1;
Returns:
an index into the constant pool, if required for this opcode.

getParamBytes

public int getParamBytes()
Returns the number of parameter bytes for this instruction.
Returns:
the number of parameter bytes for this instruction.

isWide

public boolean isWide()
Returns true if the instruction has the wide modifier, false otherwise.
Returns:
true if the instruction has the wide modifier, false otherwise.

getOpcode

public int getOpcode()
Return the opcode for this instruction.s

getNBytes

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

toString

public java.lang.String toString()
Returns a string representation of this bytecode.
Overrides:
toString in class java.lang.Object
Returns:
a string representation of this bytecode.