drh | f2bc013 | 2004-10-04 13:19:23 +0000 | [diff] [blame^] | 1 | #!/usr/bin/awk -f |
| 2 | # |
| 3 | # This AWK script scans a concatenation of the parse.h output file from the |
| 4 | # parser and the vdbe.c source file in order to generate the opcodes numbers |
| 5 | # for all opcodes. |
| 6 | # |
| 7 | # The lines of the vdbe.c that we are interested in are of the form: |
| 8 | # |
| 9 | # case OP_aaaa: /* same as TK_bbbbb */ |
| 10 | # |
| 11 | # The TK_ comment is optional. If it is present, then the value assigned to |
| 12 | # the OP_ is the same as the TK_ value. If missing, the OP_ value is assigned |
| 13 | # a small integer that is different from every other OP_ value. |
| 14 | # |
| 15 | |
| 16 | # Remember the TK_ values from the parse.h file |
| 17 | /^#define TK_/ { |
| 18 | tk[$2] = $3 |
| 19 | } |
| 20 | |
| 21 | # Scan for "case OP_aaaa:" lines in the vdbe.c file |
| 22 | /^case OP_/ { |
| 23 | name = $2 |
| 24 | gsub(/:/,"",name) |
| 25 | op[name] = -1 |
| 26 | for(i=3; i<NF-2; i++){ |
| 27 | if($i=="same" && $(i+1)=="as"){ |
| 28 | op[name] = tk[$(i+2)] |
| 29 | used[op[name]] = 1 |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | # Assign numbers to all opcodes and output the result. |
| 35 | END { |
| 36 | cnt = 0 |
| 37 | for(name in op){ |
| 38 | if( op[name]<0 ){ |
| 39 | cnt++ |
| 40 | while( used[cnt] ) cnt++ |
| 41 | op[name] = cnt |
| 42 | } |
| 43 | printf "#define %-30s %d\n", name, op[name] |
| 44 | } |
| 45 | } |