com.android.dx.rop.code
Class RegisterSpec

java.lang.Object
  extended by 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 Summary
static String PREFIX
          non-null; string to prefix register numbers with
 
Method Summary
 int compareTo(RegisterSpec other)
          Compares by (in priority order) register number, unwrapped type (that is types not TypeBearers, and local info.
 boolean equals(Object other)
          
 boolean equalsUsingSimpleType(RegisterSpec other)
          Like equals, but only consider the simple types of the registers.
 int getBasicFrameType()
          Gets the basic type corresponding to this instance's frame type.
 int getBasicType()
          Gets the basic type corresponding to this instance.
 int getCategory()
          Gets the category of this instance's type.
 TypeBearer getFrameType()
          Gets the frame type corresponding to this type.
 LocalItem getLocalItem()
          Gets the variable info associated with this instance, if any.
 int getNextReg()
          Gets the next available register number after the one in this instance.
 int getReg()
          Gets the register number.
 Type getType()
          Gets the type associated with this instance.
 TypeBearer getTypeBearer()
          Gets the type (or actual value) which is loaded from or stored to the register associated with this instance.
 int hashCode()
          
 RegisterSpec intersect(RegisterSpec other, boolean localPrimary)
          Returns an instance that is the intersection between this instance and the given one, if any.
 boolean isCategory1()
          Gets whether this instance's type is category 1.
 boolean isCategory2()
          Gets whether this instance's type is category 2.
 boolean isConstant()
          Returns whether this instance represents a constant value.
 boolean isEvenRegister()
           
static RegisterSpec make(int reg, TypeBearer type)
          Returns an instance for the given register number and type, with no variable info.
static RegisterSpec make(int reg, TypeBearer type, LocalItem local)
          Returns an instance for the given register number, type, and variable info.
static RegisterSpec makeLocalOptional(int reg, TypeBearer type, LocalItem local)
          Returns an instance for the given register number, type, and variable info.
 boolean matchesVariable(RegisterSpec other)
          Like equalsUsingSimpleType(com.android.dx.rop.code.RegisterSpec) but ignoring the register number.
 String regString()
          Gets the string form for just the register number of this instance.
static String regString(int reg)
          Gets the string form for the given register number.
 String toHuman()
          Return the "human" string form of this instance.
 String toString()
          
 RegisterSpec withLocalItem(LocalItem local)
          Returns an instance that is identical to this one except that the local variable is as specified in the parameter.
 RegisterSpec withOffset(int delta)
          Returns an instance that is identical to this one, except that the register number is offset by the given amount.
 RegisterSpec withReg(int newReg)
          Returns an instance that is identical to this one, except that the register number is replaced by the given one.
 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.
 RegisterSpec withType(TypeBearer newType)
          Returns an instance that is identical to this one, except that the type is replaced by the given one.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PREFIX

public static final String PREFIX
non-null; string to prefix register numbers with

See Also:
Constant Field Values
Method Detail

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:
TypeBearer.getBasicType(), TypeBearer.getFrameType()

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(), isCategory2()

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:
getCategory(), isCategory2()

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:
getCategory(), isCategory1()

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:

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.


Copyright © 2015. All rights reserved.