/ Check-in [eb54d455]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Modify the build process so that the VDBE opcode numbers and the table that contains the opcode names are both automatically generated. This makes it much easier to create new VDBE opcodes. (CVS 746)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: eb54d455b0325d3be96daf6c220c4ee3e0da1a85
User & Date: drh 2002-09-08 00:04:51
Context
2002-09-08
00:04
Modify the build process so that the VDBE opcode numbers and the table that contains the opcode names are both automatically generated. This makes it much easier to create new VDBE opcodes. (CVS 1727) check-in: c4f0bb02 user: drh tags: trunk
00:04
Modify the build process so that the VDBE opcode numbers and the table that contains the opcode names are both automatically generated. This makes it much easier to create new VDBE opcodes. (CVS 746) check-in: eb54d455 user: drh tags: trunk
2002-09-05
23:21
Fix a memory leak that occurred when sqlite_open() failed. (CVS 745) check-in: a8760213 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

    59     59   
    60     60   # You should not have to change anything below this line
    61     61   ###############################################################################
    62     62   
    63     63   # Object files for the SQLite library.
    64     64   #
    65     65   LIBOBJ = btree.lo build.lo delete.lo expr.lo func.lo hash.lo insert.lo \
    66         -         main.lo os.lo pager.lo parse.lo printf.lo random.lo select.lo \
    67         -         table.lo tokenize.lo update.lo util.lo vdbe.lo where.lo trigger.lo
           66  +         main.lo opcodes.lo os.lo pager.lo parse.lo printf.lo random.lo \
           67  +         select.lo table.lo tokenize.lo update.lo util.lo vdbe.lo \
           68  +         where.lo trigger.lo
    68     69   
    69     70   # All of the source code files.
    70     71   #
    71     72   SRC = \
    72     73     $(TOP)/src/btree.c \
    73     74     $(TOP)/src/btree.h \
    74     75     $(TOP)/src/build.c \
    75     76     $(TOP)/src/delete.c \
    76     77     $(TOP)/src/expr.c \
    77     78     $(TOP)/src/func.c \
    78     79     $(TOP)/src/hash.c \
           80  +  $(TOP)/src/hash.h \
    79     81     $(TOP)/src/insert.c \
    80     82     $(TOP)/src/main.c \
    81     83     $(TOP)/src/os.c \
    82     84     $(TOP)/src/pager.c \
    83     85     $(TOP)/src/pager.h \
    84     86     $(TOP)/src/parse.y \
    85     87     $(TOP)/src/printf.c \
................................................................................
    87     89     $(TOP)/src/select.c \
    88     90     $(TOP)/src/shell.c \
    89     91     $(TOP)/src/sqlite.h.in \
    90     92     $(TOP)/src/sqliteInt.h \
    91     93     $(TOP)/src/table.c \
    92     94     $(TOP)/src/tclsqlite.c \
    93     95     $(TOP)/src/tokenize.c \
           96  +  $(TOP)/src/trigger.c \
    94     97     $(TOP)/src/update.c \
    95     98     $(TOP)/src/util.c \
    96     99     $(TOP)/src/vdbe.c \
    97    100     $(TOP)/src/vdbe.h \
    98         -  $(TOP)/src/where.c \
    99         -  $(TOP)/src/trigger.c
          101  +  $(TOP)/src/where.c
   100    102   
   101    103   # Source code to the test files.
   102    104   #
   103    105   TESTSRC = \
   104    106     $(TOP)/src/btree.c \
   105    107     $(TOP)/src/func.c \
   106    108     $(TOP)/src/os.c \
   107    109     $(TOP)/src/pager.c \
   108    110     $(TOP)/src/test1.c \
   109    111     $(TOP)/src/test2.c \
   110    112     $(TOP)/src/test3.c \
   111    113     $(TOP)/src/md5.c
          114  +
          115  +# Header files used by all library source files.
          116  +#
          117  +HDR = \
          118  +   sqlite.h  \
          119  +   $(TOP)/src/btree.h \
          120  +   $(TOP)/src/hash.h \
          121  +   opcodes.h \
          122  +   $(TOP)/src/os.h \
          123  +   $(TOP)/src/sqliteInt.h  \
          124  +   $(TOP)/src/vdbe.h  \
          125  +   parse.h
   112    126   
   113    127   # This is the default Makefile target.  The objects listed here
   114    128   # are what get build when you type just "make" with no arguments.
   115    129   #
   116    130   all:	sqlite.h libsqlite.la sqlite 
   117    131   
   118    132   # Generate the file "last_change" which contains the date of change
