blob: 7f60e1afb1d7db79d45de5beac6b323a372dbb6b [file] [log] [blame]
drhf2bc0132004-10-04 13:19:23 +00001#!/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.
35END {
36 cnt = 0
drhb327f772004-10-06 15:03:57 +000037 print "/* Automatically generated. Do not edit */"
38 print "/* See the mkopcodeh.awk script for details */"
drhf2bc0132004-10-04 13:19:23 +000039 for(name in op){
40 if( op[name]<0 ){
41 cnt++
42 while( used[cnt] ) cnt++
43 op[name] = cnt
44 }
45 printf "#define %-30s %d\n", name, op[name]
46 }
47}