diff options
author | drh <drh@noemail.net> | 2004-10-04 13:19:23 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2004-10-04 13:19:23 +0000 |
commit | f2bc013c7011580ae976e5d7a978863b3f84a52d (patch) | |
tree | 8fdf6922f04914830682242910be66e9d5a58b26 /mkopcodeh.awk | |
parent | 9c105bb990007c678ca28e63b764f8d0b557d5f9 (diff) | |
download | sqlite-f2bc013c7011580ae976e5d7a978863b3f84a52d.tar.gz sqlite-f2bc013c7011580ae976e5d7a978863b3f84a52d.zip |
Save about 800 bytes of code space by aligning TK_ and OP_ constants so that
we do not have to translate between them. (CVS 1998)
FossilOrigin-Name: 4c817e3f293a9c1365e632f7dc13ae440263332a
Diffstat (limited to 'mkopcodeh.awk')
-rw-r--r-- | mkopcodeh.awk | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/mkopcodeh.awk b/mkopcodeh.awk new file mode 100644 index 000000000..49e2498b3 --- /dev/null +++ b/mkopcodeh.awk @@ -0,0 +1,45 @@ +#!/usr/bin/awk -f +# +# This AWK script scans a concatenation of the parse.h output file from the +# parser and the vdbe.c source file in order to generate the opcodes numbers +# for all opcodes. +# +# The lines of the vdbe.c that we are interested in are of the form: +# +# case OP_aaaa: /* same as TK_bbbbb */ +# +# The TK_ comment is optional. If it is present, then the value assigned to +# the OP_ is the same as the TK_ value. If missing, the OP_ value is assigned +# a small integer that is different from every other OP_ value. +# + +# Remember the TK_ values from the parse.h file +/^#define TK_/ { + tk[$2] = $3 +} + +# Scan for "case OP_aaaa:" lines in the vdbe.c file +/^case OP_/ { + name = $2 + gsub(/:/,"",name) + op[name] = -1 + for(i=3; i<NF-2; i++){ + if($i=="same" && $(i+1)=="as"){ + op[name] = tk[$(i+2)] + used[op[name]] = 1 + } + } +} + +# Assign numbers to all opcodes and output the result. +END { + cnt = 0 + for(name in op){ + if( op[name]<0 ){ + cnt++ + while( used[cnt] ) cnt++ + op[name] = cnt + } + printf "#define %-30s %d\n", name, op[name] + } +} |