................................................................................
   128    142   libtclsqlite.la:	tclsqlite.lo libsqlite.la
   129    143   	$(LIBTOOL) $(TCC) -o libtclsqlite.la tclsqlite.lo \
   130    144   		libsqlite.la $(LIBTCL) -rpath $(exec_prefix)/lib
   131    145   
   132    146   sqlite:	$(TOP)/src/shell.c libsqlite.la sqlite.h
   133    147   	$(LIBTOOL) $(TCC) $(READLINE_FLAGS) -o sqlite $(TOP)/src/shell.c \
   134    148   		libsqlite.la $(LIBREADLINE) -rpath $(exec_prefix)/lib
          149  +
          150  +# This target creates a directory named "tsrc" and fills it with
          151  +# copies of all of the C source code and header files needed to
          152  +# build on the target system.  Some of the C source code and header
          153  +# files are automatically generated.  This target takes care of
          154  +# all that automatic generation.
          155  +#
          156  +target_source:	$(SRC) $(HDR) 
          157  +	rm -rf tsrc
          158  +	mkdir tsrc
          159  +	cp $(SRC) $(HDR) tsrc
          160  +	rm tsrc/sqlite.h.in tsrc/parse.y
          161  +	cp parse.c tsrc
   135    162   
   136    163   # Rules to build the LEMON compiler generator
   137    164   #
   138    165   lemon:	$(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
   139    166   	$(BCC) -o lemon $(TOP)/tool/lemon.c
   140    167   	cp $(TOP)/tool/lempar.c .
   141    168   
   142         -# Header files used by all library source files.
   143         -#
   144         -HDR = \
   145         -   sqlite.h  \
   146         -   $(TOP)/src/btree.h \
   147         -   $(TOP)/src/os.h \
   148         -   $(TOP)/src/sqliteInt.h  \
   149         -   $(TOP)/src/vdbe.h  \
   150         -   parse.h
   151         -
   152    169   btree.lo:	$(TOP)/src/btree.c $(HDR) $(TOP)/src/pager.h
   153    170   	$(LIBTOOL) $(TCC) -c $(TOP)/src/btree.c
   154    171   
   155    172   build.lo:	$(TOP)/src/build.c $(HDR)
   156    173   	$(LIBTOOL) $(TCC) -c $(TOP)/src/build.c
   157    174   
   158    175   main.lo:	$(TOP)/src/main.c $(HDR)
   159    176   	$(LIBTOOL) $(TCC) -c $(TOP)/src/main.c
   160    177   
   161    178   pager.lo:	$(TOP)/src/pager.c $(HDR) $(TOP)/src/pager.h
   162    179   	$(LIBTOOL) $(TCC) -c $(TOP)/src/pager.c
   163    180   
          181  +opcodes.lo:	opcodes.c
          182  +	$(LIBTOOL) $(TCC) -c opcodes.c
          183  +
          184  +opcodes.c:	$(TOP)/src/vdbe.c
          185  +	echo '/* Automatically generated file.  Do not edit */' >opcodes.c
          186  +	echo 'char *sqliteOpcodeNames[] = { "???", ' >>opcodes.c
          187  +	grep '^case OP_' $(TOP)/src/vdbe.c | \
          188  +	  sed -e 's/^.*OP_/  "/' -e 's/:.*$$/", /' >>opcodes.c
          189  +	echo '};' >>opcodes.c
          190  +
          191  +opcodes.h:	$(TOP)/src/vdbe.h
          192  +	echo '/* Automatically generated file.  Do not edit */' >opcodes.h
          193  +	grep '^case OP_' $(TOP)/src/vdbe.c | \
          194  +	  sed -e 's/://' | \
          195  +	  awk '{printf "#define %-30s %3d\n", $$2, ++cnt}' >>opcodes.h
          196  +
   164    197   os.lo:	$(TOP)/src/os.c $(HDR)
   165    198   	$(LIBTOOL) $(TCC) -c $(TOP)/src/os.c
   166    199   
   167    200   parse.lo:	parse.c $(HDR)
   168    201   	$(LIBTOOL) $(TCC) -c parse.c
   169    202   
   170    203   parse.h:	parse.c
................................................................................
   279    312   
   280    313   speed.html:	$(TOP)/www/speed.tcl
   281    314   	tclsh $(TOP)/www/speed.tcl >speed.html
   282    315   
   283    316   faq.html:	$(TOP)/www/faq.tcl
   284    317   	tclsh $(TOP)/www/faq.tcl >faq.html
   285    318   
          319  +formatchng.html:	$(TOP)/www/formatchng.tcl
          320  +	tclsh $(TOP)/www/formatchng.tcl >formatchng.html
          321  +
          322  +conflict.html:	$(TOP)/www/conflict.tcl
          323  +	tclsh $(TOP)/www/conflict.tcl >conflict.html
          324  +
   286    325   download.html:	$(TOP)/www/download.tcl
   287    326   	tclsh $(TOP)/www/download.tcl >download.html
   288    327   
          328  +omitted.html:	$(TOP)/www/omitted.tcl
          329  +	tclsh $(TOP)/www/omitted.tcl >omitted.html
          330  +
          331  +datatypes.html:	$(TOP)/www/datatypes.tcl
          332  +	tclsh $(TOP)/www/datatypes.tcl >datatypes.html
          333  +
          334  +quickstart.html:	$(TOP)/www/quickstart.tcl
          335  +	tclsh $(TOP)/www/quickstart.tcl >quickstart.html
          336  +
          337  +fileformat.html:	$(TOP)/www/fileformat.tcl
          338  +	tclsh $(TOP)/www/fileformat.tcl >fileformat.html
          339  +
          340  +nulls.html:	$(TOP)/www/nulls.tcl
          341  +	tclsh $(TOP)/www/nulls.tcl >nulls.html
          342  +
   289    343   
   290    344   # Files to be published on the website.
   291    345   #
   292    346   DOC = \
   293    347     index.html \
   294    348     sqlite.html \
   295    349     changes.html \
................................................................................
   300    354     vdbe.html \
   301    355     c_interface.html \
   302    356     crosscompile.html \
   303    357     mingw.html \
   304    358     tclsqlite.html \
   305    359     download.html \
   306    360     speed.html \
   307         -  faq.html
          361  +  faq.html \
          362  +  formatchng.html \
          363  +  conflict.html \
          364  +  omitted.html \
          365  +  datatypes.html \
          366  +  quickstart.html \
          367  +  fileformat.html \
          368  +  nulls.html
   308    369   
   309    370   doc:	$(DOC)
   310    371   	mkdir -p doc
   311    372   	mv $(DOC) doc
   312    373   
   313    374   install:	sqlite libsqlite.la sqlite.h
   314    375   	$(INSTALL) -d $(exec_prefix)/lib
................................................................................
   315    376   	$(LIBTOOL) $(INSTALL) libsqlite.la $(exec_prefix)/lib
   316    377   	$(INSTALL) -d $(exec_prefix)/bin
   317    378   	$(LIBTOOL) $(INSTALL) sqlite $(exec_prefix)/bin
   318    379   	$(INSTALL) -d $(prefix)/include
   319    380   	$(INSTALL) -m 0644 sqlite.h $(prefix)/include
   320    381   
   321    382   clean:	
   322         -	rm -f *.lo *.la *.o sqlite libsqlite.la sqlite.h
          383  +	rm -f *.lo *.la *.o sqlite libsqlite.la sqlite.h opcodes.*
   323    384   	rm -rf .libs .deps 
   324    385   	rm -f lemon lempar.c parse.* sqlite*.tar.gz
   325    386   	rm -f $(PUBLISH)
   326    387   	rm -f *.da *.bb *.bbg gmon.out
   327    388   	rm -f testfixture test.db
   328    389   	rm -rf doc
   329    390   
   330    391   distclean:	clean
   331    392   	rm -f config.log config.status

Changes to main.mk.

    50     50   
    51     51   # This is how we compile
    52     52   #
    53     53   TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) -I. -I$(TOP)/src
    54     54   
    55     55   # Object files for the SQLite library.
    56     56   #
    57         -LIBOBJ = btree.o build.o delete.o expr.o func.o hash.o insert.o \
    58         -         main.o os.o pager.o parse.o printf.o random.o select.o table.o \
           57  +LIBOBJ = btree.o build.o delete.o expr.o func.o hash.o insert.o main.o \
           58  +         opcodes.o os.o pager.o parse.o printf.o random.o select.o table.o \
    59     59            tokenize.o trigger.o update.o util.o vdbe.o where.o tclsqlite.o
    60     60   
    61     61   # All of the source code files.
    62     62   #
    63     63   SRC = \
    64     64     $(TOP)/src/btree.c \
    65     65     $(TOP)/src/btree.h \
