dovs.instructions
Class Instruction

java.lang.Object
  extended by dovs.instructions.Instruction
Direct Known Subclasses:
FieldAccess, Iaconst_null, Iareturn, Iarraylength, Iathrow, Ibaload, Ibastore, Icaload, Icastore, Icheckcast, Idup, Idup_x1, Idup_x2, Idup2, Ii2b, Ii2c, Ii2s, Iiadd, Iiaload, Iiand, Iiastore, Iidiv, Iimul, Iineg, Iinstanceof, Iior, Iirem, Iireturn, Iisub, Iixor, Ilabel, Ildc_int, Ildc_string, Imultianewarray, Inew, Inop, Ipop, Ireturn, Isaload, Isastore, Iswap, Iaaload, Iaastore, Jump, LocalAccess, MethodInvoke

public abstract class Instruction
extends Object

Base class for all instruction classes. Some instruction classes correspond to one of a number of different actual JVM instructions, depending on the values of its parameters.


Field Summary
private  int id
          An identification number associated with the instruction type.
private static Map<Class<? extends Instruction>,Integer> inst_id
           
private static int next_id
           
 
Constructor Summary
Instruction()
           
 
Method Summary
 boolean canFallThrough()
          Can this instruction transfer control to the succeeding instruction?
 boolean canJump()
          Can this instruction transfer control to a label?
 Object getArg(int i)
          Returns the specified numbered argument as given to the constructor.
 int getID()
          Returns an identification number associated with the instruction type.
static int getID(Class<? extends Instruction> c)
          Returns an identification number associated with the instruction type.
 Label getTarget()
          What is the target of any jump that this instruction performs?
 int localAccess()
          Returns the index of the highest numbered local variable accessed by this instruction.
abstract  int stackChange()
          Returns the number of stack slots that the stack height will change when this instruction is executed.
abstract  String toAsm()
          Returns the instruction in jasmin format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

private int id
An identification number associated with the instruction type.

See Also:
getID()

inst_id

private static Map<Class<? extends Instruction>,Integer> inst_id

next_id

private static int next_id
Constructor Detail

Instruction

public Instruction()
Method Detail

getID

public final int getID()
Returns an identification number associated with the instruction type. Each instruction class gets a unique ID which can be used to do efficient switching on instruction types.


getID

public static int getID(Class<? extends Instruction> c)
Returns an identification number associated with the instruction type. Each instruction class gets a unique ID which can be used to do efficient switching on instruction types.

Parameters:
c - the instruction class to get the ID for

toAsm

public abstract String toAsm()
Returns the instruction in jasmin format.

Returns:
the instruction as a string

stackChange

public abstract int stackChange()
Returns the number of stack slots that the stack height will change when this instruction is executed. A positive value means the stack will grow. A negative value means the stack will shrink.

Returns:
the stack change

localAccess

public int localAccess()
Returns the index of the highest numbered local variable accessed by this instruction.

Returns:
the highest local variable index accessed, or -1 if no local variables are accessed.

canJump

public boolean canJump()
Can this instruction transfer control to a label? If so, the getTarget() method returns the label.

Returns:
whether or not the instruction can jump

canFallThrough

public boolean canFallThrough()
Can this instruction transfer control to the succeeding instruction?

Returns:
whether or not the instruction can fall through

getTarget

public Label getTarget()
What is the target of any jump that this instruction performs? This function is only legal to call if canJump() returns true.

Returns:
the target label

getArg

public Object getArg(int i)
Returns the specified numbered argument as given to the constructor.

Parameters:
i - the index of the argument.
Returns:
the specified argument.