|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.android.dx.dex.code.InsnFormat
public abstract class InsnFormat
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 | |
---|---|
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 | |
---|---|
InsnFormat()
|
Method Summary | |
---|---|
protected static int |
argIndex(DalvInsn insn)
Helper method to extract the callout-argument index from an appropriate instruction. |
protected static String |
branchComment(DalvInsn insn)
Helper method to return the comment for a branch. |
boolean |
branchFits(TargetInsn insn)
Returns whether or not the given instruction's branch offset will fit in this instance's format. |
protected static String |
branchString(DalvInsn insn)
Helper method to return a branch address string. |
abstract int |
codeSize()
Gets the code size of instructions that use this format. |
protected static short |
codeUnit(int low,
int high)
Helper method to combine two bytes into a code unit. |
protected static short |
codeUnit(int n0,
int n1,
int n2,
int n3)
Helper method to combine four nibbles into a code unit. |
BitSet |
compatibleRegs(DalvInsn insn)
Returns which of a given instruction's registers will fit in this instance's format. |
protected static String |
cstComment(DalvInsn insn)
Helper method to return an instruction comment for a constant. |
protected static String |
cstString(DalvInsn insn)
Helper method to return the constant string for a CstInsn
in human form. |
abstract String |
insnArgString(DalvInsn insn)
Returns the string form of the arguments to the given instruction. |
abstract String |
insnCommentString(DalvInsn insn,
boolean noteIndices)
Returns the associated comment for the given instruction, if any. |
abstract boolean |
isCompatible(DalvInsn insn)
Returns whether or not the given instruction's arguments will fit in this instance's format. |
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. |
String |
listingString(DalvInsn insn,
boolean noteIndices)
Returns the string form, suitable for inclusion in a listing dump, of the given instruction. |
protected static String |
literalBitsComment(CstLiteralBits value,
int width)
Helper method to return a literal bits comment string. |
protected static String |
literalBitsString(CstLiteralBits value)
Helper method to return a literal bits argument string. |
protected static int |
makeByte(int low,
int high)
Helper method to combine two nibbles into a byte. |
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. |
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. |
protected static String |
regListString(RegisterSpecList list)
Helper method to return a register list string. |
protected static String |
regRangeString(RegisterSpecList list)
Helper method to return a register range string. |
protected static boolean |
signedFitsInByte(int value)
Helper method to determine if a signed int value fits in a byte. |
protected static boolean |
signedFitsInNibble(int value)
Helper method to determine if a signed int value fits in a nibble. |
protected static boolean |
signedFitsInShort(int value)
Helper method to determine if a signed int value fits in a short. |
protected static boolean |
unsignedFitsInByte(int value)
Helper method to determine if an unsigned int value fits in a byte. |
protected static boolean |
unsignedFitsInNibble(int value)
Helper method to determine if an unsigned int value fits in a nibble. |
protected static boolean |
unsignedFitsInShort(int value)
Helper method to determine if an unsigned int value fits in a short. |
protected static void |
write(AnnotatedOutput out,
short c0)
Writes one code unit to the given output destination. |
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. |
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. |
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. |
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. |
protected static void |
write(AnnotatedOutput out,
short c0,
short c1)
Writes two code units to the given output destination. |
protected static void |
write(AnnotatedOutput out,
short c0,
short c1,
short c2)
Writes three code units to the given output destination. |
protected static void |
write(AnnotatedOutput out,
short c0,
short c1,
short c2,
short c3)
Writes four code units to the given output destination. |
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. |
abstract void |
writeTo(AnnotatedOutput out,
DalvInsn insn)
Writes the code units for the given instruction to the given output destination. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static boolean ALLOW_EXTENDED_OPCODES
Constructor Detail |
---|
public InsnFormat()
Method Detail |
---|
public final String listingString(DalvInsn insn, boolean noteIndices)
insn
- non-null;
the instructionnoteIndices
- whether to include an explicit notation of
constant pool indices
non-null;
the string formpublic abstract String insnArgString(DalvInsn insn)
""
, not
null
.
Subclasses must override this method.
insn
- non-null;
the instruction
non-null;
the string formpublic abstract String insnCommentString(DalvInsn insn, boolean noteIndices)
""
, not
null
.
Subclasses must override this method.
insn
- non-null;
the instructionnoteIndices
- whether to include an explicit notation of
constant pool indices
non-null;
the string formpublic abstract int codeSize()
>= 0;
the instruction length in 16-bit code unitspublic abstract boolean isCompatible(DalvInsn insn)
Subclasses must override this method.
insn
- non-null;
the instruction to check
true
iff the instruction's arguments are
appropriate for this instance, or false
if notpublic BitSet compatibleRegs(DalvInsn insn)
The default implementation of this method always returns an empty BitSet. Subclasses must override this method if they have registers.
insn
- non-null;
the instruction to check
non-null;
a BitSet flagging registers in the
register list that are compatible to this formatpublic boolean branchFits(TargetInsn insn)
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.
insn
- non-null;
the instruction to check
true
iff the instruction's branch offset is
appropriate for this instance, or false
if notpublic abstract void writeTo(AnnotatedOutput out, DalvInsn insn)
Subclasses must override this method.
out
- non-null;
the output destination to write toinsn
- non-null;
the instruction to writeprotected static String regListString(RegisterSpecList list)
list
- non-null;
the list of registers
non-null;
the string formprotected static String regRangeString(RegisterSpecList list)
list
- non-null;
the list of registers (which must be
sequential)
non-null;
the string formprotected static String literalBitsString(CstLiteralBits value)
value
- the value
non-null;
the string formprotected static String literalBitsComment(CstLiteralBits value, int width)
value
- the valuewidth
- the width of the constant, in bits (used for displaying
the uninterpreted bits; one of: 4 8 16 32 64
non-null;
the commentprotected static String branchString(DalvInsn insn)
insn
- non-null;
the instruction in question
non-null;
the string form of the instruction's
branch targetprotected static String branchComment(DalvInsn insn)
insn
- non-null;
the instruction in question
non-null;
the commentprotected static String cstString(DalvInsn insn)
CstInsn
in human form.
insn
- non-null;
a constant-bearing instruction
non-null;
the human string form of the contained
constantprotected static String cstComment(DalvInsn insn)
insn
- non-null;
a constant-bearing instruction
non-null;
comment string representing the constantprotected static boolean signedFitsInNibble(int value)
value
- the value in question
true
iff it's in the range -8..+7protected static boolean unsignedFitsInNibble(int value)
value
- the value in question
true
iff it's in the range 0..0xfprotected static boolean signedFitsInByte(int value)
value
- the value in question
true
iff it's in the range -0x80..+0x7fprotected static boolean unsignedFitsInByte(int value)
value
- the value in question
true
iff it's in the range 0..0xffprotected static boolean signedFitsInShort(int value)
value
- the value in question
true
iff it's in the range -0x8000..+0x7fffprotected static boolean unsignedFitsInShort(int value)
value
- the value in question
true
iff it's in the range 0..0xffffprotected static boolean isRegListSequential(RegisterSpecList list)
list
- non-null;
the list of registers
true
iff the list is sequentially orderedprotected static int argIndex(DalvInsn insn)
insn
- non-null;
the instruction
>= 0;
the callout argument indexprotected static short opcodeUnit(DalvInsn insn, int arg)
insn
- non-null;
the instruction containing the opcodearg
- 0..255;
arbitrary other byte value
protected static short opcodeUnit(DalvInsn insn)
insn
- non-null;
the instruction containing the
extended opcode
protected static short codeUnit(int low, int high)
low
- 0..255;
low bytehigh
- 0..255;
high byte
protected static short codeUnit(int n0, int n1, int n2, int n3)
n0
- 0..15;
low nibblen1
- 0..15;
medium-low nibblen2
- 0..15;
medium-high nibblen3
- 0..15;
high nibble
protected static int makeByte(int low, int high)
low
- 0..15;
low nibblehigh
- 0..15;
high nibble
0..255;
combined valueprotected static void write(AnnotatedOutput out, short c0)
out
- non-null;
where to write toc0
- code unit to writeprotected static void write(AnnotatedOutput out, short c0, short c1)
out
- non-null;
where to write toc0
- code unit to writec1
- code unit to writeprotected static void write(AnnotatedOutput out, short c0, short c1, short c2)
out
- non-null;
where to write toc0
- code unit to writec1
- code unit to writec2
- code unit to writeprotected static void write(AnnotatedOutput out, short c0, short c1, short c2, short c3)
out
- non-null;
where to write toc0
- code unit to writec1
- code unit to writec2
- code unit to writec3
- code unit to writeprotected static void write(AnnotatedOutput out, short c0, short c1, short c2, short c3, short c4)
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 writeprotected static void write(AnnotatedOutput out, short c0, int c1c2)
int
and emitted
in little-endian order.
out
- non-null;
where to write toc0
- code unit to writec1c2
- code unit pair to writeprotected static void write(AnnotatedOutput out, short c0, int c1c2, short c3)
int
and emitted
in little-endian order.
out
- non-null;
where to write toc0
- code unit to writec1c2
- code unit pair to writec3
- code unit to writeprotected static void write(AnnotatedOutput out, short c0, int c1c2, short c3, short c4)
int
and emitted
in little-endian order.
out
- non-null;
where to write toc0
- code unit to writec1c2
- code unit pair to writec3
- code unit to writec4
- code unit to writeprotected static void write(AnnotatedOutput out, short c0, long c1c2c3c4)
long
and emitted in little-endian order.
out
- non-null;
where to write toc0
- code unit to writec1c2c3c4
- code unit quad to write
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |