1 2 #pragma ident "%Z%%M% %I% %E% SMI" 3 4 /* 5 ** 2001 September 15 6 ** 7 ** The author disclaims copyright to this source code. In place of 8 ** a legal notice, here is a blessing: 9 ** 10 ** May you do good and not evil. 11 ** May you find forgiveness for yourself and forgive others. 12 ** May you share freely, never taking more than you give. 13 ** 14 ************************************************************************* 15 ** Header file for the Virtual DataBase Engine (VDBE) 16 ** 17 ** This header defines the interface to the virtual database engine 18 ** or VDBE. The VDBE implements an abstract machine that runs a 19 ** simple program to access and modify the underlying database. 20 ** 21 ** $Id: vdbe.h,v 1.71 2004/02/22 20:05:02 drh Exp $ 22 */ 23 #ifndef _SQLITE_VDBE_H_ 24 #define _SQLITE_VDBE_H_ 25 #include <stdio.h> 26 27 /* 28 ** A single VDBE is an opaque structure named "Vdbe". Only routines 29 ** in the source file sqliteVdbe.c are allowed to see the insides 30 ** of this structure. 31 */ 32 typedef struct Vdbe Vdbe; 33 34 /* 35 ** A single instruction of the virtual machine has an opcode 36 ** and as many as three operands. The instruction is recorded 37 ** as an instance of the following structure: 38 */ 39 struct VdbeOp { 40 u8 opcode; /* What operation to perform */ 41 int p1; /* First operand */ 42 int p2; /* Second parameter (often the jump destination) */ 43 char *p3; /* Third parameter */ 44 int p3type; /* P3_STATIC, P3_DYNAMIC or P3_POINTER */ 45 #ifdef VDBE_PROFILE 46 int cnt; /* Number of times this instruction was executed */ 47 long long cycles; /* Total time spend executing this instruction */ 48 #endif 49 }; 50 typedef struct VdbeOp VdbeOp; 51 52 /* 53 ** A smaller version of VdbeOp used for the VdbeAddOpList() function because 54 ** it takes up less space. 55 */ 56 struct VdbeOpList { 57 u8 opcode; /* What operation to perform */ 58 signed char p1; /* First operand */ 59 short int p2; /* Second parameter (often the jump destination) */ 60 char *p3; /* Third parameter */ 61 }; 62 typedef struct VdbeOpList VdbeOpList; 63 64 /* 65 ** Allowed values of VdbeOp.p3type 66 */ 67 #define P3_NOTUSED 0 /* The P3 parameter is not used */ 68 #define P3_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */ 69 #define P3_STATIC (-2) /* Pointer to a static string */ 70 #define P3_POINTER (-3) /* P3 is a pointer to some structure or object */ 71 72 /* 73 ** The following macro converts a relative address in the p2 field 74 ** of a VdbeOp structure into a negative number so that 75 ** sqliteVdbeAddOpList() knows that the address is relative. Calling 76 ** the macro again restores the address. 77 */ 78 #define ADDR(X) (-1-(X)) 79 80 /* 81 ** The makefile scans the vdbe.c source file and creates the "opcodes.h" 82 ** header file that defines a number for each opcode used by the VDBE. 83 */ 84 #include "opcodes.h" 85 86 /* 87 ** Prototypes for the VDBE interface. See comments on the implementation 88 ** for a description of what each of these routines does. 89 */ 90 Vdbe *sqliteVdbeCreate(sqlite*); 91 void sqliteVdbeCreateCallback(Vdbe*, int*); 92 int sqliteVdbeAddOp(Vdbe*,int,int,int); 93 int sqliteVdbeOp3(Vdbe*,int,int,int,const char *zP3,int); 94 int sqliteVdbeCode(Vdbe*,...); 95 int sqliteVdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp); 96 void sqliteVdbeChangeP1(Vdbe*, int addr, int P1); 97 void sqliteVdbeChangeP2(Vdbe*, int addr, int P2); 98 void sqliteVdbeChangeP3(Vdbe*, int addr, const char *zP1, int N); 99 void sqliteVdbeDequoteP3(Vdbe*, int addr); 100 int sqliteVdbeFindOp(Vdbe*, int, int); 101 VdbeOp *sqliteVdbeGetOp(Vdbe*, int); 102 int sqliteVdbeMakeLabel(Vdbe*); 103 void sqliteVdbeDelete(Vdbe*); 104 void sqliteVdbeMakeReady(Vdbe*,int,int); 105 int sqliteVdbeExec(Vdbe*); 106 int sqliteVdbeList(Vdbe*); 107 int sqliteVdbeFinalize(Vdbe*,char**); 108 void sqliteVdbeResolveLabel(Vdbe*, int); 109 int sqliteVdbeCurrentAddr(Vdbe*); 110 void sqliteVdbeTrace(Vdbe*,FILE*); 111 void sqliteVdbeCompressSpace(Vdbe*,int); 112 int sqliteVdbeReset(Vdbe*,char **); 113 int sqliteVdbeSetVariables(Vdbe*,int,const char**); 114 115 #endif 116