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