xref: /illumos-gate/usr/src/lib/libsqlite/src/vdbe.h (revision 1da57d55)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate ** 2001 September 15
37c478bd9Sstevel@tonic-gate **
47c478bd9Sstevel@tonic-gate ** The author disclaims copyright to this source code.  In place of
57c478bd9Sstevel@tonic-gate ** a legal notice, here is a blessing:
67c478bd9Sstevel@tonic-gate **
77c478bd9Sstevel@tonic-gate **    May you do good and not evil.
87c478bd9Sstevel@tonic-gate **    May you find forgiveness for yourself and forgive others.
97c478bd9Sstevel@tonic-gate **    May you share freely, never taking more than you give.
107c478bd9Sstevel@tonic-gate **
117c478bd9Sstevel@tonic-gate *************************************************************************
127c478bd9Sstevel@tonic-gate ** Header file for the Virtual DataBase Engine (VDBE)
137c478bd9Sstevel@tonic-gate **
147c478bd9Sstevel@tonic-gate ** This header defines the interface to the virtual database engine
157c478bd9Sstevel@tonic-gate ** or VDBE.  The VDBE implements an abstract machine that runs a
167c478bd9Sstevel@tonic-gate ** simple program to access and modify the underlying database.
177c478bd9Sstevel@tonic-gate **
187c478bd9Sstevel@tonic-gate ** $Id: vdbe.h,v 1.71 2004/02/22 20:05:02 drh Exp $
197c478bd9Sstevel@tonic-gate */
207c478bd9Sstevel@tonic-gate #ifndef _SQLITE_VDBE_H_
217c478bd9Sstevel@tonic-gate #define _SQLITE_VDBE_H_
227c478bd9Sstevel@tonic-gate #include <stdio.h>
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate /*
257c478bd9Sstevel@tonic-gate ** A single VDBE is an opaque structure named "Vdbe".  Only routines
267c478bd9Sstevel@tonic-gate ** in the source file sqliteVdbe.c are allowed to see the insides
277c478bd9Sstevel@tonic-gate ** of this structure.
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate typedef struct Vdbe Vdbe;
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate ** A single instruction of the virtual machine has an opcode
337c478bd9Sstevel@tonic-gate ** and as many as three operands.  The instruction is recorded
347c478bd9Sstevel@tonic-gate ** as an instance of the following structure:
357c478bd9Sstevel@tonic-gate */
367c478bd9Sstevel@tonic-gate struct VdbeOp {
377c478bd9Sstevel@tonic-gate   u8 opcode;          /* What operation to perform */
387c478bd9Sstevel@tonic-gate   int p1;             /* First operand */
397c478bd9Sstevel@tonic-gate   int p2;             /* Second parameter (often the jump destination) */
407c478bd9Sstevel@tonic-gate   char *p3;           /* Third parameter */
417c478bd9Sstevel@tonic-gate   int p3type;         /* P3_STATIC, P3_DYNAMIC or P3_POINTER */
427c478bd9Sstevel@tonic-gate #ifdef VDBE_PROFILE
437c478bd9Sstevel@tonic-gate   int cnt;            /* Number of times this instruction was executed */
447c478bd9Sstevel@tonic-gate   long long cycles;   /* Total time spend executing this instruction */
457c478bd9Sstevel@tonic-gate #endif
467c478bd9Sstevel@tonic-gate };
477c478bd9Sstevel@tonic-gate typedef struct VdbeOp VdbeOp;
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate ** A smaller version of VdbeOp used for the VdbeAddOpList() function because
517c478bd9Sstevel@tonic-gate ** it takes up less space.
527c478bd9Sstevel@tonic-gate */
537c478bd9Sstevel@tonic-gate struct VdbeOpList {
547c478bd9Sstevel@tonic-gate   u8 opcode;          /* What operation to perform */
557c478bd9Sstevel@tonic-gate   signed char p1;     /* First operand */
567c478bd9Sstevel@tonic-gate   short int p2;       /* Second parameter (often the jump destination) */
577c478bd9Sstevel@tonic-gate   char *p3;           /* Third parameter */
587c478bd9Sstevel@tonic-gate };
597c478bd9Sstevel@tonic-gate typedef struct VdbeOpList VdbeOpList;
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate ** Allowed values of VdbeOp.p3type
637c478bd9Sstevel@tonic-gate */
647c478bd9Sstevel@tonic-gate #define P3_NOTUSED    0   /* The P3 parameter is not used */
657c478bd9Sstevel@tonic-gate #define P3_DYNAMIC  (-1)  /* Pointer to a string obtained from sqliteMalloc() */
667c478bd9Sstevel@tonic-gate #define P3_STATIC   (-2)  /* Pointer to a static string */
677c478bd9Sstevel@tonic-gate #define P3_POINTER  (-3)  /* P3 is a pointer to some structure or object */
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate ** The following macro converts a relative address in the p2 field
71*1da57d55SToomas Soome ** of a VdbeOp structure into a negative number so that
727c478bd9Sstevel@tonic-gate ** sqliteVdbeAddOpList() knows that the address is relative.  Calling
737c478bd9Sstevel@tonic-gate ** the macro again restores the address.
747c478bd9Sstevel@tonic-gate */
757c478bd9Sstevel@tonic-gate #define ADDR(X)  (-1-(X))
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate ** The makefile scans the vdbe.c source file and creates the "opcodes.h"
797c478bd9Sstevel@tonic-gate ** header file that defines a number for each opcode used by the VDBE.
807c478bd9Sstevel@tonic-gate */
817c478bd9Sstevel@tonic-gate #include "opcodes.h"
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate ** Prototypes for the VDBE interface.  See comments on the implementation
857c478bd9Sstevel@tonic-gate ** for a description of what each of these routines does.
867c478bd9Sstevel@tonic-gate */
877c478bd9Sstevel@tonic-gate Vdbe *sqliteVdbeCreate(sqlite*);
887c478bd9Sstevel@tonic-gate void sqliteVdbeCreateCallback(Vdbe*, int*);
897c478bd9Sstevel@tonic-gate int sqliteVdbeAddOp(Vdbe*,int,int,int);
907c478bd9Sstevel@tonic-gate int sqliteVdbeOp3(Vdbe*,int,int,int,const char *zP3,int);
917c478bd9Sstevel@tonic-gate int sqliteVdbeCode(Vdbe*,...);
927c478bd9Sstevel@tonic-gate int sqliteVdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
937c478bd9Sstevel@tonic-gate void sqliteVdbeChangeP1(Vdbe*, int addr, int P1);
947c478bd9Sstevel@tonic-gate void sqliteVdbeChangeP2(Vdbe*, int addr, int P2);
957c478bd9Sstevel@tonic-gate void sqliteVdbeChangeP3(Vdbe*, int addr, const char *zP1, int N);
967c478bd9Sstevel@tonic-gate void sqliteVdbeDequoteP3(Vdbe*, int addr);
977c478bd9Sstevel@tonic-gate int sqliteVdbeFindOp(Vdbe*, int, int);
987c478bd9Sstevel@tonic-gate VdbeOp *sqliteVdbeGetOp(Vdbe*, int);
997c478bd9Sstevel@tonic-gate int sqliteVdbeMakeLabel(Vdbe*);
1007c478bd9Sstevel@tonic-gate void sqliteVdbeDelete(Vdbe*);
1017c478bd9Sstevel@tonic-gate void sqliteVdbeMakeReady(Vdbe*,int,int);
1027c478bd9Sstevel@tonic-gate int sqliteVdbeExec(Vdbe*);
1037c478bd9Sstevel@tonic-gate int sqliteVdbeList(Vdbe*);
1047c478bd9Sstevel@tonic-gate int sqliteVdbeFinalize(Vdbe*,char**);
1057c478bd9Sstevel@tonic-gate void sqliteVdbeResolveLabel(Vdbe*, int);
1067c478bd9Sstevel@tonic-gate int sqliteVdbeCurrentAddr(Vdbe*);
1077c478bd9Sstevel@tonic-gate void sqliteVdbeTrace(Vdbe*,FILE*);
1087c478bd9Sstevel@tonic-gate void sqliteVdbeCompressSpace(Vdbe*,int);
1097c478bd9Sstevel@tonic-gate int sqliteVdbeReset(Vdbe*,char **);
1107c478bd9Sstevel@tonic-gate int sqliteVdbeSetVariables(Vdbe*,int,const char**);
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate #endif
113