com.claritysys.jvm.builder
Class Label

java.lang.Object
  extended by com.claritysys.jvm.builder.Label

public final class Label
extends java.lang.Object

A label marks a point in the byte[] for branch instruction targets, and allows for forward references to be resolved later.


Constructor Summary
Label(ByteArray code)
          Create a new label over the given byte array, but do not define it yet.
 
Method Summary
 void define()
          Define the label to be equal to the current PC.
 int getOffset(boolean isWide)
          Return the offset to write to the byte[] from the given offset, depending on whether a short or int offset is needed, in order to branch to this label from the current PC location.
 boolean hasFixups()
          Returns true if there are unresolved references to this label.
 boolean isDefined()
          Return true if the label has already been defined.
 Label next()
          Get the next label in the chain.
 void setPC(int pc)
          Set the PC of the label.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Label

public Label(ByteArray code)
Create a new label over the given byte array, but do not define it yet.

Method Detail

getOffset

public int getOffset(boolean isWide)
Return the offset to write to the byte[] from the given offset, depending on whether a short or int offset is needed, in order to branch to this label from the current PC location.

If the label is defined, it returns the offset from the current PC (of course).

If NOT defined, it returns a backpatch address, which will be fixed when the label is defined.

When generating branch instructions, be sure to call this BEFORE adding the branch opcode, which will change the PC and cause this to return an incorrect offset.


hasFixups

public boolean hasFixups()
Returns true if there are unresolved references to this label.


next

public Label next()
Get the next label in the chain.


isDefined

public boolean isDefined()
Return true if the label has already been defined.


define

public void define()
Define the label to be equal to the current PC.


setPC

public void setPC(int pc)
Set the PC of the label.



Copyright ? 2000-2003 Clarity Systems Group, LLC. All Rights Reserved.