Index: Makefile.in ================================================================== --- Makefile.in +++ Makefile.in @@ -900,12 +900,12 @@ # Rules to build opcodes.c and opcodes.h # opcodes.c: opcodes.h $(TOP)/mkopcodec.awk $(NAWK) -f $(TOP)/mkopcodec.awk opcodes.h >opcodes.c -opcodes.h: parse.h $(TOP)/src/vdbe.c $(TOP)/mkopcodeh.awk - cat parse.h $(TOP)/src/vdbe.c | $(NAWK) -f $(TOP)/mkopcodeh.awk >opcodes.h +opcodes.h: parse.h $(TOP)/src/vdbe.c $(TOP)/tool/mkopcodeh.tcl + cat parse.h $(TOP)/src/vdbe.c | $(TCLSH_CMD) $(TOP)/tool/mkopcodeh.tcl >opcodes.h # Rules to build parse.c and parse.h - the outputs of lemon. # parse.h: parse.c Index: Makefile.msc ================================================================== --- Makefile.msc +++ Makefile.msc @@ -1573,12 +1573,12 @@ # Rules to build opcodes.c and opcodes.h # opcodes.c: opcodes.h $(TOP)\mkopcodec.awk $(NAWK) -f $(TOP)\mkopcodec.awk opcodes.h > opcodes.c -opcodes.h: parse.h $(TOP)\src\vdbe.c $(TOP)\mkopcodeh.awk - type parse.h $(TOP)\src\vdbe.c | $(NAWK) -f $(TOP)\mkopcodeh.awk > opcodes.h +opcodes.h: parse.h $(TOP)\src\vdbe.c $(TOP)\tool\mkopcodeh.tcl + type parse.h $(TOP)\src\vdbe.c | $(TCLSH_CMD) $(TOP)\tool\mkopcodeh.awk > opcodes.h # Rules to build parse.c and parse.h - the outputs of lemon. # parse.h: parse.c Index: main.mk ================================================================== --- main.mk +++ main.mk @@ -580,13 +580,13 @@ # Rules to build opcodes.c and opcodes.h # opcodes.c: opcodes.h $(TOP)/mkopcodec.awk $(NAWK) -f $(TOP)/mkopcodec.awk opcodes.h >opcodes.c -opcodes.h: parse.h $(TOP)/src/vdbe.c $(TOP)/mkopcodeh.awk +opcodes.h: parse.h $(TOP)/src/vdbe.c $(TOP)/tool/mkopcodeh.tcl cat parse.h $(TOP)/src/vdbe.c | \ - $(NAWK) -f $(TOP)/mkopcodeh.awk >opcodes.h + tclsh $(TOP)/tool/mkopcodeh.tcl >opcodes.h # Rules to build parse.c and parse.h - the outputs of lemon. # parse.h: parse.c DELETED mkopcodeh.awk Index: mkopcodeh.awk ================================================================== --- mkopcodeh.awk +++ /dev/null @@ -1,228 +0,0 @@ -#!/usr/bin/awk -f -# -# Generate the file opcodes.h. -# -# 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. -# -# We go to the trouble of making some OP_ values the same as TK_ values -# as an optimization. During parsing, things like expression operators -# are coded with TK_ values such as TK_ADD, TK_DIVIDE, and so forth. Later -# during code generation, we need to generate corresponding opcodes like -# OP_Add and OP_Divide. By making TK_ADD==OP_Add and TK_DIVIDE==OP_Divide, -# code to translate from one to the other is avoided. This makes the -# code generator run (infinitesimally) faster and more importantly it makes -# the library footprint smaller. -# -# This script also scans for lines of the form: -# -# case OP_aaaa: /* jump, in1, in2, in3, out2-prerelease, out3 */ -# -# When such comments are found on an opcode, it means that certain -# properties apply to that opcode. Set corresponding flags using the -# OPFLG_INITIALIZER macro. -# - - -# Remember the TK_ values from the parse.h file -/^#define TK_/ { - tk[$2] = 0+$3 # tk[x] holds the numeric value for TK symbol X -} - -# Find "/* Opcode: " lines in the vdbe.c file. Each one introduces -# a new opcode. Remember which parameters are used. -/^.. Opcode: / { - currentOp = "OP_" $3 - m = 0 - for(i=4; i<=NF; i++){ - x = $i - if( x=="P1" ) m += 1 - if( x=="P2" ) m += 2 - if( x=="P3" ) m += 4 - if( x=="P4" ) m += 8 - if( x=="P5" ) m += 16 - } - paramused[currentOp] = m -} - -# Find "** Synopsis: " lines that follow Opcode: -/^.. Synopsis: / { - if( currentOp ){ - x = $3 - for(i=4; i<=NF; i++){ - x = x " " $i - } - synopsis[currentOp] = x - } -} - -# Scan for "case OP_aaaa:" lines in the vdbe.c file -/^case OP_/ { - name = $2 - sub(/:/,"",name) - sub("\r","",name) - op[name] = -1 # op[x] holds the numeric value for OP symbol x - jump[name] = 0 - in1[name] = 0 - in2[name] = 0 - in3[name] = 0 - out2[name] = 0 - out3[name] = 0 - for(i=3; i=0 ) continue; - if( name=="OP_Transaction" \ - || name=="OP_AutoCommit" \ - || name=="OP_Savepoint" \ - || name=="OP_Checkpoint" \ - || name=="OP_Vacuum" \ - || name=="OP_JournalMode" \ - || name=="OP_VUpdate" \ - || name=="OP_VFilter" \ - || name=="OP_Next" \ - || name=="OP_NextIfOpen" \ - || name=="OP_SorterNext" \ - || name=="OP_Prev" \ - || name=="OP_PrevIfOpen" \ - ){ - cnt++ - while( used[cnt] ) cnt++ - op[name] = cnt - used[cnt] = 1 - def[cnt] = name - } - } - - # Generate the numeric values for opcodes - for(i=0; i=0} { + incr cnt + while {[info exists used($cnt)]} {incr cnt} + set op($name) $cnt + set used($cnt) 1 + set def($cnt) $name + } +} + +# Generate the numeric values for remaining opcodes +# +for {set i 0} {$i<$nOp} {incr i} { + set name $order($i) + if {$op($name)<0} { + incr cnt + while {[info exists used($cnt)]} {incr cnt} + set op($name) $cnt + set used($cnt) 1 + set def($cnt) $name + } +} +set max $cnt +for {set i 1} {$i<=$nOp} {incr i} { + if {![info exists used($i)]} { + set def($i) "OP_NotUsed_$i" + } + set name $def($i) + puts -nonewline [format {#define %-16s %3d} $name $i] + set com {} + if {[info exists sameas($i)]} { + set com "same as $sameas($i)" + } + if {[info exists synopsis($name)]} { + set x $synopsis($name) + if {$com==""} { + set com "synopsis: $x" + } else { + append com ", synopsis: $x" + } + } + if {$com!=""} { + puts -nonewline [format " /* %-42s */" $com] + } + puts "" +} + +# Generate the bitvectors: +# +set bv(0) 0 +for {set i 1} {$i<=$max} {incr i} { + set name $def($i) + if {[info exists jump($name)] && $jump($name)} {set a0 1} {set a0 0} + if {[info exists in1($name)] && $in1($name)} {set a1 2} {set a1 0} + if {[info exists in2($name)] && $in2($name)} {set a2 4} {set a2 0} + if {[info exists in3($name)] && $in3($name)} {set a3 8} {set a3 0} + if {[info exists out2($name)] && $out2($name)} {set a4 16} {set a4 0} + if {[info exists out3($name)] && $out3($name)} {set a5 32} {set a5 0} + set bv($i) [expr {$a0+$a1+$a2+$a3+$a4+$a5}] +} +puts "" +puts "/* Properties such as \"out2\" or \"jump\" that are specified in" +puts "** comments following the \"case\" for each opcode in the vdbe.c" +puts "** are encoded into bitvectors as follows:" +puts "*/" +puts "#define OPFLG_JUMP 0x0001 /* jump: P2 holds jmp target */" +puts "#define OPFLG_IN1 0x0002 /* in1: P1 is an input */" +puts "#define OPFLG_IN2 0x0004 /* in2: P2 is an input */" +puts "#define OPFLG_IN3 0x0008 /* in3: P3 is an input */" +puts "#define OPFLG_OUT2 0x0010 /* out2: P2 is an output */" +puts "#define OPFLG_OUT3 0x0020 /* out3: P3 is an output */" +puts "#define OPFLG_INITIALIZER \173\\" +for {set i 0} {$i<=$max} {incr i} { + if {$i%8==0} { + puts -nonewline [format "/* %3d */" $i] + } + puts -nonewline [format " 0x%02x," $bv($i)] + if {$i%8==7} { + puts "\\" + } +} +puts "\175"