summaryrefslogtreecommitdiffstats
path: root/opcode-gen/opcode-gen
diff options
context:
space:
mode:
Diffstat (limited to 'opcode-gen/opcode-gen')
-rwxr-xr-xopcode-gen/opcode-gen39
1 files changed, 39 insertions, 0 deletions
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"