Package com.android.dx.dex.code
Class DalvInsn
java.lang.Object
com.android.dx.dex.code.DalvInsn
- Direct Known Subclasses:
FixedSizeInsn
,VariableSizeInsn
,ZeroSizeInsn
Base class for Dalvik instructions.
-
Constructor Summary
ConstructorDescriptionDalvInsn
(Dop opcode, SourcePosition position, RegisterSpecList registers) Constructs an instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract String
Gets the string form for any arguments to this instance.abstract int
codeSize()
Gets the size of this instruction, in 16-bit code units.Helper which returns the comment form of the associated constants for inclusion in a human oriented listing dump.Helper which returns the string form of the associated constants for inclusion in a human oriented listing dump.expandedPrefix
(BitSet compatRegs) Gets the instruction prefix required, if any, to use in an expanded version of this instance.expandedSuffix
(BitSet compatRegs) Gets the instruction suffix required, if any, to use in an expanded version of this instance.expandedVersion
(BitSet compatRegs) Gets the instruction that is equivalent to this one, except that it replaces incompatible registers with sequential registers starting at0
(storing the result, if any, in register0
as well).final int
Gets the output address of this instruction, if it is known.Gets the instruction that is equivalent to this one, except that it uses sequential registers starting at0
(storing the result, if any, in register0
as well).final int
getMinimumRegisterRequirement
(BitSet compatRegs) Gets the minimum distinct registers required for this instruction.final int
Gets the address immediately after this instance.final Dop
Gets the opcode.final SourcePosition
Gets the source position.final RegisterSpecList
Gets the register list for this instruction.final boolean
Gets whether the address of this instruction is known.final boolean
Returns whether this instance's opcode uses a result register.final String
Gets the short identifier for this instruction.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.protected abstract String
listingString0
(boolean noteIndices) Helper forlistingString(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.final void
setAddress
(int address) Sets the output address.final String
toString()
withMapper
(RegisterMapper mapper) Returns an instance that is just like this one, except that the register list is mapped by usingmapper
.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.
-
Constructor Details
-
DalvInsn
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 asRegisterSpecList.EMPTY
.- Parameters:
opcode
- the opcode; one of the constants fromDops
position
-non-null;
source positionregisters
-non-null;
register list, including a result register if appropriate (that is, registers may be either ins and outs)
-
-
Method Details
-
makeMove
Makes a move instruction, appropriate and ideal for the given arguments.- Parameters:
position
-non-null;
source position informationdest
-non-null;
destination registersrc
-non-null;
source register- Returns:
non-null;
an appropriately-constructed instance
-
toString
-
hasAddress
public final boolean hasAddress()Gets whether the address of this instruction is known.- See Also:
-
getAddress
public final int getAddress()Gets the output address of this instruction, if it is known. This throws aRuntimeException
if it has not yet been set.- Returns:
>= 0;
the output address- See Also:
-
getOpcode
Gets the opcode.- Returns:
non-null;
the opcode
-
getPosition
Gets the source position.- Returns:
non-null;
the source position
-
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 forgetOpcode().hasResult()
.- Returns:
true
iff this opcode uses a result register
-
getMinimumRegisterRequirement
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
Gets the instruction that is equivalent to this one, except that it uses sequential registers starting at0
(storing the result, if any, in register0
as well).- Returns:
non-null;
the replacement
-
expandedPrefix
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:
-
expandedSuffix
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
Gets the instruction that is equivalent to this one, except that it replaces incompatible registers with sequential registers starting at0
(storing the result, if any, in register0
as well). The sequence of instructions fromexpandedPrefix(java.util.BitSet)
andexpandedSuffix(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 bygetMinimumRegisterRequirement(java.util.BitSet)
.- Parameters:
compatRegs
-non-null;
set of compatible registers- Returns:
non-null;
the replacement
-
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
Returns the string form of this instance suitable for inclusion in a human-oriented listing dump. This method will returnnull
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 wellwidth
-width >= 0;
the width of the output or0
for unlimited widthnoteIndices
- whether to include an explicit notation of constant pool indices- Returns:
null-ok;
the string form ornull
if this instance should not appear in a listing
-
setAddress
public final void setAddress(int address) Sets the output address.- Parameters:
address
-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
Returns an instance that is just like this one, except that the register list is mapped by usingmapper
.- 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
Writes this instance to the given output. This method should never annotate the output.- Parameters:
out
-non-null;
where to write to
-
withOpcode
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
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
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
Gets the string form for any arguments to this instance. Subclasses must override this.- Returns:
null-ok;
the string version of any arguments ornull
if there are none
-
listingString0
Helper forlistingString(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 returnnull
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
-
cstString
Helper which returns the string form of the associated constants for inclusion in a human oriented listing dump. This method is only implemented for instructions with one or more constants.- Returns:
- the constant as a string.
-
cstComment
Helper which returns the comment form of the associated constants for inclusion in a human oriented listing dump. This method is only implemented for instructions with one or more constants.- Returns:
- the comment as a string.
-