Class InsnFormat
java.lang.Object
com.android.dx.dex.code.InsnFormat
- Direct Known Subclasses:
Form10t, Form10x, Form11n, Form11x, Form12x, Form20t, Form21c, Form21h, Form21s, Form21t, Form22b, Form22c, Form22s, Form22t, Form22x, Form23x, Form30t, Form31c, Form31i, Form31t, Form32x, Form35c, Form3rc, Form45cc, Form4rcc, Form51l, SpecialFormat
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanflag to enable/disable the new extended opcode formats; meant as a temporary measure until VM support for the salient opcodes is added. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static intHelper method to extract the callout-argument index from an appropriate instruction.protected static StringbranchComment(DalvInsn insn) Helper method to return the comment for a branch.booleanbranchFits(TargetInsn insn) Returns whether or not the given instruction's branch offset will fit in this instance's format.protected static StringbranchString(DalvInsn insn) Helper method to return a branch address string.abstract intcodeSize()Gets the code size of instructions that use this format.protected static shortcodeUnit(int low, int high) Helper method to combine two bytes into a code unit.protected static shortcodeUnit(int n0, int n1, int n2, int n3) Helper method to combine four nibbles into a code unit.compatibleRegs(DalvInsn insn) Returns which of a given instruction's registers will fit in this instance's format.abstract StringinsnArgString(DalvInsn insn) Returns the string form of the arguments to the given instruction.abstract StringinsnCommentString(DalvInsn insn, boolean noteIndices) Returns the associated comment for the given instruction, if any.abstract booleanisCompatible(DalvInsn insn) Returns whether or not the given instruction's arguments will fit in this instance's format.protected static booleanHelper method to determine if a list of registers are sequential, including degenerate cases for empty or single-element lists.final StringlistingString(DalvInsn insn, boolean noteIndices) Returns the string form, suitable for inclusion in a listing dump, of the given instruction.protected static StringliteralBitsComment(CstLiteralBits value, int width) Helper method to return a literal bits comment string.protected static StringliteralBitsString(CstLiteralBits value) Helper method to return a literal bits argument string.protected static intmakeByte(int low, int high) Helper method to combine two nibbles into a byte.protected static shortopcodeUnit(DalvInsn insn) Helper method to get an extended (16-bit) opcode out of an instruction, returning it as a code unit.protected static shortopcodeUnit(DalvInsn insn, int arg) Helper method to combine an opcode and a second byte of data into the appropriate form for emitting into a code buffer.protected static StringHelper method to return a register list string.protected static StringHelper method to return a register range string.protected static booleansignedFitsInByte(int value) Helper method to determine if a signed int value fits in a byte.protected static booleansignedFitsInNibble(int value) Helper method to determine if a signed int value fits in a nibble.protected static booleansignedFitsInShort(int value) Helper method to determine if a signed int value fits in a short.protected static booleanunsignedFitsInByte(int value) Helper method to determine if an unsigned int value fits in a byte.protected static booleanunsignedFitsInNibble(int value) Helper method to determine if an unsigned int value fits in a nibble.protected static booleanunsignedFitsInShort(int value) Helper method to determine if an unsigned int value fits in a short.protected static voidwrite(AnnotatedOutput out, short c0) Writes one code unit to the given output destination.protected static voidwrite(AnnotatedOutput out, short c0, int c1c2) Writes three code units to the given output destination, where the second and third are represented as singleintand emitted in little-endian order.protected static voidwrite(AnnotatedOutput out, short c0, int c1c2, short c3) Writes four code units to the given output destination, where the second and third are represented as singleintand emitted in little-endian order.protected static voidwrite(AnnotatedOutput out, short c0, int c1c2, short c3, short c4) Writes five code units to the given output destination, where the second and third are represented as singleintand emitted in little-endian order.protected static voidwrite(AnnotatedOutput out, short c0, long c1c2c3c4) Writes five code units to the given output destination, where the second through fifth are represented as singlelongand emitted in little-endian order.protected static voidwrite(AnnotatedOutput out, short c0, short c1) Writes two code units to the given output destination.protected static voidwrite(AnnotatedOutput out, short c0, short c1, short c2) Writes three code units to the given output destination.protected static voidwrite(AnnotatedOutput out, short c0, short c1, short c2, short c3) Writes four code units to the given output destination.protected static voidwrite(AnnotatedOutput out, short c0, short c1, short c2, short c3, short c4) Writes five code units to the given output destination.abstract voidwriteTo(AnnotatedOutput out, DalvInsn insn) Writes the code units for the given instruction to the given output destination.
-
Field Details
-
ALLOW_EXTENDED_OPCODES
public static final boolean ALLOW_EXTENDED_OPCODESflag to enable/disable the new extended opcode formats; meant as a temporary measure until VM support for the salient opcodes is added. TODO: Remove this declaration when the VM can deal.- See Also:
-
-
Constructor Details
-
InsnFormat
public InsnFormat()
-
-
Method Details
-
listingString
Returns the string form, suitable for inclusion in a listing dump, of the given instruction. The instruction must be of this instance's format for proper operation.- Parameters:
insn-non-null;the instructionnoteIndices- whether to include an explicit notation of constant pool indices- Returns:
non-null;the string form
-
insnArgString
Returns the string form of the arguments to the given instruction. The instruction must be of this instance's format. If the instruction has no arguments, then the result should be"", notnull.Subclasses must override this method.
- Parameters:
insn-non-null;the instruction- Returns:
non-null;the string form
-
insnCommentString
Returns the associated comment for the given instruction, if any. The instruction must be of this instance's format. If the instruction has no comment, then the result should be"", notnull.Subclasses must override this method.
- Parameters:
insn-non-null;the instructionnoteIndices- whether to include an explicit notation of constant pool indices- Returns:
non-null;the string form
-
codeSize
public abstract int codeSize()Gets the code size of instructions that use this format. The size is a number of 16-bit code units, not bytes. This should throw an exception if this format is of variable size.- Returns:
>= 0;the instruction length in 16-bit code units
-
isCompatible
Returns whether or not the given instruction's arguments will fit in this instance's format. This includes such things as counting register arguments, checking register ranges, and making sure that additional arguments are of appropriate types and are in-range. If this format has a branch target but the instruction's branch offset is unknown, this method will simply not check the offset.Subclasses must override this method.
- Parameters:
insn-non-null;the instruction to check- Returns:
trueiff the instruction's arguments are appropriate for this instance, orfalseif not
-
compatibleRegs
Returns which of a given instruction's registers will fit in this instance's format.The default implementation of this method always returns an empty BitSet. Subclasses must override this method if they have registers.
- Parameters:
insn-non-null;the instruction to check- Returns:
non-null;a BitSet flagging registers in the register list that are compatible to this format
-
branchFits
Returns whether or not the given instruction's branch offset will fit in this instance's format. This always returnsfalsefor formats that don't include a branch offset.The default implementation of this method always returns
false. Subclasses must override this method if they include branch offsets.- Parameters:
insn-non-null;the instruction to check- Returns:
trueiff the instruction's branch offset is appropriate for this instance, orfalseif not
-
writeTo
Writes the code units for the given instruction to the given output destination. The instruction must be of this instance's format.Subclasses must override this method.
- Parameters:
out-non-null;the output destination to write toinsn-non-null;the instruction to write
-
regListString
Helper method to return a register list string.- Parameters:
list-non-null;the list of registers- Returns:
non-null;the string form
-
regRangeString
Helper method to return a register range string.- Parameters:
list-non-null;the list of registers (which must be sequential)- Returns:
non-null;the string form
-
literalBitsString
Helper method to return a literal bits argument string.- Parameters:
value- the value- Returns:
non-null;the string form
-
literalBitsComment
Helper method to return a literal bits comment string.- Parameters:
value- the valuewidth- the width of the constant, in bits (used for displaying the uninterpreted bits; one of:4 8 16 32 64- Returns:
non-null;the comment
-
branchString
-
branchComment
-
signedFitsInNibble
protected static boolean signedFitsInNibble(int value) Helper method to determine if a signed int value fits in a nibble.- Parameters:
value- the value in question- Returns:
trueiff it's in the range -8..+7
-
unsignedFitsInNibble
protected static boolean unsignedFitsInNibble(int value) Helper method to determine if an unsigned int value fits in a nibble.- Parameters:
value- the value in question- Returns:
trueiff it's in the range 0..0xf
-
signedFitsInByte
protected static boolean signedFitsInByte(int value) Helper method to determine if a signed int value fits in a byte.- Parameters:
value- the value in question- Returns:
trueiff it's in the range -0x80..+0x7f
-
unsignedFitsInByte
protected static boolean unsignedFitsInByte(int value) Helper method to determine if an unsigned int value fits in a byte.- Parameters:
value- the value in question- Returns:
trueiff it's in the range 0..0xff
-
signedFitsInShort
protected static boolean signedFitsInShort(int value) Helper method to determine if a signed int value fits in a short.- Parameters:
value- the value in question- Returns:
trueiff it's in the range -0x8000..+0x7fff
-
unsignedFitsInShort
protected static boolean unsignedFitsInShort(int value) Helper method to determine if an unsigned int value fits in a short.- Parameters:
value- the value in question- Returns:
trueiff it's in the range 0..0xffff
-
isRegListSequential
Helper method to determine if a list of registers are sequential, including degenerate cases for empty or single-element lists.- Parameters:
list-non-null;the list of registers- Returns:
trueiff the list is sequentially ordered
-
argIndex
Helper method to extract the callout-argument index from an appropriate instruction.- Parameters:
insn-non-null;the instruction- Returns:
>= 0;the callout argument index
-
opcodeUnit
Helper method to combine an opcode and a second byte of data into the appropriate form for emitting into a code buffer.- Parameters:
insn-non-null;the instruction containing the opcodearg-0..255;arbitrary other byte value- Returns:
- combined value
-
opcodeUnit
Helper method to get an extended (16-bit) opcode out of an instruction, returning it as a code unit. The opcode must be an extended opcode.- Parameters:
insn-non-null;the instruction containing the extended opcode- Returns:
- the opcode as a code unit
-
codeUnit
protected static short codeUnit(int low, int high) Helper method to combine two bytes into a code unit.- Parameters:
low-0..255;low bytehigh-0..255;high byte- Returns:
- combined value
-
codeUnit
protected static short codeUnit(int n0, int n1, int n2, int n3) Helper method to combine four nibbles into a code unit.- Parameters:
n0-0..15;low nibblen1-0..15;medium-low nibblen2-0..15;medium-high nibblen3-0..15;high nibble- Returns:
- combined value
-
makeByte
protected static int makeByte(int low, int high) Helper method to combine two nibbles into a byte.- Parameters:
low-0..15;low nibblehigh-0..15;high nibble- Returns:
0..255;combined value
-
write
Writes one code unit to the given output destination.- Parameters:
out-non-null;where to write toc0- code unit to write
-
write
Writes two code units to the given output destination.- Parameters:
out-non-null;where to write toc0- code unit to writec1- code unit to write
-
write
Writes three code units to the given output destination.- Parameters:
out-non-null;where to write toc0- code unit to writec1- code unit to writec2- code unit to write
-
write
Writes four code units to the given output destination.- Parameters:
out-non-null;where to write toc0- code unit to writec1- code unit to writec2- code unit to writec3- code unit to write
-
write
Writes five code units to the given output destination.- Parameters:
out-non-null;where to write toc0- code unit to writec1- code unit to writec2- code unit to writec3- code unit to writec4- code unit to write
-
write
Writes three code units to the given output destination, where the second and third are represented as singleintand emitted in little-endian order.- Parameters:
out-non-null;where to write toc0- code unit to writec1c2- code unit pair to write
-
write
Writes four code units to the given output destination, where the second and third are represented as singleintand emitted in little-endian order.- Parameters:
out-non-null;where to write toc0- code unit to writec1c2- code unit pair to writec3- code unit to write
-
write
Writes five code units to the given output destination, where the second and third are represented as singleintand emitted in little-endian order.- Parameters:
out-non-null;where to write toc0- code unit to writec1c2- code unit pair to writec3- code unit to writec4- code unit to write
-
write
Writes five code units to the given output destination, where the second through fifth are represented as singlelongand emitted in little-endian order.- Parameters:
out-non-null;where to write toc0- code unit to writec1c2c3c4- code unit quad to write
-