Class DalvInsn
java.lang.Object
com.android.dx.dex.code.DalvInsn
- Direct Known Subclasses:
FixedSizeInsn, VariableSizeInsn, ZeroSizeInsn
Base class for Dalvik instructions.
-
Constructor Summary
ConstructorsConstructorDescriptionDalvInsn(Dop opcode, SourcePosition position, RegisterSpecList registers) Constructs an instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract StringGets the string form for any arguments to this instance.abstract intcodeSize()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 register0as well).final intGets 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 register0as well).final intgetMinimumRegisterRequirement(BitSet compatRegs) Gets the minimum distinct registers required for this instruction.final intGets the address immediately after this instance.final DopGets the opcode.final SourcePositionGets the source position.final RegisterSpecListGets the register list for this instruction.final booleanGets whether the address of this instruction is known.final booleanReturns whether this instance's opcode uses a result register.final StringGets the short identifier for this instruction.final StringlistingString(String prefix, int width, boolean noteIndices) Returns the string form of this instance suitable for inclusion in a human-oriented listing dump.protected abstract StringlistingString0(boolean noteIndices) Helper forlistingString(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 SimpleInsnmakeMove(SourcePosition position, RegisterSpec dest, RegisterSpec src) Makes a move instruction, appropriate and ideal for the given arguments.final voidsetAddress(int address) Sets the output address.final StringtoString()withMapper(RegisterMapper mapper) Returns an instance that is just like this one, except that the register list is mapped by usingmapper.abstract DalvInsnwithOpcode(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 DalvInsnwithRegisterOffset(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 DalvInsnwithRegisters(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 voidwriteTo(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
nopor 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 fromDopsposition-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 aRuntimeExceptionif it has not yet been set.- Returns:
>= 0;the output address- See Also:
-
getOpcode
-
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:
trueiff 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 register0as 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 register0as well). The sequence of instructions fromexpandedPrefix(BitSet)andexpandedSuffix(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(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 returnnullif 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 or0for unlimited widthnoteIndices- whether to include an explicit notation of constant pool indices- Returns:
null-ok;the string form ornullif 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
-
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 ornullif there are none
-
listingString0
Helper forlistingString(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 returnnullif 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.
-