com.android.dx.dex.code
Class DalvInsn

java.lang.Object
  extended by com.android.dx.dex.code.DalvInsn
Direct Known Subclasses:
FixedSizeInsn, VariableSizeInsn, ZeroSizeInsn

public abstract class DalvInsn
extends Object

Base class for Dalvik instructions.


Constructor Summary
DalvInsn(Dop opcode, SourcePosition position, RegisterSpecList registers)
          Constructs an instance.
 
Method Summary
protected abstract  String argString()
          Gets the string form for any arguments to this instance.
abstract  int codeSize()
          Gets the size of this instruction, in 16-bit code units.
 DalvInsn expandedPrefix(BitSet compatRegs)
          Gets the instruction prefix required, if any, to use in an expanded version of this instance.
 DalvInsn expandedSuffix(BitSet compatRegs)
          Gets the instruction suffix required, if any, to use in an expanded version of this instance.
 DalvInsn expandedVersion(BitSet compatRegs)
          Gets the instruction that is equivalent to this one, except that it replaces incompatible registers with sequential registers starting at 0 (storing the result, if any, in register 0 as well).
 int getAddress()
          Gets the output address of this instruction, if it is known.
 DalvInsn getLowRegVersion()
          Gets the instruction that is equivalent to this one, except that it uses sequential registers starting at 0 (storing the result, if any, in register 0 as well).
 int getMinimumRegisterRequirement(BitSet compatRegs)
          Gets the minimum distinct registers required for this instruction.
 int getNextAddress()
          Gets the address immediately after this instance.
 Dop getOpcode()
          Gets the opcode.
 SourcePosition getPosition()
          Gets the source position.
 RegisterSpecList getRegisters()
          Gets the register list for this instruction.
 boolean hasAddress()
          Gets whether the address of this instruction is known.
 boolean hasResult()
          Returns whether this instance's opcode uses a result register.
 String identifierString()
          Gets the short identifier for this instruction.
 String listingString(String prefix, int width, boolean noteIndices)
          Returns the string form of this instance suitable for inclusion in a human-oriented listing dump.
protected abstract  String listingString0(boolean noteIndices)
          Helper for listingString(java.lang.String, int, boolean), which returns the string form of this instance suitable for inclusion in a human-oriented listing dump, not including the instruction address and without respect for any output formatting.
static SimpleInsn makeMove(SourcePosition position, RegisterSpec dest, RegisterSpec src)
          Makes a move instruction, appropriate and ideal for the given arguments.
 void setAddress(int address)
          Sets the output address.
 String toString()
          
 DalvInsn withMapper(RegisterMapper mapper)
          Returns an instance that is just like this one, except that the register list is mapped by using mapper.
abstract  DalvInsn withOpcode(Dop opcode)
          Returns an instance that is just like this one, except that its opcode is replaced by the one given, and its address is reset.
abstract  DalvInsn withRegisterOffset(int delta)
          Returns an instance that is just like this one, except that all register references have been offset by the given delta, and its address is reset.
abstract  DalvInsn withRegisters(RegisterSpecList registers)
          Returns an instance that is just like this one, except that the register list is replaced by the given one, and its address is reset.
abstract  void writeTo(AnnotatedOutput out)
          Writes this instance to the given output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DalvInsn

public DalvInsn(Dop opcode,
                SourcePosition position,
                RegisterSpecList registers)
Constructs an instance. The output address of this instance is initially unknown (-1).

Note: In the unlikely event that an instruction takes absolutely no registers (e.g., a nop or a no-argument no-result static method call), then the given register list may be passed as RegisterSpecList.EMPTY.

Parameters:
opcode - the opcode; one of the constants from Dops
position - non-null; source position
registers - non-null; register list, including a result register if appropriate (that is, registers may be either ins and outs)
Method Detail

makeMove

public static SimpleInsn makeMove(SourcePosition position,
                                  RegisterSpec dest,
                                  RegisterSpec src)
Makes a move instruction, appropriate and ideal for the given arguments.

Parameters:
position - non-null; source position information
dest - non-null; destination register
src - non-null; source register
Returns:
non-null; an appropriately-constructed instance

toString

public final String toString()

Overrides:
toString in class Object

hasAddress

public final boolean hasAddress()
Gets whether the address of this instruction is known.

See Also:
getAddress(), setAddress(int)

getAddress

public final int getAddress()
Gets the output address of this instruction, if it is known. This throws a RuntimeException if it has not yet been set.

Returns:
>= 0; the output address
See Also:
setAddress(int)

getOpcode

public final Dop getOpcode()
Gets the opcode.

Returns:
non-null; the opcode

getPosition

public final SourcePosition getPosition()
Gets the source position.

Returns:
non-null; the source position

getRegisters

public final RegisterSpecList getRegisters()
Gets the register list for this instruction.

Returns:
non-null; the registers

hasResult

public final boolean hasResult()
Returns whether this instance's opcode uses a result register. This method is a convenient shorthand for getOpcode().hasResult().

Returns:
true iff this opcode uses a result register

getMinimumRegisterRequirement