................................................................................
   105    105   
   106    106   # Header files used by all library source files.
   107    107   #
   108    108   HDR = \
   109    109      sqlite.h  \
   110    110      $(TOP)/src/btree.h \
   111    111      $(TOP)/src/hash.h \
          112  +   opcodes.h \
   112    113      $(TOP)/src/os.h \
   113    114      $(TOP)/src/sqliteInt.h  \
   114    115      $(TOP)/src/vdbe.h  \
   115    116      parse.h
   116    117   
   117    118   # This is the default Makefile target.  The objects listed here
   118    119   # are what get build when you type just "make" with no arguments.
................................................................................
   161    162   
   162    163   main.o:	$(TOP)/src/main.c $(HDR)
   163    164   	$(TCCX) -c $(TOP)/src/main.c
   164    165   
   165    166   pager.o:	$(TOP)/src/pager.c $(HDR) $(TOP)/src/pager.h
   166    167   	$(TCCX) -c $(TOP)/src/pager.c
   167    168   
          169  +opcodes.o:	opcodes.c
          170  +	$(TCCX) -c opcodes.c
          171  +
          172  +opcodes.c:	$(TOP)/src/vdbe.c
          173  +	echo '/* Automatically generated file.  Do not edit */' >opcodes.c
          174  +	echo 'char *sqliteOpcodeNames[] = { "???", ' >>opcodes.c
          175  +	grep '^case OP_' $(TOP)/src/vdbe.c | \
          176  +	  sed -e 's/^.*OP_/  "/' -e 's/:.*$$/", /' >>opcodes.c
          177  +	echo '};' >>opcodes.c
          178  +
          179  +opcodes.h:	$(TOP)/src/vdbe.h
          180  +	echo '/* Automatically generated file.  Do not edit */' >opcodes.h
          181  +	grep '^case OP_' $(TOP)/src/vdbe.c | \
          182  +	  sed -e 's/://' | \
          183  +	  awk '{printf "#define %-30s %3d\n", $$2, ++cnt}' >>opcodes.h
          184  +
   168    185   os.o:	$(TOP)/src/os.c $(HDR)
   169    186   	$(TCCX) -c $(TOP)/src/os.c
   170    187   
   171    188   parse.o:	parse.c $(HDR)
   172    189   	$(TCCX) -c parse.c
   173    190   
   174    191   parse.h:	parse.c
