blob: 5eac05fc0231be1cc9f2fafc4384a5fb6b3b8533 [file] [log] [blame]
drh7651e0a2015-10-07 12:11:36 +00001#!/usr/bin/tclsh
2#
3# This TCL script scans the opcodes.h file (which is itself generated by
4# another TCL script) and uses the information gleaned to create the
5# opcodes.c source file.
6#
7# Opcodes.c contains strings which are the symbolic names for the various
8# opcodes used by the VDBE. These strings are used when disassembling a
9# VDBE program during tracing or as a result of the EXPLAIN keyword.
10#
11puts "/* Automatically generated. Do not edit */"
12puts "/* See the tool/mkopcodec.tcl script for details. */"
13puts "#if !defined(SQLITE_OMIT_EXPLAIN) \\"
14puts " || defined(VDBE_PROFILE) \\"
15puts " || defined(SQLITE_DEBUG)"
16puts "#if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) || defined(SQLITE_DEBUG)"
17puts "# define OpHelp(X) \"\\0\" X"
18puts "#else"
19puts "# define OpHelp(X)"
20puts "#endif"
21puts "const char *sqlite3OpcodeName(int i)\173"
drhed94af52016-02-01 17:20:08 +000022puts " static const char *const azName\[\] = \173"
drh7651e0a2015-10-07 12:11:36 +000023set mx 0
24
drh20de9f62021-07-29 16:49:28 +000025set in [open [lindex $argv 0]]
26fconfigure $in -translation binary
drh7651e0a2015-10-07 12:11:36 +000027while {![eof $in]} {
28 set line [gets $in]
29 if {[regexp {^#define OP_} $line]} {
30 set name [lindex $line 1]
31 regsub {^OP_} $name {} name
32 set i [lindex $line 2]
33 set label($i) $name
34 if {$mx<$i} {set mx $i}
35 if {[regexp {synopsis: (.*) \*/} $line all x]} {
36 set synopsis($i) [string trim $x]
37 } else {
38 set synopsis($i) {}
39 }
40 }
41}
42close $in
43
drhed94af52016-02-01 17:20:08 +000044for {set i 0} {$i<=$mx} {incr i} {
drh7651e0a2015-10-07 12:11:36 +000045 puts [format " /* %3d */ %-18s OpHelp(\"%s\")," \
46 $i \"$label($i)\" $synopsis($i)]
47}
48puts " \175;"
49puts " return azName\[i\];"
50puts "\175"
51puts "#endif"