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

public abstract Class InsnFormat

extends Object
Class Inheritance
Known Direct Subclasses
org.droidparts.dexmaker.dx.dex.code.form.Form10t, org.droidparts.dexmaker.dx.dex.code.form.Form10x, org.droidparts.dexmaker.dx.dex.code.form.Form11n, org.droidparts.dexmaker.dx.dex.code.form.Form11x, org.droidparts.dexmaker.dx.dex.code.form.Form12x, org.droidparts.dexmaker.dx.dex.code.form.Form20t, org.droidparts.dexmaker.dx.dex.code.form.Form21c, org.droidparts.dexmaker.dx.dex.code.form.Form21h, org.droidparts.dexmaker.dx.dex.code.form.Form21s, org.droidparts.dexmaker.dx.dex.code.form.Form21t, org.droidparts.dexmaker.dx.dex.code.form.Form22b, org.droidparts.dexmaker.dx.dex.code.form.Form22c, org.droidparts.dexmaker.dx.dex.code.form.Form22s, org.droidparts.dexmaker.dx.dex.code.form.Form22t, org.droidparts.dexmaker.dx.dex.code.form.Form22x, org.droidparts.dexmaker.dx.dex.code.form.Form23x, org.droidparts.dexmaker.dx.dex.code.form.Form30t, org.droidparts.dexmaker.dx.dex.code.form.Form31c, org.droidparts.dexmaker.dx.dex.code.form.Form31i, org.droidparts.dexmaker.dx.dex.code.form.Form31t, org.droidparts.dexmaker.dx.dex.code.form.Form32s, org.droidparts.dexmaker.dx.dex.code.form.Form32x, org.droidparts.dexmaker.dx.dex.code.form.Form33x, org.droidparts.dexmaker.dx.dex.code.form.Form35c, org.droidparts.dexmaker.dx.dex.code.form.Form3rc, org.droidparts.dexmaker.dx.dex.code.form.Form41c, org.droidparts.dexmaker.dx.dex.code.form.Form51l, org.droidparts.dexmaker.dx.dex.code.form.Form52c, org.droidparts.dexmaker.dx.dex.code.form.Form5rc, org.droidparts.dexmaker.dx.dex.code.form.SpecialFormat
Imports
org.droidparts.dexmaker.dx.rop.code.RegisterSpec, .RegisterSpecList, org.droidparts.dexmaker.dx.rop.cst.*, org.droidparts.dexmaker.dx.util.AnnotatedOutput, .Hex, java.util.BitSet

Base class for all instruction format handlers. Instruction format handlers know how to translate DalvInsn instances into streams of code units, as well as human-oriented listing strings representing such translations.

Field Summary

Modifier and TypeField and Description
public static boolean
ALLOW_EXTENDED_OPCODES

flag to enable/disable the new extended opcode formats; meant as a temporary measure until VM support for the salient opcodes is added.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected static int

Returns:

>= 0; the callout argument index
argIndex
(DalvInsn
non-null; the instruction
insn
)

Helper method to extract the callout-argument index from an appropriate instruction.

protected static String

Returns:

non-null; the comment
branchComment
(DalvInsn
non-null; the instruction in question
insn
)

Helper method to return the comment for a branch.

public boolean

Returns:

true iff the instruction's branch offset is appropriate for this instance, or false if not
branchFits
(TargetInsn
non-null; the instruction to check
insn
)

Returns whether or not the given instruction's branch offset will fit in this instance's format.

protected static String

Returns:

non-null; the string form of the instruction's branch target
branchString
(DalvInsn
non-null; the instruction in question
insn
)

Helper method to return a branch address string.

public abstract int

Returns:

>= 0; the instruction length in 16-bit code units
codeSize
()

Gets the code size of instructions that use this format.

protected static short

Returns:

combined value
codeUnit
(int
0..255; low byte
low
,
int
0..255; high byte
high
)

Helper method to combine two bytes into a code unit.

protected static short

Returns:

combined value
codeUnit
(int
0..15; low nibble
n0
,
int
0..15; medium-low nibble
n1
,
int
0..15; medium-high nibble
n2
,
int
0..15; high nibble
n3
)