................................................................................
   344    361   
   345    362   install:	sqlite libsqlite.a sqlite.h
   346    363   	mv sqlite /usr/bin
   347    364   	mv libsqlite.a /usr/lib
   348    365   	mv sqlite.h /usr/include
   349    366   
   350    367   clean:	
   351         -	rm -f *.o sqlite libsqlite.a sqlite.h
          368  +	rm -f *.o sqlite libsqlite.a sqlite.h opcodes.*
   352    369   	rm -f lemon lempar.c parse.* sqlite*.tar.gz
   353    370   	rm -f $(PUBLISH)
   354    371   	rm -f *.da *.bb *.bbg gmon.out
   355    372   	rm -rf tsrc

Changes to src/expr.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains routines used for analyzing expressions and
    13     13   ** for generating VDBE code that evaluates expressions in SQLite.
    14     14   **
    15         -** $Id: expr.c,v 1.80 2002/08/24 18:24:54 drh Exp $
           15  +** $Id: expr.c,v 1.81 2002/09/08 00:04:52 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <ctype.h>
    19     19   
    20     20   /*
    21     21   ** Construct a new expression node and return a pointer to it.  Memory
    22     22   ** for this node is obtained from sqliteMalloc().  The calling function
................................................................................
  1365   1365       case TK_LT:
  1366   1366       case TK_LE:
  1367   1367       case TK_GT:
  1368   1368       case TK_GE:
  1369   1369       case TK_NE:
  1370   1370       case TK_EQ: {
  1371   1371         if( pParse->db->file_format>=4 && sqliteExprType(pExpr)==SQLITE_SO_TEXT ){
  1372         -        op += 6;  /* Convert numeric opcodes to text opcodes */
         1372  +        /* Convert numeric comparison opcodes into text comparison opcodes.
         1373  +        ** This step depends on the fact that the text comparision opcodes are
         1374  +        ** always 6 greater than their corresponding numeric comparison
         1375  +        ** opcodes.
         1376  +        */
         1377  +        assert( OP_Eq+6 == OP_StrEq );
         1378  +        op += 6;
  1373   1379         }
  1374   1380         sqliteExprCode(pParse, pExpr->pLeft);
  1375   1381         sqliteExprCode(pParse, pExpr->pRight);
  1376   1382         sqliteVdbeAddOp(v, op, jumpIfNull, dest);
  1377   1383         break;
  1378   1384       }
  1379   1385       case TK_ISNULL:

Changes to src/vdbe.c.

    26     26   ** type to the other occurs as necessary.
    27     27   ** 
    28     28   ** Most of the code in this file is taken up by the sqliteVdbeExec()
    29     29   ** function which does the work of interpreting a VDBE program.
    30     30   ** But other routines are also provided to help in building up
    31     31   ** a program instruction by instruction.
    32     32   **
    33         -** $Id: vdbe.c,v 1.175 2002/09/03 19:43:24 drh Exp $
           33  +** $Id: vdbe.c,v 1.176 2002/09/08 00:04:52 drh Exp $
    34     34   */
    35     35   #include "sqliteInt.h"
    36     36   #include <ctype.h>
    37     37   
           38  +/*
           39  +** The makefile scans this source file and creates the following
           40  +** array of string constants which are the names of all VDBE opcodes.
           41  +** This array is defined in a separate source code file named opcode.c
           42  +** which is automatically generated by the makefile.
           43  +*/
           44  +extern char *sqliteOpcodeNames[];
           45  +
    38     46   /*
    39     47   ** The following global variable is incremented every time a cursor
    40     48   ** moves, either by the OP_MoveTo or the OP_Next opcode.  The test
    41     49   ** procedures use this information to make sure that indices are
    42     50   ** working correctly.
    43     51   */
    44     52   int sqlite_search_count = 0;
