diff options
author | Dan Bornstein <danfuzz@android.com> | 2010-11-17 12:05:04 -0800 |
---|---|---|
committer | Dan Bornstein <danfuzz@android.com> | 2010-11-17 12:05:04 -0800 |
commit | 8424432a87c784547e4510bca538eaedc312e40d (patch) | |
tree | fd2adcb356418d6dc697ba5a8e1a1bb90eb1fde2 | |
parent | d03baafc41fe04167d0a8ba01d8cbc9bcbed8195 (diff) | |
download | android_dalvik-8424432a87c784547e4510bca538eaedc312e40d.tar.gz android_dalvik-8424432a87c784547e4510bca538eaedc312e40d.tar.bz2 android_dalvik-8424432a87c784547e4510bca538eaedc312e40d.zip |
Generate the tables in InstrUtils.c...almost.
This patch adds code to opcode-gen to generate the opcode info tables
currently built at vm start time, but they are left commented out for
now. I wanted to separate the work of getting these tables generated
from the work of getting those new tables hooked up, and this seemed
like a reasonable way to cut through the larger effort.
To be clear, I've already verified that the data in the new
pregenerated tables matches what's in the status quo.
Change-Id: Ie73dc6c6a5721e8f714f845c97b5338141995770
-rw-r--r-- | dexdump/DexDump.c | 2 | ||||
-rw-r--r-- | libdex/InstrUtils.c | 445 | ||||
-rw-r--r-- | libdex/InstrUtils.h | 2 | ||||
-rw-r--r-- | opcode-gen/bytecode.txt | 5 | ||||
-rwxr-xr-x | opcode-gen/opcode-gen | 108 | ||||
-rwxr-xr-x | opcode-gen/regen-all | 1 |
6 files changed, 537 insertions, 26 deletions
diff --git a/dexdump/DexDump.c b/dexdump/DexDump.c index 071793ea3..594930376 100644 --- a/dexdump/DexDump.c +++ b/dexdump/DexDump.c @@ -1032,7 +1032,7 @@ void dumpInstruction(DexFile* pDexFile, const DexCode* pCode, int insnIdx, pDecInsn->vA, conv.d, pDecInsn->vB_wide); } break; - case kFmtUnknown: + case kFmt00x: // unknown op or breakpoint break; default: printf(" ???"); diff --git a/libdex/InstrUtils.c b/libdex/InstrUtils.c index 01c8311a9..ab15c816e 100644 --- a/libdex/InstrUtils.c +++ b/libdex/InstrUtils.c @@ -16,11 +16,450 @@ /* * Dalvik instruction utility functions. + * + * IMPORTANT NOTE: Much of the contents of this file are generated + * automatically by the opcode-gen tool. Any edits to the generated + * sections will get wiped out the next time the tool is run. */ -#include "InstrUtils.h" +#include "InstrUtils.h" #include <stdlib.h> +#if 0 +/* coming soon! */ + +/* + * Table that maps each opcode to the full width of instructions that + * use that opcode, in (16-bit) code units. Unimplemented opcodes as + * well as the "breakpoint" opcode have a width of zero. + */ +static InstructionWidth gOpcodeWidthTable[kNumDalvikInstructions] = { + // BEGIN(libdex-widths); GENERATED AUTOMATICALLY BY opcode-gen + 1, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 2, 3, 2, 2, 3, 5, 2, 2, 3, 2, 1, 1, 2, + 2, 1, 2, 2, 3, 3, 3, 1, 1, 2, 3, 3, 3, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, + 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, + 3, 3, 3, 0, 3, 3, 3, 3, 3, 0, 0, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 3, 3, + 3, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 2, 2, 2, 0, + // END(libdex-widths) +}; + +/* + * Table that maps each opcode to the flags associated with that + * opcode. + */ +static InstructionFlags gOpcodeFlagsTable[kNumDalvikInstructions] = { + // BEGIN(libdex-flags); GENERATED AUTOMATICALLY BY opcode-gen + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanReturn, + kInstrCanReturn, + kInstrCanReturn, + kInstrCanReturn, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue, + kInstrCanThrow, + kInstrCanBranch, + kInstrCanBranch, + kInstrCanBranch, + kInstrCanContinue|kInstrCanSwitch, + kInstrCanContinue|kInstrCanSwitch, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue|kInstrCanBranch, + kInstrCanContinue|kInstrCanBranch, + kInstrCanContinue|kInstrCanBranch, + kInstrCanContinue|kInstrCanBranch, + kInstrCanContinue|kInstrCanBranch, + kInstrCanContinue|kInstrCanBranch, + kInstrCanContinue|kInstrCanBranch, + kInstrCanContinue|kInstrCanBranch, + kInstrCanContinue|kInstrCanBranch, + kInstrCanContinue|kInstrCanBranch, + kInstrCanContinue|kInstrCanBranch, + kInstrCanContinue|kInstrCanBranch, + 0, + 0, + 0, + 0, + 0, + 0, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow|kInstrInvoke, + kInstrCanContinue|kInstrCanThrow|kInstrInvoke, + kInstrCanContinue|kInstrCanThrow|kInstrInvoke, + kInstrCanContinue|kInstrCanThrow|kInstrInvoke, + kInstrCanContinue|kInstrCanThrow|kInstrInvoke, + 0, + kInstrCanContinue|kInstrCanThrow|kInstrInvoke, + kInstrCanContinue|kInstrCanThrow|kInstrInvoke, + kInstrCanContinue|kInstrCanThrow|kInstrInvoke, + kInstrCanContinue|kInstrCanThrow|kInstrInvoke, + kInstrCanContinue|kInstrCanThrow|kInstrInvoke, + 0, + 0, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + 0, + kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow|kInstrInvoke, + kInstrCanReturn, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow|kInstrInvoke, + kInstrCanContinue|kInstrCanThrow|kInstrInvoke, + kInstrCanContinue|kInstrCanThrow|kInstrInvoke, + kInstrCanContinue|kInstrCanThrow|kInstrInvoke, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + kInstrCanContinue|kInstrCanThrow, + 0, + // END(libdex-flags) +}; + +/* + * Table that maps each opcode to the instruction format associated + * that opcode. + */ +static InstructionFormat gOpcodeFormatTable[kNumDalvikInstructions] = { + // BEGIN(libdex-formats); GENERATED AUTOMATICALLY BY opcode-gen + kFmt10x, kFmt12x, kFmt22x, kFmt32x, kFmt12x, kFmt22x, kFmt32x, + kFmt12x, kFmt22x, kFmt32x, kFmt11x, kFmt11x, kFmt11x, kFmt11x, + kFmt10x, kFmt11x, kFmt11x, kFmt11x, kFmt11n, kFmt21s, kFmt31i, + kFmt21h, kFmt21s, kFmt31i, kFmt51l, kFmt21h, kFmt21c, kFmt31c, + kFmt21c, kFmt11x, kFmt11x, kFmt21c, kFmt22c, kFmt12x, kFmt21c, + kFmt22c, kFmt35c, kFmt3rc, kFmt31t, kFmt11x, kFmt10t, kFmt20t, + kFmt30t, kFmt31t, kFmt31t, kFmt23x, kFmt23x, kFmt23x, kFmt23x, + kFmt23x, kFmt22t, kFmt22t, kFmt22t, kFmt22t, kFmt22t, kFmt22t, + kFmt21t, kFmt21t, kFmt21t, kFmt21t, kFmt21t, kFmt21t, kFmt00x, + kFmt00x, kFmt00x, kFmt00x, kFmt00x, kFmt00x, kFmt23x, kFmt23x, + kFmt23x, kFmt23x, kFmt23x, kFmt23x, kFmt23x, kFmt23x, kFmt23x, + kFmt23x, kFmt23x, kFmt23x, kFmt23x, kFmt23x, kFmt22c, kFmt22c, + kFmt22c, kFmt22c, kFmt22c, kFmt22c, kFmt22c, kFmt22c, kFmt22c, + kFmt22c, kFmt22c, kFmt22c, kFmt22c, kFmt22c, kFmt21c, kFmt21c, + kFmt21c, kFmt21c, kFmt21c, kFmt21c, kFmt21c, kFmt21c, kFmt21c, + kFmt21c, kFmt21c, kFmt21c, kFmt21c, kFmt21c, kFmt35c, kFmt35c, + kFmt35c, kFmt35c, kFmt35c, kFmt00x, kFmt3rc, kFmt3rc, kFmt3rc, + kFmt3rc, kFmt3rc, kFmt00x, kFmt00x, kFmt12x, kFmt12x, kFmt12x, + kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, + kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, + kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt23x, kFmt23x, kFmt23x, + kFmt23x, kFmt23x, kFmt23x, kFmt23x, kFmt23x, kFmt23x, kFmt23x, + kFmt23x, kFmt23x, kFmt23x, kFmt23x, kFmt23x, kFmt23x, kFmt23x, + kFmt23x, kFmt23x, kFmt23x, kFmt23x, kFmt23x, kFmt23x, kFmt23x, + kFmt23x, kFmt23x, kFmt23x, kFmt23x, kFmt23x, kFmt23x, kFmt23x, + kFmt23x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, + kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, + kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, + kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, + kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt12x, kFmt22s, kFmt22s, + kFmt22s, kFmt22s, kFmt22s, kFmt22s, kFmt22s, kFmt22s, kFmt22b, + kFmt22b, kFmt22b, kFmt22b, kFmt22b, kFmt22b, kFmt22b, kFmt22b, + kFmt22b, kFmt22b, kFmt22b, kFmt22c, kFmt22c, kFmt21c, kFmt21c, + kFmt22c, kFmt22c, kFmt22c, kFmt21c, kFmt21c, kFmt00x, kFmt20bc, + kFmt35mi, kFmt3rmi, kFmt35c, kFmt10x, kFmt22cs, kFmt22cs, kFmt22cs, + kFmt22cs, kFmt22cs, kFmt22cs, kFmt35ms, kFmt3rms, kFmt35ms, kFmt3rms, + kFmt22c, kFmt21c, kFmt21c, kFmt00x, + // END(libdex-formats) +}; + +/* + * Table that maps each opcode to the index type implied by that + * opcode. + */ +static InstructionIndexType gOpcodeIndexTypeTable[kNumDalvikInstructions] = { + // BEGIN(libdex-index-types); GENERATED AUTOMATICALLY BY opcode-gen + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexStringRef, + kIndexStringRef, kIndexTypeRef, kIndexNone, + kIndexNone, kIndexTypeRef, kIndexTypeRef, + kIndexNone, kIndexTypeRef, kIndexTypeRef, + kIndexTypeRef, kIndexTypeRef, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexUnknown, + kIndexUnknown, kIndexUnknown, kIndexUnknown, + kIndexUnknown, kIndexUnknown, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexFieldRef, kIndexFieldRef, + kIndexFieldRef, kIndexFieldRef, kIndexFieldRef, + kIndexFieldRef, kIndexFieldRef, kIndexFieldRef, + kIndexFieldRef, kIndexFieldRef, kIndexFieldRef, + kIndexFieldRef, kIndexFieldRef, kIndexFieldRef, + kIndexFieldRef, kIndexFieldRef, kIndexFieldRef, + kIndexFieldRef, kIndexFieldRef, kIndexFieldRef, + kIndexFieldRef, kIndexFieldRef, kIndexFieldRef, + kIndexFieldRef, kIndexFieldRef, kIndexFieldRef, + kIndexFieldRef, kIndexFieldRef, kIndexMethodRef, + kIndexMethodRef, kIndexMethodRef, kIndexMethodRef, + kIndexMethodRef, kIndexUnknown, kIndexMethodRef, + kIndexMethodRef, kIndexMethodRef, kIndexMethodRef, + kIndexMethodRef, kIndexUnknown, kIndexUnknown, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexNone, + kIndexNone, kIndexNone, kIndexFieldRef, + kIndexFieldRef, kIndexFieldRef, kIndexFieldRef, + kIndexFieldRef, kIndexFieldRef, kIndexFieldRef, + kIndexFieldRef, kIndexFieldRef, kIndexUnknown, + kIndexVaries, kIndexInlineMethod, kIndexInlineMethod, + kIndexMethodRef, kIndexNone, kIndexFieldOffset, + kIndexFieldOffset, kIndexFieldOffset, kIndexFieldOffset, + kIndexFieldOffset, kIndexFieldOffset, kIndexVtableOffset, + kIndexVtableOffset, kIndexVtableOffset, kIndexVtableOffset, + kIndexFieldRef, kIndexFieldRef, kIndexFieldRef, + kIndexUnknown, + // END(libdex-index-types) +}; +#endif /* * Generate a table that holds the width of all instructions. @@ -691,7 +1130,7 @@ InstructionFormat* dexCreateInstrFormatTable(void) for (i = 0; i < kNumDalvikInstructions; i++) { OpCode opc = (OpCode) i; - InstructionFormat fmt = kFmtUnknown; + InstructionFormat fmt = kFmt00x; switch (opc) { case OP_GOTO: @@ -1024,7 +1463,7 @@ InstructionFormat* dexCreateInstrFormatTable(void) case OP_UNUSED_7A: case OP_BREAKPOINT: case OP_UNUSED_FF: - fmt = kFmtUnknown; + fmt = kFmt00x; break; /* diff --git a/libdex/InstrUtils.h b/libdex/InstrUtils.h index e65a1bf72..44e5af24d 100644 --- a/libdex/InstrUtils.h +++ b/libdex/InstrUtils.h @@ -38,7 +38,7 @@ */ typedef unsigned char InstructionFormat; enum InstructionFormat { - kFmtUnknown = 0, + kFmt00x = 0, // unknown format (also used for "breakpoint" opcode) kFmt10x, // op kFmt12x, // op vA, vB kFmt11n, // op vA, #+B diff --git a/opcode-gen/bytecode.txt b/opcode-gen/bytecode.txt index 4462dac96..b24e6119a 100644 --- a/opcode-gen/bytecode.txt +++ b/opcode-gen/bytecode.txt @@ -41,7 +41,7 @@ format 22t format 35c 3rc 5rc # Optimized formats -format 00x # not in spec; used for breakpoint +format 00x # not in spec; used for undefined opcodes and breakpoint format 20bc # not in spec; used for throw-verification-error format 22cs format 35mi @@ -57,6 +57,7 @@ format 3rms # y # n # index type; one of: +# unknown -- used for undefined opcodes and breakpoint # none # varies # type-ref @@ -311,7 +312,7 @@ op e8 +iget-wide-volatile 22c y field-ref optimized|continue|thro op e9 +iput-wide-volatile 22c n field-ref optimized|continue|throw op ea +sget-wide-volatile 21c y field-ref optimized|continue|throw op eb +sput-wide-volatile 21c n field-ref optimized|continue|throw -op ec ^breakpoint 00x n none optimized|continue|throw +op ec ^breakpoint 00x n unknown optimized op ed ^throw-verification-error 20bc n varies optimized|throw op ee +execute-inline 35mi n inline-method optimized|continue|throw op ef +execute-inline/range 3rmi n inline-method optimized|continue|throw diff --git a/opcode-gen/opcode-gen b/opcode-gen/opcode-gen index 976a169ad..17560d107 100755 --- a/opcode-gen/opcode-gen +++ b/opcode-gen/opcode-gen @@ -172,8 +172,73 @@ consumeUntil != "" { next; } +/BEGIN\(libdex-widths\)/ { + consumeUntil = "END(libdex-widths)"; + print; + + col = 1; + for (i = 0; i <= MAX_LIBDEX_OPCODE; i++) { + value = sprintf("%d,", isUnusedByte(i) ? 0 : width[i]); + col = colPrint(value, (i == MAX_LIBDEX_OPCODE), col, 16, 2, " "); + } + + next; +} + +/BEGIN\(libdex-flags\)/ { + consumeUntil = "END(libdex-flags)"; + print; + + for (i = 0; i <= MAX_LIBDEX_OPCODE; i++) { + value = flagsToC(isUnusedByte(i) ? 0 : flags[i]); + printf(" %s,\n", value); + } + + next; +} + +/BEGIN\(libdex-formats\)/ { + consumeUntil = "END(libdex-formats)"; + print; + + col = 1; + for (i = 0; i <= MAX_LIBDEX_OPCODE; i++) { + value = sprintf("kFmt%s,", isUnusedByte(i) ? "00x" : format[i]); + col = colPrint(value, (i == MAX_LIBDEX_OPCODE), col, 7, 9, " "); + } + + next; +} + +/BEGIN\(libdex-index-types\)/ { + consumeUntil = "END(libdex-index-types)"; + print; + + col = 1; + for (i = 0; i <= MAX_LIBDEX_OPCODE; i++) { + value = isUnusedByte(i) ? "unknown" : indexType[i]; + value = sprintf("%s,", indexTypeValues[value]); + col = colPrint(value, (i == MAX_LIBDEX_OPCODE), col, 3, 19, " "); + } + + next; +} + { print; } +# Helper to print out an element in a multi-column fashion. It returns +# the (one-based) column number that the next element will be printed +# in. +function colPrint(value, isLast, col, numCols, colWidth, linePrefix) { + isLast = (isLast || (col == numCols)); + printf("%s%-*s%s", + (col == 1) ? linePrefix : " ", + isLast ? 1 : colWidth, value, + isLast ? "\n" : ""); + + return (col % numCols) + 1; +} + # Read the bytecode description file. function readBytecodes(i, parts, line, cmd, status, count) { # locals: parts, line, cmd, status, count @@ -230,14 +295,19 @@ function defineOpcode(line, count, parts, idx) { flags[idx] = parts[6]; # Calculate derived values. + constName[idx] = toupper(name[idx]); gsub("[---/]", "_", constName[idx]); # Dash and slash become underscore. gsub("[+^]", "", constName[idx]); # Plus and caret are removed. split(name[idx], parts, "/"); + family[idx] = toupper(parts[1]); gsub("-", "_", family[idx]); # Dash becomes underscore. gsub("[+^]", "", family[idx]); # Plus and caret are removed. + split(format[idx], parts, ""); # Width is the first format char. + width[idx] = parts[1]; + # This association is used when computing "next" opcodes. familyFormat[family[idx],format[idx]] = idx; @@ -398,39 +468,39 @@ function isOptimized(idx, parts, f) { return 0; } -# Returns true if there is no definition for given opcode (by index). +# Returns true if there is no definition for the given opcode (by index). function isUnused(idx) { return (name[idx] == ""); } +# Returns true if there is no definition for the given opcode (by +# index), taken as a single-byte opcode. The odd case for this +# function is 255, which is the first extended (two-byte) opcode. For +# the purposes of this function, it is considered unused. (This is +# meant as a stop-gap measure for code that is not yet prepared to +# deal with extended opcodes.) +function isUnusedByte(idx) { + return (idx == 255) || (name[idx] == ""); +} + # Returns the constant name of the given single-byte opcode (by index) # or the string "UNUSED_XX" (where XX is the index in hex) if the -# opcode is unused. The odd case for this function is 255, which is -# the first extended (two-byte) opcode. For the purposes of this -# function, it is considered unused. (This is meant as a stop-gap -# measure for code that is not yet prepared to deal with extended -# opcodes.) -function constNameOrUnusedByte(idx, n) { - n = constName[idx]; - if ((n == "") || (i == 255)) { +# opcode is unused. See isUnusedByte(), above, for more info. +function constNameOrUnusedByte(idx) { + if (isUnusedByte(idx)) { return toupper(sprintf("UNUSED_%02x", idx)); } - return n; + return constName[idx]; } # Returns the (human-oriented) name of the given single-byte opcode # (by index) or the string "unused-xx" (where xx is the index in hex) -# if the opcode is unused. The odd case for this function is 255, -# which is the first extended (two-byte) opcode. For the purposes of -# this function, it is considered unused. (This is meant as a stop-gap -# measure for code that is not yet prepared to deal with extended -# opcodes.) -function nameOrUnusedByte(idx, n) { - n = name[idx]; - if ((n == "") || (i == 255)) { +# if the opcode is unused. See isUnusedByte(), above, for more info. +function nameOrUnusedByte(idx) { + if (isUnusedByte(idx)) { return sprintf("unused-%02x", idx); } - return n; + return name[idx]; } ' "$file" > "$tmpfile" diff --git a/opcode-gen/regen-all b/opcode-gen/regen-all index 4e5c38229..276893e7e 100755 --- a/opcode-gen/regen-all +++ b/opcode-gen/regen-all @@ -37,5 +37,6 @@ cd ".." ${progdir}/opcode-gen dx/src/com/android/dx/dex/code/DalvOps.java ${progdir}/opcode-gen dx/src/com/android/dx/dex/code/Dops.java ${progdir}/opcode-gen dx/src/com/android/dx/dex/code/RopToDop.java +${progdir}/opcode-gen libdex/InstrUtils.c ${progdir}/opcode-gen libdex/OpCode.h ${progdir}/opcode-gen libdex/OpCodeNames.c |