3 # Generate the file opcodes.h.
5 # This AWK script scans a concatenation of the parse.h output file from the
6 # parser and the vdbe.c source file in order to generate the opcodes numbers
9 # The lines of the vdbe.c that we are interested in are of the form:
11 # case OP_aaaa: /* same as TK_bbbbb */
13 # The TK_ comment is optional. If it is present, then the value assigned to
14 # the OP_ is the same as the TK_ value. If missing, the OP_ value is assigned
15 # a small integer that is different from every other OP_ value.
17 # We go to the trouble of making some OP_ value the same as TK_ values
18 # as an optimization. During parsing, things like expression operators
19 # are coded with TK_ values such as TK_ADD, TK_DIVIDE, and so forth. Later
20 # during code generation, we need to generate corresponding opcodes like
21 # OP_Add and OP_Divide. By making TK_ADD==OP_Add and TK_DIVIDE==OP_Divide,
22 # code to translation from one to the other is avoided. This makes the
23 # code generator run (infinitesimally) faster and more importantly it makes
24 # the total library smaller.
28 # Remember the TK_ values from the parse.h file
33 # Scan for "case OP_aaaa:" lines in the vdbe.c file
40 if($i==
"same" && $
(i
+1)==
"as"){
45 sameas
[op
[name
]] = sym
53 # Assign numbers to all opcodes and output the result.
57 print "/* Automatically generated. Do not edit */"
58 print "/* See the mkopcodeh.awk script for details */"
62 while( used
[cnt
] ) cnt
++
66 if( op
[name
]>max
) max = op
[name
]
67 printf "#define %-25s %15d", name
, op
[name
]
68 if( sameas
[op
[name
]] ) {
69 printf " /* same as %-12s*/", sameas
[op
[name
]]
78 printf "\n/* The following opcode values are never used */\n"
81 printf "#define %-25s %15d\n", sprintf( "OP_NotUsed_%-3d", i
), i
85 # Generate the 10 16-bit bitmasks used by function opcodeUsesStack()
86 # in vdbeaux.c. See comments in that function for details.
89 nopush
[1] =
0 # 16..31
90 nopush
[2] =
0 # 32..47
91 nopush
[3] =
0 # 48..63
92 nopush
[4] =
0 # 64..79
93 nopush
[5] =
0 # 80..95
94 nopush
[6] =
0 # 96..111
95 nopush
[7] =
0 # 112..127
96 nopush
[8] =
0 # 128..143
97 nopush
[9] =
0 # 144..159
103 nopush
[i
] = nopush
[i
] + (2^j
)
108 printf "#define NOPUSH_MASK_%d %d\n", i
, nopush
[i
]