................................................................................
  1062   1070     sqliteFree(p->aOp);
  1063   1071     sqliteFree(p->aLabel);
  1064   1072     sqliteFree(p->aStack);
  1065   1073     sqliteFree(p->zStack);
  1066   1074     sqliteFree(p);
  1067   1075   }
  1068   1076   
  1069         -/*
  1070         -** A translation from opcode numbers to opcode names.  Used for testing
  1071         -** and debugging only.
  1072         -**
  1073         -** If any of the numeric OP_ values for opcodes defined in sqliteVdbe.h
  1074         -** change, be sure to change this array to match.  You can use the
  1075         -** "opNames.awk" awk script which is part of the source tree to regenerate
  1076         -** this array, then copy and paste it into this file, if you want.
  1077         -*/
  1078         -static char *zOpName[] = { 0,
  1079         -  "Transaction",       "Checkpoint",        "Commit",            "Rollback",
  1080         -  "ReadCookie",        "SetCookie",         "VerifyCookie",      "Open",
  1081         -  "OpenTemp",          "OpenWrite",         "OpenAux",           "OpenWrAux",
  1082         -  "RenameCursor",      "Close",             "MoveTo",            "NewRecno",
  1083         -  "PutIntKey",         "PutStrKey",         "Distinct",          "Found",
  1084         -  "NotFound",          "IsUnique",          "NotExists",         "Delete",
  1085         -  "Column",            "KeyAsData",         "Recno",             "FullKey",
  1086         -  "NullRow",           "Last",              "Rewind",            "Next",
  1087         -  "Destroy",           "Clear",             "CreateIndex",       "CreateTable",
  1088         -  "IntegrityCk",       "IdxPut",            "IdxDelete",         "IdxRecno",
  1089         -  "IdxGT",             "IdxGE",             "MemLoad",           "MemStore",
  1090         -  "MemIncr",           "ListWrite",         "ListRewind",        "ListRead",
  1091         -  "ListReset",         "ListPush",          "ListPop",           "SortPut",
  1092         -  "SortMakeRec",       "SortMakeKey",       "Sort",              "SortNext",
  1093         -  "SortCallback",      "SortReset",         "FileOpen",          "FileRead",
  1094         -  "FileColumn",        "AggReset",          "AggFocus",          "AggNext",
  1095         -  "AggSet",            "AggGet",            "AggFunc",           "AggInit",
  1096         -  "AggPush",           "AggPop",            "SetInsert",         "SetFound",
  1097         -  "SetNotFound",       "SetFirst",          "SetNext",           "MakeRecord",
  1098         -  "MakeKey",           "MakeIdxKey",        "IncrKey",           "Goto",
  1099         -  "If",                "IfNot",             "Halt",              "Gosub",
  1100         -  "Return",            "ColumnCount",       "ColumnName",        "Callback",
  1101         -  "NullCallback",      "Integer",           "String",            "Pop",
  1102         -  "Dup",               "Pull",              "Push",              "MustBeInt",
  1103         -  "Add",               "AddImm",            "Subtract",          "Multiply",
  1104         -  "Divide",            "Remainder",         "BitAnd",            "BitOr",
  1105         -  "BitNot",            "ShiftLeft",         "ShiftRight",        "AbsValue",
  1106         -  "Eq",                "Ne",                "Lt",                "Le",
  1107         -  "Gt",                "Ge",                "StrEq",             "StrNe",
  1108         -  "StrLt",             "StrLe",             "StrGt",             "StrGe",
  1109         -  "IsNull",            "NotNull",           "Negative",          "And",
  1110         -  "Or",                "Not",               "Concat",            "Noop",
  1111         -  "Function",        
  1112         -};
  1113         -
  1114         -/*
  1115         -** Given the name of an opcode, return its number.  Return 0 if
  1116         -** there is no match.
  1117         -**
  1118         -** This routine is used for testing and debugging.
  1119         -*/
  1120         -int sqliteVdbeOpcode(const char *zName){
  1121         -  int i;
  1122         -  for(i=1; i<=OP_MAX; i++){
  1123         -    if( sqliteStrICmp(zName, zOpName[i])==0 ) return i;
  1124         -  }
  1125         -  return 0;
  1126         -}
  1127         -
  1128   1077   /*
  1129   1078   ** Give a listing of the program in the virtual machine.
  1130   1079   **
  1131   1080   ** The interface is the same as sqliteVdbeExec().  But instead of
  1132   1081   ** running the code, it invokes the callback once for each instruction.
  1133   1082   ** This feature is used to implement "EXPLAIN".
  1134   1083   */
................................................................................
  1171   1120       sprintf(zP2,"%d", p->aOp[i].p2);
  1172   1121       if( p->aOp[i].p3type==P3_POINTER ){
  1173   1122         sprintf(zP3, "ptr(%#x)", (int)p->aOp[i].p3);
  1174   1123         azValue[4] = zP3;
  1175   1124       }else{
  1176   1125         azValue[4] = p->aOp[i].p3;
  1177   1126       }
  1178         -    azValue[1] = zOpName[p->aOp[i].opcode];
         1127  +    azValue[1] = sqliteOpcodeNames[p->aOp[i].opcode];
  1179   1128       if( sqliteSafetyOff(db) ){
  1180   1129         rc = SQLITE_MISUSE;
  1181   1130         break;
  1182   1131       }
  1183   1132       if( xCallback(pArg, 5, azValue, azColumnNames) ){
  1184   1133         rc = SQLITE_ABORT;
  1185   1134       }
