From 11a4a79b09a2be2bd7a7141ce112de3ad0432e53 Mon Sep 17 00:00:00 2001 From: Dan Bornstein Date: Tue, 16 Nov 2010 13:09:45 -0800 Subject: Generate most of OpCode.h using opcode-gen. This was the easiest bit to tackle in libdex. More to come! Change-Id: I3f79039ce98951d694d2c896ee1c7a60b417bc49 --- opcode-gen/opcode-gen | 39 +++++++++++++++++++++++++++++++++++++++ opcode-gen/regen-all | 4 +--- 2 files changed, 40 insertions(+), 3 deletions(-) (limited to 'opcode-gen') diff --git a/opcode-gen/opcode-gen b/opcode-gen/opcode-gen index f57026815..7b2c36307 100755 --- a/opcode-gen/opcode-gen +++ b/opcode-gen/opcode-gen @@ -62,6 +62,7 @@ awk -v "bytecodeFile=$bytecodeFile" ' BEGIN { MAX_OPCODE = 65535; + MAX_LIBDEX_OPCODE = 255; # TODO: Will not be true for long! initIndexTypes(); initFlags(); if (readBytecodes()) exit 1; @@ -137,6 +138,29 @@ consumeUntil != "" { next; } +/BEGIN\(libdex-opcode-enum\)/ { + consumeUntil = "END(libdex-opcode-enum)"; + print; + + for (i = 0; i <= MAX_LIBDEX_OPCODE; i++) { + printf(" OP_%-28s = 0x%02x,\n", uppernameOrUnusedByte(i), i); + } + + next; +} + +/BEGIN\(libdex-goto-table\)/ { + consumeUntil = "END(libdex-goto-table)"; + print; + + for (i = 0; i <= MAX_LIBDEX_OPCODE; i++) { + content = sprintf(" H(OP_%s),", uppernameOrUnusedByte(i)); + printf("%-78s\\\n", content); + } + + next; +} + { print; } # Read the bytecode description file. @@ -369,6 +393,21 @@ function isUnused(idx, n) { n = name[idx]; return (n == "") || (index(n, "unused") != 0); } + +# Returns the uppercase 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 uppernameOrUnusedByte(idx, n) { + n = uppername[idx]; + if ((n == "") || (i == 255)) { + return toupper(sprintf("UNUSED_%02x", idx)); + } + return n; +} ' "$file" > "$tmpfile" cp "$tmpfile" "$file" diff --git a/opcode-gen/regen-all b/opcode-gen/regen-all index 790bf84e8..32330e86d 100755 --- a/opcode-gen/regen-all +++ b/opcode-gen/regen-all @@ -37,6 +37,4 @@ 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 - -# Coming soon! -# ${progdir}/opcode-gen libdex/OpCode.h +${progdir}/opcode-gen libdex/OpCode.h -- cgit v1.2.3