public final int getMinimumRegisterRequirement(BitSet compatRegs)
Gets the minimum distinct registers required for this instruction. Uses the given BitSet to determine which registers require replacement, and ignores registers that are already compatible. This assumes that the result (if any) can share registers with the sources (if any), that each source register is unique, and that (to be explicit here) category-2 values take up two consecutive registers.

Parameters:
compatRegs - non-null; set of compatible registers
Returns:
>= 0; the minimum distinct register requirement

getLowRegVersion

public DalvInsn getLowRegVersion()
Gets the instruction that is equivalent to this one, except that it uses sequential registers starting at 0 (storing the result, if any, in register 0 as well).

Returns:
non-null; the replacement

expandedPrefix

public DalvInsn expandedPrefix(BitSet compatRegs)
Gets the instruction prefix required, if any, to use in an expanded version of this instance. Will not generate moves for registers marked compatible to the format by the given BitSet.

Parameters:
compatRegs - non-null; set of compatible registers
Returns:
null-ok; the prefix, if any
See Also:
expandedVersion(java.util.BitSet)

expandedSuffix

public DalvInsn expandedSuffix(BitSet compatRegs)
Gets the instruction suffix required, if any, to use in an expanded version of this instance. Will not generate a move for a register marked compatible to the format by the given BitSet.

Parameters:
compatRegs - non-null; set of compatible registers
Returns:
null-ok; the suffix, if any
See Also:
expandedVersion(java.util.BitSet)

expandedVersion

public DalvInsn expandedVersion(BitSet compatRegs)
Gets the instruction that is equivalent to this one, except that it replaces incompatible registers with sequential registers starting at 0 (storing the result, if any, in register 0 as well). The sequence of instructions from expandedPrefix(java.util.BitSet) and expandedSuffix(java.util.BitSet) (if non-null) surrounding the result of a call to this method are the expanded transformation of this instance, and it is guaranteed that the number of low registers used will be the number returned by getMinimumRegisterRequirement(java.util.BitSet).

Parameters:
compatRegs - non-null; set of compatible registers
Returns:
non-null; the replacement

identifierString

public final String identifierString()
Gets the short identifier for this instruction. This is its address, if assigned, or its identity hashcode if not.

Returns:
non-null; the identifier

listingString

public final String listingString(String prefix,
                                  int width,
                                  boolean noteIndices)
Returns the string form of this instance suitable for inclusion in a human-oriented listing dump. This method will return null if this instance should not appear in a listing.

Parameters:
prefix - non-null; prefix before the address; each follow-on line will be indented to match as well
width - >= 0; the width of the output or 0 for unlimited width
noteIndices - whether to include an explicit notation of constant pool indices
Returns:
null-ok; the string form or null if this instance should not appear in a listing

setAddress

public final void setAddress(int address)
Sets the output address.

Parameters:
address - >= 0; the output address

getNextAddress

public final int getNextAddress()
Gets the address immediately after this instance. This is only calculable if this instance's address is known, and it is equal to the address plus the length of the instruction format of this instance's opcode.

Returns:
>= 0; the next address

withMapper

public DalvInsn withMapper(RegisterMapper mapper)
Returns an instance that is just like this one, except that the register list is mapped by using mapper.

Parameters:
mapper - non-null; used to map registers
Returns:
non-null; an appropriately-constructed instance

codeSize

public abstract int codeSize()
Gets the size of this instruction, in 16-bit code units.

Returns:
>= 0; the code size of this instruction

writeTo

public abstract void writeTo(AnnotatedOutput out)
Writes this instance to the given output. This method should never annotate the output.

Parameters:
out - non-null; where to write to

withOpcode

public abstract DalvInsn withOpcode(Dop opcode)
Returns an instance that is just like this one, except that its opcode is replaced by the one given, and its address is reset.

Parameters:
opcode - non-null; the new opcode
Returns:
non-null; an appropriately-constructed instance

withRegisterOffset

public abstract DalvInsn withRegisterOffset(int delta)
Returns an instance that is just like this one, except that all register references have been offset by the given delta, and its address is reset.

Parameters:
delta - the amount to offset register references by
Returns:
non-null; an appropriately-constructed instance

withRegisters

public abstract DalvInsn withRegisters(RegisterSpecList registers)
Returns an instance that is just like this one, except that the register list is replaced by the given one, and its address is reset.

Parameters:
registers - non-null; new register list
Returns:
non-null; an appropriately-constructed instance

argString

protected abstract String argString()
Gets the string form for any arguments to this instance. Subclasses must override this.

Returns:
null-ok; the string version of any arguments or null if there are none

listingString0

protected abstract String listingString0(boolean noteIndices)
Helper for listingString(java.lang.String, int, boolean), which returns the string form of this instance suitable for inclusion in a human-oriented listing dump, not including the instruction address and without respect for any output formatting. This method should return null if this instance should not appear in a listing.

Parameters:
noteIndices - whether to include an explicit notation of constant pool indices
Returns:
null-ok; the listing string


Copyright © 2015. All rights reserved.