drh | b327f77 | 2004-10-06 15:03:57 +0000 | [diff] [blame] | 1 | #!/usr/bin/awk -f |
| 2 | # |
| 3 | # This AWK script scans the opcodes.h file (which is itself generated by |
| 4 | # another awk 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 | # |
| 11 | BEGIN { |
| 12 | print "/* Automatically generated. Do not edit */" |
drh | 279d477 | 2005-01-20 23:23:29 +0000 | [diff] [blame] | 13 | print "/* See the mkopcodec.awk script for details. */" |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 14 | printf "#if !defined(SQLITE_OMIT_EXPLAIN)" |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 15 | printf " || defined(VDBE_PROFILE)" |
| 16 | print " || defined(SQLITE_DEBUG)" |
drh | c7379ce | 2013-10-30 02:28:23 +0000 | [diff] [blame] | 17 | print "#if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) || defined(SQLITE_DEBUG)" |
drh | 81316f8 | 2013-10-29 20:40:47 +0000 | [diff] [blame] | 18 | print "# define OpHelp(X) \"\\0\" X" |
| 19 | print "#else" |
| 20 | print "# define OpHelp(X)" |
| 21 | print "#endif" |
drh | 46c99e0 | 2007-08-27 23:26:59 +0000 | [diff] [blame] | 22 | print "const char *sqlite3OpcodeName(int i){" |
| 23 | print " static const char *const azName[] = { \"?\"," |
drh | 307ff30 | 2011-08-30 01:29:04 +0000 | [diff] [blame] | 24 | mx = 0 |
drh | b327f77 | 2004-10-06 15:03:57 +0000 | [diff] [blame] | 25 | } |
drh | 81316f8 | 2013-10-29 20:40:47 +0000 | [diff] [blame] | 26 | /^.define OP_/ { |
drh | b327f77 | 2004-10-06 15:03:57 +0000 | [diff] [blame] | 27 | sub("OP_","",$2) |
drh | 307ff30 | 2011-08-30 01:29:04 +0000 | [diff] [blame] | 28 | i = $3+0 |
| 29 | label[i] = $2 |
| 30 | if( mx<i ) mx = i |
drh | 81316f8 | 2013-10-29 20:40:47 +0000 | [diff] [blame] | 31 | for(j=5; j<NF; j++) if( $j=="synopsis:" ) break |
| 32 | if( j<NF ){ |
| 33 | j++ |
| 34 | x = $j |
| 35 | for(j=j+1; j<NF; j++) x = x " " $j |
| 36 | synopsis[i] = x |
| 37 | }else{ |
| 38 | synopsis[i] = "" |
| 39 | } |
drh | b327f77 | 2004-10-06 15:03:57 +0000 | [diff] [blame] | 40 | } |
| 41 | END { |
drh | 307ff30 | 2011-08-30 01:29:04 +0000 | [diff] [blame] | 42 | for(i=1; i<=mx; i++){ |
drh | 81316f8 | 2013-10-29 20:40:47 +0000 | [diff] [blame] | 43 | printf " /* %3d */ %-18s OpHelp(\"%s\"),\n", i, \ |
| 44 | "\"" label[i] "\"", synopsis[i] |
drh | 307ff30 | 2011-08-30 01:29:04 +0000 | [diff] [blame] | 45 | } |
drh | 46c99e0 | 2007-08-27 23:26:59 +0000 | [diff] [blame] | 46 | print " };" |
| 47 | print " return azName[i];" |
| 48 | print "}" |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 49 | print "#endif" |
drh | b327f77 | 2004-10-06 15:03:57 +0000 | [diff] [blame] | 50 | } |