Class RegisterSpec

java.lang.Object
com.android.dx.rop.code.RegisterSpec
All Implemented Interfaces:
TypeBearer, ToHuman, Comparable<RegisterSpec>

public final class RegisterSpec extends Object implements TypeBearer, ToHuman, Comparable<RegisterSpec>
Combination of a register number and a type, used as the sources and destinations of register-based operations.
  • Field Details

  • Method Details

    • make

      public static RegisterSpec make(int reg, TypeBearer type)
      Returns an instance for the given register number and type, with no variable info. This method is allowed to return shared instances (but doesn't necessarily do so).
      Parameters:
      reg - >= 0; the register number
      type - non-null; the type (or possibly actual value) which is loaded from or stored to the indicated register
      Returns:
      non-null; an appropriately-constructed instance
    • make

      public static RegisterSpec make(int reg, TypeBearer type, LocalItem local)
      Returns an instance for the given register number, type, and variable info. This method is allowed to return shared instances (but doesn't necessarily do so).
      Parameters:
      reg - >= 0; the register number
      type - non-null; the type (or possibly actual value) which is loaded from or stored to the indicated register
      local - non-null; the associated local variable
      Returns:
      non-null; an appropriately-constructed instance
    • makeLocalOptional

      public static RegisterSpec makeLocalOptional(int reg, TypeBearer type, LocalItem local)
      Returns an instance for the given register number, type, and variable info. This method is allowed to return shared instances (but doesn't necessarily do so).
      Parameters:
      reg - >= 0; the register number
      type - non-null; the type (or possibly actual value) which is loaded from or stored to the indicated register
      local - null-ok; the associated variable info or null for none
      Returns:
      non-null; an appropriately-constructed instance
    • regString

      public static String regString(int reg)
      Gets the string form for the given register number.
      Parameters:
      reg - >= 0; the register number
      Returns:
      non-null; the string form
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • equalsUsingSimpleType

      public boolean equalsUsingSimpleType(RegisterSpec other)
      Like equals, but only consider the simple types of the registers. That is, this compares getType() on the types to ignore whatever arbitrary extra stuff might be carried around by an outer TypeBearer.
      Parameters:
      other - null-ok; spec to compare to
      Returns:
      true iff this and other are equal in the stated way
    • matchesVariable

      public boolean matchesVariable(RegisterSpec other)
      Like equalsUsingSimpleType(com.android.dx.rop.code.RegisterSpec) but ignoring the register number. This is useful to determine if two instances refer to the "same" local variable.
      Parameters:
      other - null-ok; spec to compare to
      Returns:
      true iff this and other are equal in the stated way
    • compareTo

      public int compareTo(RegisterSpec other)
      Compares by (in priority order) register number, unwrapped type (that is types not TypeBearers, and local info.
      Specified by:
      compareTo in interface Comparable<RegisterSpec>
      Parameters:
      other - non-null; spec to compare to
      Returns:
      -1..1; standard result of comparison
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toHuman

      public String toHuman()
      Return the "human" string form of this instance. This is generally less "debuggy" than toString().
      Specified by:
      toHuman in interface ToHuman
      Returns:
      non-null; the human string form
    • getType

      public Type getType()
      Gets the type associated with this instance.
      Specified by:
      getType in interface TypeBearer
      Returns:
      non-null; the type
    • getFrameType

      public TypeBearer getFrameType()
      Gets the frame type corresponding to this type. This method returns this, except if Type.isIntlike() on the underlying type returns true but the underlying type is not in fact Type.INT, in which case this method returns an instance whose underlying type is INT.
      Specified by:
      getFrameType in interface TypeBearer
      Returns:
      non-null; the frame type for this instance
    • getBasicType

      public final int getBasicType()
      Gets the basic type corresponding to this instance.
      Specified by:
      getBasicType in interface TypeBearer
      Returns:
      the basic type; one of the BT_* constants defined by Type
    • getBasicFrameType

      public final int getBasicFrameType()
      Gets the basic type corresponding to this instance's frame type. This is equivalent to getFrameType().getBasicType(), and is the same as calling getFrameType() unless this instance is an int-like type, in which case this method returns BT_INT.
      Specified by:
      getBasicFrameType in interface TypeBearer
      Returns:
      the basic frame type; one of the BT_* constants defined by Type
      See Also:
    • isConstant

      public final boolean isConstant()
      Returns whether this instance represents a constant value.
      Specified by:
      isConstant in interface TypeBearer
      Returns:
      true if this instance represents a constant value and false if not
    • getReg

      public int getReg()
      Gets the register number.
      Returns:
      >= 0; the register number
    • getTypeBearer

      public TypeBearer getTypeBearer()
      Gets the type (or actual value) which is loaded from or stored to the register associated with this instance.
      Returns:
      non-null; the type
    • getLocalItem

      public LocalItem getLocalItem()
      Gets the variable info associated with this instance, if any.
      Returns:
      null-ok; the variable info, or null if this instance has none
    • getNextReg

      public int getNextReg()
      Gets the next available register number after the one in this instance. This is equal to the register number plus the width (category) of the type used. Among other things, this may also be used to determine the minimum required register count implied by this instance.
      Returns:
      >= 0; the required registers size
    • getCategory

      public int getCategory()
      Gets the category of this instance's type. This is just a convenient shorthand for getType().getCategory().
      Returns:
      1..2; the category of this instance's type
      See Also:
    • isCategory1

      public boolean isCategory1()
      Gets whether this instance's type is category 1. This is just a convenient shorthand for getType().isCategory1().
      Returns:
      whether or not this instance's type is of category 1
      See Also:
    • isCategory2

      public boolean isCategory2()
      Gets whether this instance's type is category 2. This is just a convenient shorthand for getType().isCategory2().
      Returns:
      whether or not this instance's type is of category 2
      See Also:
    • regString

      public String regString()
      Gets the string form for just the register number of this instance.
      Returns:
      non-null; the register string form
    • intersect

      public RegisterSpec intersect(RegisterSpec other, boolean localPrimary)
      Returns an instance that is the intersection between this instance and the given one, if any. The intersection is defined as follows:
      • If other is null, then the result is null.
      • If the register numbers don't match, then the intersection is null. Otherwise, the register number of the intersection is the same as the one in the two instances.
      • If the types returned by getType() are not equals(), then the intersection is null.
      • If the type bearers returned by getTypeBearer() are equals(), then the intersection's type bearer is the one from this instance. Otherwise, the intersection's type bearer is the getType() of this instance.
      • If the locals are equals(), then the local info of the intersection is the local info of this instance. Otherwise, the local info of the intersection is null.
      Parameters:
      other - null-ok; instance to intersect with (or null)
      localPrimary - whether local variables are primary to the intersection; if true, then the only non-null results occur when registers being intersected have equal local infos (or both have null local infos)
      Returns:
      null-ok; the intersection
    • withReg

      public RegisterSpec withReg(int newReg)
      Returns an instance that is identical to this one, except that the register number is replaced by the given one.
      Parameters:
      newReg - >= 0; the new register number
      Returns:
      non-null; an appropriately-constructed instance
    • withType

      public RegisterSpec withType(TypeBearer newType)
      Returns an instance that is identical to this one, except that the type is replaced by the given one.
      Parameters:
      newType - non-null; the new type
      Returns:
      non-null; an appropriately-constructed instance
    • withOffset

      public RegisterSpec withOffset(int delta)
      Returns an instance that is identical to this one, except that the register number is offset by the given amount.
      Parameters:
      delta - the amount to offset the register number by
      Returns:
      non-null; an appropriately-constructed instance
    • withSimpleType

      public RegisterSpec withSimpleType()
      Returns an instance that is identical to this one, except that the type bearer is replaced by the actual underlying type (thereby stripping off non-type information) with any initialization information stripped away as well.
      Returns:
      non-null; an appropriately-constructed instance
    • withLocalItem

      public RegisterSpec withLocalItem(LocalItem local)
      Returns an instance that is identical to this one except that the local variable is as specified in the parameter.
      Parameters:
      local - null-ok; the local item or null for none
      Returns:
      an appropriate instance
    • isEvenRegister

      public boolean isEvenRegister()
      Returns:
      boolean specifying if this instance is an even register or not.
    • clearInternTable

      public static void clearInternTable()