................................................................................
  1306   1255       sprintf(zPtr, "ptr(%#x)", (int)pOp->p3);
  1307   1256       zP3 = zPtr;
  1308   1257     }else{
  1309   1258       zP3 = pOp->p3;
  1310   1259     }
  1311   1260     if( pOut==0 ) pOut = stdout;
  1312   1261     fprintf(pOut,"%4d %-12s %4d %4d %s\n",
  1313         -      pc, zOpName[pOp->opcode], pOp->p1, pOp->p2, zP3 ? zP3 : "");
         1262  +      pc, sqliteOpcodeNames[pOp->opcode], pOp->p1, pOp->p2, zP3 ? zP3 : "");
  1314   1263     fflush(pOut);
  1315   1264   }
  1316   1265   #endif
  1317   1266   
  1318   1267   /*
  1319   1268   ** Make sure there is space in the Vdbe structure to hold at least
  1320   1269   ** mxCursor cursors.  If there is not currently enough space, then
................................................................................
  2279   2228     }else{
  2280   2229       p->tos++;
  2281   2230       aStack[nos].flags = STK_Int;
  2282   2231       aStack[nos].i = c;
  2283   2232     }
  2284   2233     break;
  2285   2234   }
  2286         -
         2235  +/* INSERT NO CODE HERE!
         2236  +**
         2237  +** The opcode numbers are extracted from this source file by doing
         2238  +**
         2239  +**    grep '^case OP_' vdbe.c | ... >opcodes.h
         2240  +**
         2241  +** The opcodes are numbered in the order that they appear in this file.
         2242  +** But in order for the expression generating code to work right, the
         2243  +** string comparison operators that follow must be numbered exactly 6
         2244  +** greater than the numeric comparison opcodes above.  So no other
         2245  +** cases can appear between the two.
         2246  +*/
  2287   2247   /* Opcode: StrEq P1 P2 *
  2288   2248   **
  2289   2249   ** Pop the top two elements from the stack.  If they are equal, then
  2290   2250   ** jump to instruction P2.  Otherwise, continue to the next instruction.
  2291   2251   **
  2292   2252   ** If either operand is NULL (and thus if the result is unknown) then
  2293   2253   ** take the jump if P1 is true.
................................................................................
  2399   2359         aStack[nos].flags = STK_Null;
  2400   2360       }
  2401   2361       break;
  2402   2362     }else{
  2403   2363       if( Stringify(p, tos) || Stringify(p, nos) ) goto no_mem;
  2404   2364       c = strcmp(zStack[nos], zStack[tos]);
  2405   2365     }
         2366  +  /* The asserts on each case of the following switch are there to verify
         2367  +  ** that string comparison opcodes are always exactly 6 greater than the
         2368  +  ** corresponding numeric comparison opcodes.  The code generator depends
         2369  +  ** on this fact.
         2370  +  */
  2406   2371     switch( pOp->opcode ){
  2407         -    case OP_StrEq:    c = c==0;     break;
  2408         -    case OP_StrNe:    c = c!=0;     break;
  2409         -    case OP_StrLt:    c = c<0;      break;
  2410         -    case OP_StrLe:    c = c<=0;     break;
  2411         -    case OP_StrGt:    c = c>0;      break;
  2412         -    default:          c = c>=0;     break;
         2372  +    case OP_StrEq:    c = c==0;    assert( pOp->opcode-6==OP_Eq );   break;
         2373  +    case OP_StrNe:    c = c!=0;    assert( pOp->opcode-6==OP_Ne );   break;
         2374  +    case OP_StrLt:    c = c<0;     assert( pOp->opcode-6==OP_Lt );   break;
         2375  +    case OP_StrLe:    c = c<=0;    assert( pOp->opcode-6==OP_Le );   break;
         2376  +    case OP_StrGt:    c = c>0;     assert( pOp->opcode-6==OP_Gt );   break;
         2377  +    default:          c = c>=0;    assert( pOp->opcode-6==OP_Ge );   break;
  2413   2378     }
  2414   2379     POPSTACK;
  2415   2380     POPSTACK;
  2416   2381     if( pOp->p2 ){
  2417   2382       if( c ) pc = pOp->p2-1;
  2418   2383     }else{
  2419   2384       p->tos++;
................................................................................
  3784   3749         zStack[tos] = z;
  3785   3750         aStack[tos].n = amt;
  3786   3751       }
  3787   3752       p->tos = tos;
  3788   3753     }
  3789   3754     break;
  3790   3755   }
         3756  +
         3757  +/* Opcode: Extract * * *
         3758  +*/
  3791   3759   
  3792   3760   /* Opcode: Recno P1 * *
  3793   3761   **
  3794   3762   ** Push onto the stack an integer which is the first 4 bytes of the
  3795   3763   ** the key to the current entry in a sequential scan of the database
  3796   3764   ** file P1.  The sequential scan should have been started using the 
  3797   3765   ** Next opcode.

Changes to src/vdbe.h.

    11     11   *************************************************************************
    12     12   ** Header file for the Virtual DataBase Engine (VDBE)
    13     13   **
    14     14   ** This header defines the interface to the virtual database engine
    15     15   ** or VDBE.  The VDBE implements an abstract machine that runs a
    16     16   ** simple program to access and modify the underlying database.
    17     17   **
    18         -** $Id: vdbe.h,v 1.59 2002/08/28 03:01:01 drh Exp $
           18  +** $Id: vdbe.h,v 1.60 2002/09/08 00:04:53 drh Exp $
    19     19   */
    20     20   #ifndef _SQLITE_VDBE_H_
    21     21   #define _SQLITE_VDBE_H_
    22     22   #include <stdio.h>
    23     23   
    24     24   /*
    25     25   ** A single VDBE is an opaque structure named "Vdbe".  Only routines
................................................................................
    55     55   ** of a VdbeOp structure into a negative number so that 
    56     56   ** sqliteVdbeAddOpList() knows that the address is relative.  Calling
    57     57   ** the macro again restores the address.
    58     58   */
    59     59   #define ADDR(X)  (-1-(X))
    60     60   
    61     61   /*
    62         -** These are the available opcodes.
    63         -**
    64         -** If any of the values changes or if opcodes are added or removed,
    65         -** be sure to also update the zOpName[] array in sqliteVdbe.c to
    66         -** mirror the change.
    67         -**
    68         -** The source tree contains an AWK script named renumberOps.awk that
    69         -** can be used to renumber these opcodes when new opcodes are inserted.
           62  +** The makefile scans the vdbe.c source file and creates the "opcodes.h"
           63  +** header file that defines a number for each opcode used by the VDBE.
    70     64   */
    71         -#define OP_Transaction         1
    72         -#define OP_Checkpoint          2
    73         -#define OP_Commit              3
    74         -#define OP_Rollback            4
    75         -
    76         -#define OP_ReadCookie          5
    77         -#define OP_SetCookie           6
    78         -#define OP_VerifyCookie        7
    79         -
    80         -#define OP_Open                8
    81         -#define OP_OpenTemp            9
    82         -#define OP_OpenWrite          10
    83         -#define OP_OpenAux            11
    84         -#define OP_OpenWrAux          12
    85         -#define OP_RenameCursor       13
    86         -#define OP_Close              14
    87         -#define OP_MoveTo             15
    88         -#define OP_NewRecno           16
    89         -#define OP_PutIntKey          17
    90         -#define OP_PutStrKey          18
    91         -#define OP_Distinct           19
    92         -#define OP_Found              20
    93         -#define OP_NotFound           21
    94         -#define OP_IsUnique           22
    95         -#define OP_NotExists          23
    96         -#define OP_Delete             24
    97         -#define OP_Column             25
    98         -#define OP_KeyAsData          26
    99         -#define OP_Recno              27
   100         -#define OP_FullKey            28
   101         -#define OP_NullRow            29
   102         -#define OP_Last               30
   103         -#define OP_Rewind             31
   104         -#define OP_Next               32
   105         -
   106         -#define OP_Destroy            33
   107         -#define OP_Clear              34
   108         -#define OP_CreateIndex        35
   109         -#define OP_CreateTable        36
   110         -#define OP_IntegrityCk        37
   111         -
   112         -#define OP_IdxPut             38
   113         -#define OP_IdxDelete          39
   114         -#define OP_IdxRecno           40
   115         -#define OP_IdxGT              41
   116         -#define OP_IdxGE              42
   117         -
   118         -#define OP_MemLoad            43
   119         -#define OP_MemStore           44
   120         -#define OP_MemIncr            45
   121         -
   122         -#define OP_ListWrite          46
   123         -#define OP_ListRewind         47
   124         -#define OP_ListRead           48
   125         -#define OP_ListReset          49
   126         -#define OP_ListPush           50
   127         -#define OP_ListPop            51
   128         -
   129         -#define OP_SortPut            52
   130         -#define OP_SortMakeRec        53
   131         -#define OP_SortMakeKey        54
   132         -#define OP_Sort               55
   133         -#define OP_SortNext           56
   134         -#define OP_SortCallback       57
   135         -#define OP_SortReset          58
   136         -
   137         -#define OP_FileOpen           59
   138         -#define OP_FileRead           60
   139         -#define OP_FileColumn         61
   140         -
   141         -#define OP_AggReset           62
   142         -#define OP_AggFocus           63
   143         -#define OP_AggNext            64
   144         -#define OP_AggSet             65
   145         -#define OP_AggGet             66
   146         -#define OP_AggFunc            67
   147         -#define OP_AggInit            68
   148         -#define OP_AggPush            69
   149         -#define OP_AggPop             70
   150         -
   151         -#define OP_SetInsert          71
   152         -#define OP_SetFound           72
   153         -#define OP_SetNotFound        73
   154         -#define OP_SetFirst           74
   155         -#define OP_SetNext            75
   156         -
   157         -#define OP_MakeRecord         76
   158         -#define OP_MakeKey            77
   159         -#define OP_MakeIdxKey         78
   160         -#define OP_IncrKey            79
   161         -
   162         -#define OP_Goto               80
   163         -#define OP_If                 81
   164         -#define OP_IfNot              82
   165         -#define OP_Halt               83
   166         -#define OP_Gosub              84
   167         -#define OP_Return             85
   168         -
   169         -#define OP_ColumnCount        86
   170         -#define OP_ColumnName         87
   171         -#define OP_Callback           88
   172         -#define OP_NullCallback       89
   173         -
   174         -#define OP_Integer            90
   175         -#define OP_String             91
   176         -#define OP_Pop                92
   177         -#define OP_Dup                93
   178         -#define OP_Pull               94
   179         -#define OP_Push               95
   180         -#define OP_MustBeInt          96
   181         -
   182         -#define OP_Add                97
   183         -#define OP_AddImm             98
   184         -#define OP_Subtract           99
   185         -#define OP_Multiply          100
   186         -#define OP_Divide            101
   187         -#define OP_Remainder         102
   188         -#define OP_BitAnd            103
   189         -#define OP_BitOr             104
   190         -#define OP_BitNot            105
   191         -#define OP_ShiftLeft         106
   192         -#define OP_ShiftRight        107
   193         -#define OP_AbsValue          108
   194         -
   195         -/***** IMPORTANT NOTE: The code generator assumes that OP_XX+6==OP_StrXX *****/
   196         -#define OP_Eq                109
   197         -#define OP_Ne                110
   198         -#define OP_Lt                111
   199         -#define OP_Le                112
   200         -#define OP_Gt                113
   201         -#define OP_Ge                114
   202         -#define OP_StrEq             115
   203         -#define OP_StrNe             116
   204         -#define OP_StrLt             117
   205         -#define OP_StrLe             118
   206         -#define OP_StrGt             119
   207         -#define OP_StrGe             120
   208         -/***** IMPORTANT NOTE: the code generator assumes that OP_XX+6==OP_StrXX *****/
   209         -
   210         -#define OP_IsNull            121
   211         -#define OP_NotNull           122
   212         -#define OP_Negative          123
   213         -#define OP_And               124
   214         -#define OP_Or                125
   215         -#define OP_Not               126
   216         -#define OP_Concat            127
   217         -#define OP_Noop              128
   218         -#define OP_Function          129
   219         -
   220         -#define OP_MAX               129
           65  +#include "opcodes.h"
   221     66   
   222     67   /*
   223     68   ** Prototypes for the VDBE interface.  See comments on the implementation
   224     69   ** for a description of what each of these routines does.
   225     70   */
   226     71   Vdbe *sqliteVdbeCreate(sqlite*);
   227     72   void sqliteVdbeCreateCallback(Vdbe*, int*);