Helper method to combine four nibbles into a code unit.

public BitSet

Returns:

non-null; a BitSet flagging registers in the register list that are compatible to this format
compatibleRegs
(DalvInsn
non-null; the instruction to check
insn
)

Returns which of a given instruction's registers will fit in this instance's format.

protected static String

Returns:

non-null; comment string representing the constant
cstComment
(DalvInsn
non-null; a constant-bearing instruction
insn
)

Helper method to return an instruction comment for a constant.

protected static String

Returns:

non-null; the human string form of the contained constant
cstString
(DalvInsn
non-null; a constant-bearing instruction
insn
)

Helper method to return the constant string for a CstInsn in human form.

public abstract String

Returns:

non-null; the string form
insnArgString
(DalvInsn
non-null; the instruction
insn
)

Returns the string form of the arguments to the given instruction.

public abstract String

Returns:

non-null; the string form
insnCommentString
(DalvInsn
non-null; the instruction
insn
,
boolean
whether to include an explicit notation of constant pool indices
noteIndices
)

Returns the associated comment for the given instruction, if any.

public abstract boolean

Returns:

true iff the instruction's arguments are appropriate for this instance, or false if not
isCompatible
(DalvInsn
non-null; the instruction to check
insn
)

Returns whether or not the given instruction's arguments will fit in this instance's format.

protected static boolean

Returns:

true iff the list is sequentially ordered
isRegListSequential
(RegisterSpecList
non-null; the list of registers
list
)

Helper method to determine if a list of registers are sequential, including degenerate cases for empty or single-element lists.

public final String

Returns:

non-null; the string form
listingString
(DalvInsn
non-null; the instruction
insn
,
boolean
whether to include an explicit notation of constant pool indices
noteIndices
)

Returns the string form, suitable for inclusion in a listing dump, of the given instruction.

protected static String

Returns:

non-null; the comment
literalBitsComment
(CstLiteralBits
the value
value
,
int
the width of the constant, in bits (used for displaying the uninterpreted bits; one of: 4 8 16 32 64
width
)

Helper method to return a literal bits comment string.

protected static String

Returns:

non-null; the string form
literalBitsString
(CstLiteralBits
the value
value
)

Helper method to return a literal bits argument string.

protected static int

Returns:

0..255; combined value
makeByte
(int
0..15; low nibble
low
,
int
0..15; high nibble
high
)

Helper method to combine two nibbles into a byte.

protected static short

Returns:

combined value
opcodeUnit
(DalvInsn
non-null; the instruction containing the opcode
insn
,
int
0..255; arbitrary other byte value
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 short

Returns:

the opcode as a code unit
opcodeUnit
(DalvInsn
non-null; the instruction containing the extended opcode
insn
)

Helper method to get an extended (16-bit) opcode out of an instruction, returning it as a code unit.

protected static String

Returns:

non-null; the string form
regListString
(RegisterSpecList
non-null; the list of registers
list
)

Helper method to return a register list string.

protected static String

Returns:

non-null; the string form
regRangeString
(RegisterSpecList
non-null; the list of registers (which must be sequential)
list
)

Helper method to return a register range string.

protected static boolean

Returns:

true iff it's in the range -0x80..+0x7f
signedFitsInByte
(int
the value in question
value
)

Helper method to determine if a signed int value fits in a byte.

protected static boolean

Returns:

true iff it's in the range -8..+7
signedFitsInNibble
(int
the value in question
value
)

Helper method to determine if a signed int value fits in a nibble.

protected static boolean

Returns:

true iff it's in the range -0x8000..+0x7fff
signedFitsInShort
(int
the value in question
value
)

Helper method to determine if a signed int value fits in a short.

protected static boolean

Returns:

true iff it's in the range 0..0xff
unsignedFitsInByte
(int
the value in question
value
)

Helper method to determine if an unsigned int value fits in a byte.

protected static boolean

Returns:

true iff it's in the range 0..0xf
unsignedFitsInNibble
(int
the value in question
value
)

Helper method to determine if an unsigned int value fits in a nibble.

protected static boolean

Returns:

true iff it's in the range 0..0xffff
unsignedFitsInShort
(int
the value in question
value
)

Helper method to determine if an unsigned int value fits in a short.

protected static void
write(AnnotatedOutput
non-null; where to write to
out
,
short
code unit to write
c0
)

Writes one code unit to the given output destination.

protected static void
write(AnnotatedOutput
non-null; where to write to
out
,
short
code unit to write
c0
,
short
code unit to write
c1
)

Writes two code units to the given output destination.

protected static void
write(AnnotatedOutput
non-null; where to write to
out
,
short
code unit to write
c0
,
short
code unit to write
c1
,
short
code unit to write
c2
)

Writes three code units to the given output destination.

protected static void
write(AnnotatedOutput
non-null; where to write to
out
,
short
code unit to write
c0
,
short
code unit to write
c1
,
short
code unit to write
c2
,
short
code unit to write
c3
)

Writes four code units to the given output destination.

protected static void
write(AnnotatedOutput
non-null; where to write to
out
,
short
code unit to write
c0
,
short
code unit to write
c1
,
short
code unit to write
c2
,
short
code unit to write
c3
,
short
code unit to write
c4
)

Writes five code units to the given output destination.

protected static void
write(AnnotatedOutput
non-null; where to write to
out
,
short
code unit to write
c0
,
int
code unit pair to write
c1c2
)

Writes three code units to the given output destination, where the second and third are represented as single int and emitted in little-endian order.

protected static void
write(AnnotatedOutput
non-null; where to write to
out
,
short
code unit to write
c0
,
int
code unit pair to write
c1c2
,
short
code unit to write
c3
)

Writes four code units to the given output destination, where the second and third are represented as single int and emitted in little-endian order.

protected static void
write(AnnotatedOutput
non-null; where to write to
out
,
short
code unit to write
c0
,
int
code unit pair to write
c1c2
,
short
code unit to write
c3
,
short
code unit to write
c4
)

Writes five code units to the given output destination, where the second and third are represented as single int and emitted in little-endian order.

protected static void
write(AnnotatedOutput
non-null; where to write to
out
,
short
code unit to write
c0
,
long
code unit quad to write
c1c2c3c4
)

Writes five code units to the given output destination, where the second through fifth are represented as single long and emitted in little-endian order.

public abstract void
writeTo(AnnotatedOutput
non-null; the output destination to write to
out
,
DalvInsn
non-null; the instruction to write
insn
)

Writes the code units for the given instruction to the given output destination.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALLOW_EXTENDED_OPCODESback to summary
public static boolean ALLOW_EXTENDED_OPCODES

flag 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.

Constructor Detail

InsnFormatback to summary
public InsnFormat()

Method Detail

argIndexback to summary
protected static int argIndex(DalvInsn insn)

Helper method to extract the callout-argument index from an appropriate instruction.

Parameters
insn:DalvInsn

non-null; the instruction

Returns:int

>= 0; the callout argument index

branchCommentback to summary
protected static String branchComment(DalvInsn insn)

Helper method to return the comment for a branch.

Parameters
insn:DalvInsn

non-null; the instruction in question

Returns:String

non-null; the comment

branchFitsback to summary
public boolean branchFits(TargetInsn insn)

Returns whether or not the given instruction's branch offset will fit in this instance's format. This always returns false for 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:TargetInsn

non-null; the instruction to check

Returns:boolean

true iff the instruction's branch offset is appropriate for this instance, or false if not

branchStringback to summary
protected static String branchString(DalvInsn insn)

Helper method to return a branch address string.

Parameters
insn:DalvInsn

non-null; the instruction in question

Returns:String

non-null; the string form of the instruction's branch target

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

>= 0; the instruction length in 16-bit code units

codeUnitback to summary
protected static short codeUnit(int low, int high)

Helper method to combine two bytes into a code unit.

Parameters
low:int

0..255; low byte

high:int

0..255; high byte

Returns:short

combined value

codeUnitback to summary
protected static short codeUnit(int n0, int n1, int n2, int n3)

Helper method to combine four nibbles into a code unit.

Parameters
n0:int

0..15; low nibble

n1:int

0..15; medium-low nibble

n2:int

0..15; medium-high nibble

n3:int

0..15; high nibble

Returns:short

combined value

compatibleRegsback to summary
public BitSet compatibleRegs(DalvInsn insn)

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:DalvInsn

non-null; the instruction to check

Returns:BitSet

non-null; a BitSet flagging registers in the register list that are compatible to this format

cstCommentback to summary
protected static String cstComment(DalvInsn insn)

Helper method to return an instruction comment for a constant.

Parameters
insn:DalvInsn

non-null; a constant-bearing instruction

Returns:String

non-null; comment string representing the constant

cstStringback to summary
protected static String cstString(DalvInsn insn)

Helper method to return the constant string for a CstInsn in human form.

Parameters
insn:DalvInsn

non-null; a constant-bearing instruction

Returns:String

non-null; the human string form of the contained constant

insnArgStringback to summary
public abstract String insnArgString(DalvInsn insn)

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 "", not null.

Subclasses must override this method.

Parameters
insn:DalvInsn

non-null; the instruction

Returns:String

non-null; the string form

insnCommentStringback to summary
public abstract String insnCommentString(DalvInsn insn, boolean noteIndices)

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 "", not null.

Subclasses must override this method.

Parameters
insn:DalvInsn

non-null; the instruction

noteIndices:boolean

whether to include an explicit notation of constant pool indices

Returns:String

non-null; the string form

isCompatibleback to summary
public abstract boolean isCompatible(DalvInsn insn)

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:DalvInsn

non-null; the instruction to check

Returns:boolean

true iff the instruction's arguments are appropriate for this instance, or false if not

isRegListSequentialback to summary
protected static boolean isRegListSequential(RegisterSpecList list)

Helper method to determine if a list of registers are sequential, including degenerate cases for empty or single-element lists.

Parameters
list:RegisterSpecList

non-null; the list of registers

Returns:boolean

true iff the list is sequentially ordered

listingStringback to summary
public final String listingString(DalvInsn insn, boolean noteIndices)

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:DalvInsn

non-null; the instruction

noteIndices:boolean

whether to include an explicit notation of constant pool indices

Returns:String

non-null; the string form

literalBitsCommentback to summary
protected static String literalBitsComment(CstLiteralBits value, int width)

Helper method to return a literal bits comment string.

Parameters
value:CstLiteralBits

the value

width:int

the width of the constant, in bits (used for displaying the uninterpreted bits; one of: 4 8 16 32 64

Returns:String

non-null; the comment

literalBitsStringback to summary
protected static String literalBitsString(CstLiteralBits value)

Helper method to return a literal bits argument string.

Parameters
value:CstLiteralBits

the value

Returns:String

non-null; the string form

makeByteback to summary
protected static int makeByte(int low, int high)

Helper method to combine two nibbles into a byte.

Parameters
low:int

0..15; low nibble

high:int

0..15; high nibble

Returns:int

0..255; combined value

opcodeUnitback to summary
protected static short opcodeUnit(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.

Parameters
insn:DalvInsn

non-null; the instruction containing the opcode

arg:int

0..255; arbitrary other byte value

Returns:short

combined value

opcodeUnitback to summary
protected static short opcodeUnit(DalvInsn insn)

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:DalvInsn

non-null; the instruction containing the extended opcode

Returns:short

the opcode as a code unit

regListStringback to summary
protected static String regListString(RegisterSpecList list)

Helper method to return a register list string.

Parameters
list:RegisterSpecList

non-null; the list of registers

Returns:String

non-null; the string form

regRangeStringback to summary
protected static String regRangeString(RegisterSpecList list)

Helper method to return a register range string.

Parameters
list:RegisterSpecList

non-null; the list of registers (which must be sequential)

Returns:String

non-null; the string form

signedFitsInByteback to summary
protected static boolean signedFitsInByte(int value)

Helper method to determine if a signed int value fits in a byte.

Parameters
value:int

the value in question

Returns:boolean

true iff it's in the range -0x80..+0x7f

signedFitsInNibbleback to summary
protected static boolean signedFitsInNibble(int value)

Helper method to determine if a signed int value fits in a nibble.

Parameters
value:int

the value in question

Returns:boolean

true iff it's in the range -8..+7

signedFitsInShortback to summary
protected static boolean signedFitsInShort(int value)

Helper method to determine if a signed int value fits in a short.

Parameters
value:int

the value in question

Returns:boolean

true iff it's in the range -0x8000..+0x7fff

unsignedFitsInByteback to summary
protected static boolean unsignedFitsInByte(int value)

Helper method to determine if an unsigned int value fits in a byte.

Parameters
value:int

the value in question

Returns:boolean

true iff it's in the range 0..0xff

unsignedFitsInNibbleback to summary
protected static boolean unsignedFitsInNibble(int value)

Helper method to determine if an unsigned int value fits in a nibble.

Parameters
value:int

the value in question

Returns:boolean

true iff it's in the range 0..0xf

unsignedFitsInShortback to summary
protected static boolean unsignedFitsInShort(int value)

Helper method to determine if an unsigned int value fits in a short.

Parameters
value:int

the value in question

Returns:boolean

true iff it's in the range 0..0xffff

writeback to summary
protected static void write(AnnotatedOutput out, short c0)

Writes one code unit to the given output destination.

Parameters
out:AnnotatedOutput

non-null; where to write to

c0:short

code unit to write

writeback to summary
protected static void write(AnnotatedOutput out, short c0, short c1)

Writes two code units to the given output destination.

Parameters
out:AnnotatedOutput

non-null; where to write to

c0:short

code unit to write

c1:short

code unit to write

writeback to summary
protected static void write(AnnotatedOutput out, short c0, short c1, short c2)

Writes three code units to the given output destination.

Parameters
out:AnnotatedOutput

non-null; where to write to

c0:short

code unit to write

c1:short

code unit to write

c2:short

code unit to write

writeback to summary
protected static void write(AnnotatedOutput out, short c0, short c1, short c2, short c3)

Writes four code units to the given output destination.

Parameters
out:AnnotatedOutput

non-null; where to write to

c0:short

code unit to write

c1:short

code unit to write

c2:short

code unit to write

c3:short

code unit to write

writeback to summary
protected static void write(AnnotatedOutput out, short c0, short c1, short c2, short c3, short c4)

Writes five code units to the given output destination.

Parameters
out:AnnotatedOutput

non-null; where to write to

c0:short

code unit to write

c1:short

code unit to write

c2:short

code unit to write

c3:short

code unit to write

c4:short

code unit to write

writeback to summary
protected static void write(AnnotatedOutput out, short c0, int c1c2)

Writes three code units to the given output destination, where the second and third are represented as single int and emitted in little-endian order.

Parameters
out:AnnotatedOutput

non-null; where to write to

c0:short

code unit to write

c1c2:int

code unit pair to write

writeback to summary
protected static void write(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 single int and emitted in little-endian order.

Parameters
out:AnnotatedOutput

non-null; where to write to

c0:short

code unit to write

c1c2:int

code unit pair to write

c3:short

code unit to write

writeback to summary
protected static void write(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 single int and emitted in little-endian order.

Parameters
out:AnnotatedOutput

non-null; where to write to

c0:short

code unit to write

c1c2:int

code unit pair to write

c3:short

code unit to write

c4:short

code unit to write

writeback to summary
protected static void write(AnnotatedOutput out, short c0, long c1c2c3c4)

Writes five code units to the given output destination, where the second through fifth are represented as single long and emitted in little-endian order.

Parameters
out:AnnotatedOutput

non-null; where to write to

c0:short

code unit to write

c1c2c3c4:long

code unit quad to write

writeToback to summary
public abstract void writeTo(AnnotatedOutput out, DalvInsn insn)

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:AnnotatedOutput

non-null; the output destination to write to

insn:DalvInsn

non-null; the instruction to write