diff options
author | Dan Bornstein <danfuzz@android.com> | 2010-12-02 10:35:48 -0800 |
---|---|---|
committer | Dan Bornstein <danfuzz@android.com> | 2010-12-02 11:33:29 -0800 |
commit | 4b6e9baa06c39376496a1860972a68924c8d4440 (patch) | |
tree | d1defd0fb6117b5a4ecc5fc06083a2d21c4aa2a8 /libdex | |
parent | 9a1f81699cc05b58378ffb9aadb4e97677943791 (diff) | |
download | android_dalvik-4b6e9baa06c39376496a1860972a68924c8d4440.tar.gz android_dalvik-4b6e9baa06c39376496a1860972a68924c8d4440.tar.bz2 android_dalvik-4b6e9baa06c39376496a1860972a68924c8d4440.zip |
Make the enums typedeffed as such.
This makes these definitions C++-friendly. I also tried to clean up
and generally improve the documentation in this area. (Maybe you can
guess what's coming next.)
Change-Id: I76ab3087dcde5cc255288a993ec7b2963f2b733b
Diffstat (limited to 'libdex')
-rw-r--r-- | libdex/InstrUtils.c | 7 | ||||
-rw-r--r-- | libdex/InstrUtils.h | 84 |
2 files changed, 47 insertions, 44 deletions
diff --git a/libdex/InstrUtils.c b/libdex/InstrUtils.c index e1353f2f7..434c15123 100644 --- a/libdex/InstrUtils.c +++ b/libdex/InstrUtils.c @@ -55,7 +55,7 @@ static InstructionWidth gOpcodeWidthTable[kNumDalvikInstructions] = { * Table that maps each opcode to the flags associated with that * opcode. */ -static InstructionFlags gOpcodeFlagsTable[kNumDalvikInstructions] = { +static u1 gOpcodeFlagsTable[kNumDalvikInstructions] = { // BEGIN(libdex-flags); GENERATED AUTOMATICALLY BY opcode-gen kInstrCanContinue, kInstrCanContinue, @@ -320,7 +320,7 @@ static InstructionFlags gOpcodeFlagsTable[kNumDalvikInstructions] = { * Table that maps each opcode to the instruction format associated * that opcode. */ -static InstructionFormat gOpcodeFormatTable[kNumDalvikInstructions] = { +static u1 gOpcodeFormatTable[kNumDalvikInstructions] = { // BEGIN(libdex-formats); GENERATED AUTOMATICALLY BY opcode-gen kFmt10x, kFmt12x, kFmt22x, kFmt32x, kFmt12x, kFmt22x, kFmt32x, kFmt12x, kFmt22x, kFmt32x, kFmt11x, kFmt11x, kFmt11x, kFmt11x, @@ -366,7 +366,7 @@ static InstructionFormat gOpcodeFormatTable[kNumDalvikInstructions] = { * Table that maps each opcode to the index type implied by that * opcode. */ -static InstructionIndexType gOpcodeIndexTypeTable[kNumDalvikInstructions] = { +static u1 gOpcodeIndexTypeTable[kNumDalvikInstructions] = { // BEGIN(libdex-index-types); GENERATED AUTOMATICALLY BY opcode-gen kIndexNone, kIndexNone, kIndexNone, kIndexNone, kIndexNone, kIndexNone, @@ -709,5 +709,6 @@ size_t dexGetInstrOrTableWidth(const u2* insns) } else { width = dexGetInstrWidth(dexOpcodeFromCodeUnit(insns[0])); } + return width; } diff --git a/libdex/InstrUtils.h b/libdex/InstrUtils.h index d0decfd34..c6d81abf0 100644 --- a/libdex/InstrUtils.h +++ b/libdex/InstrUtils.h @@ -24,17 +24,12 @@ #include "DexOpcodes.h" /* - * Dalvik-defined instruction formats. - * - * (This defines InstructionFormat as an unsigned char to reduce the size - * of the table. This isn't necessary with some compilers, which use an - * integer width appropriate for the number of enum values.) + * Possible instruction formats associated with Dalvik opcodes. * * See the file opcode-gen/README.txt for information about updating * opcodes and instruction formats. */ -typedef unsigned char InstructionFormat; -enum InstructionFormat { +typedef enum { kFmt00x = 0, // unknown format (also used for "breakpoint" opcode) kFmt10x, // op kFmt12x, // op vA, vB @@ -71,14 +66,13 @@ enum InstructionFormat { kFmt41c, // exop vAAAA, thing@BBBBBBBB kFmt52c, // exop vAAAA, vBBBB, thing@CCCCCCCC kFmt5rc, // exop {vCCCC .. v(CCCC+AAAA-1)}, thing@BBBBBBBB -}; +} InstructionFormat; /* - * Different kinds of indexed reference, for formats that include such an - * indexed reference (e.g., 21c and 35c) + * Types of indexed reference that are associated with opcodes whose + * formats include such an indexed reference (e.g., 21c and 35c). */ -typedef unsigned char InstructionIndexType; -enum InstructionIndexType { +typedef enum InstructionIndexType { kIndexUnknown = 0, kIndexNone, // has no index kIndexVaries, // "It depends." Used for throw-verification-error @@ -89,32 +83,21 @@ enum InstructionIndexType { kIndexInlineMethod, // inline method index (for inline linked methods) kIndexVtableOffset, // vtable offset (for static linked methods) kIndexFieldOffset // field offset (for static linked fields) -}; - -/* - * Holds the contents of a decoded instruction. - */ -typedef struct DecodedInstruction { - u4 vA; - u4 vB; - u8 vB_wide; /* for kFmt51l */ - u4 vC; - u4 arg[5]; /* vC/D/E/F/G in invoke or filled-new-array */ - Opcode opcode; - InstructionIndexType indexType; -} DecodedInstruction; +} InstructionIndexType; /* - * Instruction width, a value in the range 0 to 5. + * Instruction width implied by an opcode; a value in the range 0 to + * 5. Note that there are special "pseudo-instructions" which are used + * to encode switch and data tables, and these don't have a fixed width. + * See dexGetInstrOrTableWidth(), below. */ -typedef unsigned char InstructionWidth; +typedef u1 InstructionWidth; /* - * Instruction flags, used by the verifier and JIT to determine where - * control can flow to next. Expected to fit in 8 bits. + * Opcode control flow flags, used by the verifier and JIT. */ -typedef unsigned char InstructionFlags; -enum InstructionFlags { +typedef u1 InstructionFlags; +enum InstructionFlagsBits { kInstrCanBranch = 1, // conditional or unconditional branch kInstrCanContinue = 1 << 1, // flow can continue to next statement kInstrCanSwitch = 1 << 2, // switch statement @@ -124,14 +107,20 @@ enum InstructionFlags { }; /* - * Struct that includes a pointer to each of the instruction information + * Struct that includes a pointer to each of the opcode information * tables. + * + * Note: We use "u1*" here instead of the names of the enumerated + * types to guarantee that elements don't use much space. We hold out + * hope for a standard way to indicate the size of an enumerated type + * that works for both C and C++, but in the mean time, this will + * suffice. */ typedef struct InstructionInfoTables { - InstructionFormat* formats; - InstructionIndexType* indexTypes; - InstructionFlags* flags; - InstructionWidth* widths; + u1* formats; /* InstructionFormat elements */ + u1* indexTypes; /* InstructionIndexType elements */ + InstructionFlags* flags; + InstructionWidth* widths; } InstructionInfoTables; /* @@ -140,6 +129,19 @@ typedef struct InstructionInfoTables { extern InstructionInfoTables gDexOpcodeInfo; /* + * Holds the contents of a decoded instruction. + */ +typedef struct DecodedInstruction { + u4 vA; + u4 vB; + u8 vB_wide; /* for kFmt51l */ + u4 vC; + u4 arg[5]; /* vC/D/E/F/G in invoke or filled-new-array */ + Opcode opcode; + InstructionIndexType indexType; +} DecodedInstruction; + +/* * Return the width of the specified instruction, or 0 if not defined. */ DEX_INLINE size_t dexGetInstrWidth(Opcode opcode) @@ -158,7 +160,7 @@ size_t dexGetInstrOrTableWidth(const u2* insns); /* * Returns the flags for the specified opcode. */ -DEX_INLINE int dexGetInstrFlags(Opcode opcode) +DEX_INLINE InstructionFlags dexGetInstrFlags(Opcode opcode) { //assert(/*opcode >= 0 &&*/ opcode < kNumDalvikInstructions); return gDexOpcodeInfo.flags[opcode]; @@ -167,7 +169,7 @@ DEX_INLINE int dexGetInstrFlags(Opcode opcode) /* * Returns true if the given flags represent a goto (unconditional branch). */ -DEX_INLINE bool dexIsGoto(int flags) +DEX_INLINE bool dexIsGoto(InstructionFlags flags) { return (flags & (kInstrCanBranch | kInstrCanContinue)) == kInstrCanBranch; } @@ -178,7 +180,7 @@ DEX_INLINE bool dexIsGoto(int flags) DEX_INLINE InstructionFormat dexGetInstrFormat(Opcode opcode) { //assert(/*opcode >= 0 &&*/ opcode < kNumDalvikInstructions); - return gDexOpcodeInfo.formats[opcode]; + return (InstructionFormat) gDexOpcodeInfo.formats[opcode]; } /* @@ -187,7 +189,7 @@ DEX_INLINE InstructionFormat dexGetInstrFormat(Opcode opcode) DEX_INLINE InstructionIndexType dexGetInstrIndexType(Opcode opcode) { //assert(/*opcode >= 0 &&*/ opcode < kNumDalvikInstructions); - return gDexOpcodeInfo.indexTypes[opcode]; + return (InstructionIndexType) gDexOpcodeInfo.indexTypes[opcode]; } /* |