................................................................................
   230     75   void sqliteVdbeChangeP1(Vdbe*, int addr, int P1);
   231     76   void sqliteVdbeChangeP2(Vdbe*, int addr, int P2);
   232     77   void sqliteVdbeChangeP3(Vdbe*, int addr, const char *zP1, int N);
   233     78   void sqliteVdbeDequoteP3(Vdbe*, int addr);
   234     79   int sqliteVdbeFindOp(Vdbe*, int, int);
   235     80   int sqliteVdbeMakeLabel(Vdbe*);
   236     81   void sqliteVdbeDelete(Vdbe*);
   237         -int sqliteVdbeOpcode(const char *zName);
   238     82   int sqliteVdbeExec(Vdbe*,sqlite_callback,void*,char**,void*,
   239     83                      int(*)(void*,const char*,int));
   240     84   int sqliteVdbeList(Vdbe*,sqlite_callback,void*,char**);
   241     85   void sqliteVdbeResolveLabel(Vdbe*, int);
   242     86   int sqliteVdbeCurrentAddr(Vdbe*);
   243     87   void sqliteVdbeTrace(Vdbe*,FILE*);
   244     88   void sqliteVdbeCompressSpace(Vdbe*,int);
   245     89   
   246     90   #endif

Deleted tool/opNames.awk.

     1         -# Read the sqliteVdbe.h file and generate a table of opcode names.
     2         -#
     3         -BEGIN {
     4         -  printf "static char *zOpName[] = { 0,\n"
     5         -  n = 0
     6         -}
     7         -/^#define OP_MAX/ {
     8         -  next
     9         -}
    10         -/^#define OP_/ {
    11         -  name = "\"" substr($2,4) "\","
    12         -  if( n<3 ){
    13         -    printf "  %-19s", name
    14         -    n++
    15         -  } else {
    16         -    printf "  %s\n", name
    17         -    n = 0
    18         -  }
    19         -}
    20         -END {
    21         -  if( n ){ printf "\n" }
    22         -  printf "};\n"
    23         -}

Deleted tool/renumberOps.awk.

     1         -# Run this script on sqliteVdbe.h to renumber the opcodes sequentially.
     2         -#
     3         -BEGIN { cnt = 1 }
     4         -/^#define OP_MAX/ {
     5         -  printf "#define %-20s %3d\n",$2, cnt-1
     6         -  next
     7         -}
     8         -/^#define OP_/ {
     9         -  printf "#define %-20s %3d\n",$2, cnt++
    10         -  next
    11         -}
    12         -{ print }