summaryrefslogtreecommitdiff
path: root/ext/pdo_sqlite/sqlite/mkopcodeh.awk
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2005-01-07 05:27:27 +0000
committerWez Furlong <wez@php.net>2005-01-07 05:27:27 +0000
commite6c282a76639fe4b6e9166210b4f338b83df44e7 (patch)
tree6b0cb08f8b1efc397477efcfff0bbffaedbe0f36 /ext/pdo_sqlite/sqlite/mkopcodeh.awk
parent02d6b65c672835f27fd2b160338ab05f1dfca3a1 (diff)
downloadphp-git-e6c282a76639fe4b6e9166210b4f338b83df44e7.tar.gz
jumbo commit; implement sqlstate error codes.
Bundle sqlite3
Diffstat (limited to 'ext/pdo_sqlite/sqlite/mkopcodeh.awk')
-rw-r--r--ext/pdo_sqlite/sqlite/mkopcodeh.awk48
1 files changed, 48 insertions, 0 deletions
diff --git a/ext/pdo_sqlite/sqlite/mkopcodeh.awk b/ext/pdo_sqlite/sqlite/mkopcodeh.awk
new file mode 100644
index 0000000000..ead07d5ff9
--- /dev/null
+++ b/ext/pdo_sqlite/sqlite/mkopcodeh.awk
@@ -0,0 +1,48 @@
+#!/usr/bin/awk -f
+#
+# 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.
+#
+
+# Remember the TK_ values from the parse.h file
+/^#define TK_/ {
+ tk[$2] = $3
+}
+
+# Scan for "case OP_aaaa:" lines in the vdbe.c file
+/^case OP_/ {
+ name = $2
+ gsub(/:/,"",name)
+ gsub("\r","",name)
+ op[name] = -1
+ for(i=3; i<NF-2; i++){
+ if($i=="same" && $(i+1)=="as"){
+ op[name] = tk[$(i+2)]
+ used[op[name]] = 1
+ }
+ }
+}
+
+# Assign numbers to all opcodes and output the result.
+END {
+ cnt = 0
+ print "/* Automatically generated. Do not edit */"
+ print "/* See the mkopcodeh.awk script for details */"
+ for(name in op){
+ if( op[name]<0 ){
+ cnt++
+ while( used[cnt] ) cnt++
+ op[name] = cnt
+ }
+ printf "#define %-30s %d\n", name, op[name]
+ }
+}