disable the egl demos.
[AROS-Contrib.git] / sqlite3 / mkopcodeh.awk
bloba258194ca831026bbcd02417c1c3dab994c6072a
1 #!/usr/bin/awk -f
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
7 # for all opcodes.
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
29 /^#define TK_/ {
30 tk[$2] = $3
33 # Scan for "case OP_aaaa:" lines in the vdbe.c file
34 /^case OP_/ {
35 name = $2
36 gsub(/:/,"",name)
37 gsub("\r","",name)
38 op[name] = -1
39 for(i=3; i<NF; i++){
40 if($i=="same" && $(i+1)=="as"){
41 sym = $(i+2)
42 sub(/,/,"",sym)
43 op[name] = tk[sym]
44 used[op[name]] = 1
45 sameas[op[name]] = sym
47 if($i=="no-push"){
48 nopush[name] = 1
53 # Assign numbers to all opcodes and output the result.
54 END {
55 cnt = 0
56 max = 0
57 print "/* Automatically generated. Do not edit */"
58 print "/* See the mkopcodeh.awk script for details */"
59 for(name in op){
60 if( op[name]<0 ){
61 cnt++
62 while( used[cnt] ) cnt++
63 op[name] = cnt
65 used[op[name]] = 1;
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]]
71 printf "\n"
74 seenUnused = 0;
75 for(i=1; i<max; i++){
76 if( !used[i] ){
77 if( !seenUnused ){
78 printf "\n/* The following opcode values are never used */\n"
79 seenUnused = 1
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.
88 nopush[0] = 0 # 0..15
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
98 for(name in op){
99 if( nopush[name] ){
100 n = op[name]
101 j = n%16
102 i = ((n - j)/16)
103 nopush[i] = nopush[i] + (2^j)
106 printf "\n"
107 for(i=0; i<10; i++){
108 printf "#define NOPUSH_MASK_%d %d\n", i, nopush[i]