Top Description Fields Constructors Methods
org.droidparts.dexmaker.dx.dex.code

public abstract Class DalvInsn

extends Object
Class Inheritance
Known Direct Subclasses
org.droidparts.dexmaker.dx.dex.code.FixedSizeInsn, org.droidparts.dexmaker.dx.dex.code.VariableSizeInsn, org.droidparts.dexmaker.dx.dex.code.ZeroSizeInsn
Imports
org.droidparts.dexmaker.dx.rop.code.RegisterSpec, .RegisterSpecList, .SourcePosition, org.droidparts.dexmaker.dx.util.AnnotatedOutput, .Hex, .TwoColumnOutput, java.util.BitSet

Base class for Dalvik instructions.

Field Summary

Modifier and TypeField and Description
private int
address

the actual output address of this instance, if known, or -1 if not

private final Dop
opcode

the opcode; one of the constants from Dops

private final SourcePosition
position

non-null; source position

private final RegisterSpecList
registers

non-null; list of register arguments

Constructor Summary

AccessConstructor and Description
public
DalvInsn(Dop
the opcode; one of the constants from Dops
opcode
,
SourcePosition
non-null; source position
position
,
RegisterSpecList
non-null; register list, including a result register if appropriate (that is, registers may be either ins and outs)
registers
)

Constructs an instance.

Method Summary

Modifier and TypeMethod and Description
protected abstract String

Returns:

null-ok; the string version of any arguments or null if there are none
argString
()

Gets the string form for any arguments to this instance.

public abstract int

Returns:

>= 0; the code size of this instruction
codeSize
()

Gets the size of this instruction, in 16-bit code units.

public DalvInsn

Returns:

null-ok; the prefix, if any
expandedPrefix
(BitSet
non-null; set of compatible registers
compatRegs
)

Gets the instruction prefix required, if any, to use in an expanded version of this instance.

public DalvInsn

Returns:

null-ok; the suffix, if any
expandedSuffix
(BitSet
non-null; set of compatible registers
compatRegs
)

Gets the instruction suffix required, if any, to use in an expanded version of this instance.

public DalvInsn

Returns:

non-null; the replacement
expandedVersion
(BitSet
non-null; set of compatible registers
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).

public final int

Returns:

>= 0; the output address
getAddress
()

Gets the output address of this instruction, if it is known.

public DalvInsn

Returns:

non-null; the replacement
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).

public final int

Returns:

>= 0; the minimum distinct register requirement
getMinimumRegisterRequirement
(BitSet
non-null; set of compatible registers
compatRegs
)

Gets the minimum distinct registers required for this instruction.

public final int

Returns:

>= 0; the next address
getNextAddress
()

Gets the address immediately after this instance.

public final Dop

Returns:

non-null; the opcode
getOpcode
()

Gets the opcode.

public final SourcePosition

Returns:

non-null; the source position
getPosition
()

Gets the source position.

public final RegisterSpecList

Returns:

non-null; the registers
getRegisters
()

Gets the register list for this instruction.

public final boolean
hasAddress()

Gets whether the address of this instruction is known.

public final boolean

Returns:

true iff this opcode uses a result register
hasResult
()

Returns whether this instance's opcode uses a result register.

public final String

Returns:

non-null; the identifier
identifierString
()

Gets the short identifier for this instruction.

public final String

Returns:

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

Returns the string form of this instance suitable for inclusion in a human-oriented listing dump.

protected abstract String

Returns:

null-ok; the listing string
listingString0
(boolean
whether to include an explicit notation of constant pool indices
noteIndices
)

Helper for listingString, 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.

public static SimpleInsn

Returns:

non-null; an appropriately-constructed instance
makeMove
(SourcePosition
non-null; source position information
position
,
RegisterSpec
non-null; destination register
dest
,
RegisterSpec
non-null; source register
src
)

Makes a move instruction, appropriate and ideal for the given arguments.

public final void
setAddress(int
>= 0; the output address
address
)

Sets the output address.

public final String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public abstract DalvInsn

Returns:

non-null; an appropriately-constructed instance
withOpcode
(Dop
non-null; the new opcode
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.

public abstract DalvInsn

Returns:

non-null; an appropriately-constructed instance
withRegisterOffset
(int
the amount to offset register references by
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.

public abstract DalvInsn

Returns:

non-null; an appropriately-constructed instance
withRegisters
(RegisterSpecList
non-null; new register list
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.

public abstract void
writeTo(AnnotatedOutput
non-null; where to write to
out
)

Writes this instance to the given output.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

addressback to summary
private int address

the actual output address of this instance, if known, or -1 if not

opcodeback to summary
private final Dop opcode

the opcode; one of the constants from Dops

positionback to summary
private final SourcePosition position

non-null; source position

registersback to summary
private final RegisterSpecList registers

non-null; list of register arguments

Constructor Detail

DalvInsnback to summary
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:Dop

the opcode; one of the constants from Dops

position:SourcePosition

non-null; source position

registers:RegisterSpecList

non-null; register list, including a result register if appropriate (that is, registers may be either ins and outs)

Method Detail

argStringback to summary
protected abstract String argString()

Gets the string form for any arguments to this instance. Subclasses must override this.

Returns:String

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

codeSizeback to summary
public abstract int codeSize()

Gets the size of this instruction, in 16-bit code units.

Returns:int

>= 0; the code size of this instruction

expandedPrefixback to summary
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:BitSet

non-null; set of compatible registers

Returns:DalvInsn

null-ok; the prefix, if any

See Also
expandedVersion
expandedSuffixback to summary
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:BitSet

non-null; set of compatible registers

Returns:DalvInsn

null-ok; the suffix, if any

See Also
expandedVersion
expandedVersionback to summary
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 and expandedSuffix (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.

Parameters
compatRegs:BitSet

non-null; set of compatible registers

Returns:DalvInsn

non-null; the replacement

getAddressback to summary
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:int

>= 0; the output address

See Also
setAddress
getLowRegVersionback to summary
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:DalvInsn

non-null; the replacement

getMinimumRegisterRequirementback to summary
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:BitSet

non-null; set of compatible registers

Returns:int

>= 0; the minimum distinct register requirement

getNextAddressback to summary
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:int

>= 0; the next address

getOpcodeback to summary
public final Dop getOpcode()

Gets the opcode.

Returns:Dop

non-null; the opcode

getPositionback to summary
public final SourcePosition getPosition()

Gets the source position.

Returns:SourcePosition

non-null; the source position

getRegistersback to summary
public final RegisterSpecList getRegisters()

Gets the register list for this instruction.

Returns:RegisterSpecList

non-null; the registers

hasAddressback to summary
public final boolean hasAddress()

Gets whether the address of this instruction is known.

See Also
getAddress, setAddress
hasResultback to summary
public final boolean hasResult()

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

Returns:boolean

true iff this opcode uses a result register

identifierStringback to summary
public final String identifierString()

Gets the short identifier for this instruction. This is its address, if assigned, or its identity hashcode if not.

Returns:String

non-null; the identifier

listingStringback to summary
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:String

non-null; prefix before the address; each follow-on line will be indented to match as well

width:int

>= 0; the width of the output or 0 for unlimited width

noteIndices:boolean

whether to include an explicit notation of constant pool indices

Returns:String

null-ok; the string form or null if this instance should not appear in a listing

listingString0back to summary
protected abstract String listingString0(boolean noteIndices)

Helper for listingString, 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:boolean

whether to include an explicit notation of constant pool indices

Returns:String

null-ok; the listing string

makeMoveback to summary
public static SimpleInsn makeMove(SourcePosition position, RegisterSpec dest, RegisterSpec src)

Makes a move instruction, appropriate and ideal for the given arguments.

Parameters
position:SourcePosition

non-null; source position information

dest:RegisterSpec

non-null; destination register

src:RegisterSpec

non-null; source register

Returns:SimpleInsn

non-null; an appropriately-constructed instance

setAddressback to summary
public final void setAddress(int address)

Sets the output address.

Parameters
address:int

>= 0; the output address

toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
withOpcodeback to summary
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:Dop

non-null; the new opcode

Returns:DalvInsn

non-null; an appropriately-constructed instance

withRegisterOffsetback to summary
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:int

the amount to offset register references by

Returns:DalvInsn

non-null; an appropriately-constructed instance

withRegistersback to summary
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:RegisterSpecList

non-null; new register list

Returns:DalvInsn

non-null; an appropriately-constructed instance

writeToback to summary
public abstract void writeTo(AnnotatedOutput out)

Writes this instance to the given output. This method should never annotate the output.

Parameters
out:AnnotatedOutput

non-null; where to write to