From 2d0fbde8e7737d87b96629aec00c3b5a54672cc8 Mon Sep 17 00:00:00 2001 From: "Justin T. Gibbs" Date: Wed, 18 Jul 2001 21:03:32 +0000 Subject: [PATCH] Add support for parsing version strings out of assembler source files and outputing them in generated files. Fixed a few other scanner bugs that for some reason didn't show up until these modifications were made. MFC after: 10 days --- sys/dev/aic7xxx/aicasm/aicasm.c | 29 +++++++------ sys/dev/aic7xxx/aicasm/aicasm.h | 3 +- sys/dev/aic7xxx/aicasm/aicasm_gram.y | 48 +++++++++++++++++----- sys/dev/aic7xxx/aicasm/aicasm_scan.l | 57 ++++++++++++++++++++++---- sys/dev/aic7xxx/aicasm/aicasm_symbol.c | 10 +++-- 5 files changed, 111 insertions(+), 36 deletions(-) diff --git a/sys/dev/aic7xxx/aicasm/aicasm.c b/sys/dev/aic7xxx/aicasm/aicasm.c index 1402b3a76d06..dfb3ef76fac8 100644 --- a/sys/dev/aic7xxx/aicasm/aicasm.c +++ b/sys/dev/aic7xxx/aicasm/aicasm.c @@ -28,7 +28,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: //depot/src/aic7xxx/aicasm/aicasm.c#6 $ + * $Id: //depot/src/aic7xxx/aicasm/aicasm.c#8 $ * * $FreeBSD$ */ @@ -180,7 +180,8 @@ main(int argc, char *argv[]) includes_search_curdir = 0; for (include_dir = SLIST_FIRST(&search_path); include_dir != NULL; - include_dir = SLIST_NEXT(include_dir, links)) + include_dir = SLIST_NEXT(include_dir, + links)) /* * All entries before a '-I-' only * apply to includes specified with @@ -276,9 +277,9 @@ back_patch() { struct instruction *cur_instr; - for(cur_instr = STAILQ_FIRST(&seq_program); - cur_instr != NULL; - cur_instr = STAILQ_NEXT(cur_instr, links)) { + for (cur_instr = STAILQ_FIRST(&seq_program); + cur_instr != NULL; + cur_instr = STAILQ_NEXT(cur_instr, links)) { if (cur_instr->patch_label != NULL) { struct ins_format3 *f3_instr; u_int address; @@ -312,13 +313,15 @@ output_code() instrcount = 0; fprintf(ofile, "/* - * DO NOT EDIT - This file is automatically generated. - */\n"); + * DO NOT EDIT - This file is automatically generated + * from the following source files: + * +%s */\n", versions); fprintf(ofile, "static uint8_t seqprog[] = {\n"); - for(cur_instr = STAILQ_FIRST(&seq_program); - cur_instr != NULL; - cur_instr = STAILQ_NEXT(cur_instr, links)) { + for (cur_instr = STAILQ_FIRST(&seq_program); + cur_instr != NULL; + cur_instr = STAILQ_NEXT(cur_instr, links)) { fprintf(ofile, "%s\t0x%02x, 0x%02x, 0x%02x, 0x%02x", cur_instr == STAILQ_FIRST(&seq_program) ? "" : ",\n", @@ -340,9 +343,9 @@ output_code() /* * Output patch information. Patch functions first. */ - for(cur_node = SLIST_FIRST(&patch_functions); - cur_node != NULL; - cur_node = SLIST_NEXT(cur_node,links)) { + for (cur_node = SLIST_FIRST(&patch_functions); + cur_node != NULL; + cur_node = SLIST_NEXT(cur_node,links)) { fprintf(ofile, "static int ahc_patch%d_func(struct ahc_softc *ahc); diff --git a/sys/dev/aic7xxx/aicasm/aicasm.h b/sys/dev/aic7xxx/aicasm/aicasm.h index 692dc04faf70..361a9b227d26 100644 --- a/sys/dev/aic7xxx/aicasm/aicasm.h +++ b/sys/dev/aic7xxx/aicasm/aicasm.h @@ -28,7 +28,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: //depot/src/aic7xxx/aicasm/aicasm.h#4 $ + * $Id: //depot/src/aic7xxx/aicasm/aicasm.h#5 $ * * $FreeBSD$ */ @@ -69,6 +69,7 @@ extern int includes_search_curdir; /* False if we've seen -I- */ extern char *appname; extern int yylineno; extern char *yyfilename; +extern char *versions; void stop(const char *errstring, int err_code); void include_file(char *file_name, include_type type); diff --git a/sys/dev/aic7xxx/aicasm/aicasm_gram.y b/sys/dev/aic7xxx/aicasm/aicasm_gram.y index 91425f38c30a..f562e6ee41d9 100644 --- a/sys/dev/aic7xxx/aicasm/aicasm_gram.y +++ b/sys/dev/aic7xxx/aicasm/aicasm_gram.y @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: //depot/src/aic7xxx/aicasm/aicasm_gram.y#6 $ + * $Id: //depot/src/aic7xxx/aicasm/aicasm_gram.y#7 $ * * $FreeBSD$ */ @@ -53,6 +53,7 @@ int yylineno; char *yyfilename; +char *versions; static symbol_t *cur_symbol; static symtype cur_symtype; static symbol_t *accumulator; @@ -79,6 +80,7 @@ static void test_writable_symbol(symbol_t *symbol); static void type_check(symbol_t *symbol, expression_t *expression, int and_op); static void make_expression(expression_t *immed, int value); static void add_conditional(symbol_t *symbol); +static void add_version(const char *verstring); static int is_download_const(expression_t *immed); #define YYDEBUG 1 @@ -124,11 +126,11 @@ static int is_download_const(expression_t *immed); %token T_NUMBER -%token T_PATH +%token T_PATH T_STRING %token T_CEXPR -%token T_EOF T_INCLUDE +%token T_EOF T_INCLUDE T_VERSION %token T_SHR T_SHL T_ROR T_ROL @@ -180,6 +182,8 @@ static int is_download_const(expression_t *immed); program: include | program include +| version +| program version | register | program register | constant @@ -202,9 +206,18 @@ program: include: T_INCLUDE '<' T_PATH '>' - { include_file($3, BRACKETED_INCLUDE); } + { + include_file($3, BRACKETED_INCLUDE); + } | T_INCLUDE '"' T_PATH '"' - { include_file($3, QUOTED_INCLUDE); } + { + include_file($3, QUOTED_INCLUDE); + } +; + +version: + T_VERSION '=' T_STRING + { add_version($3); } ; register: @@ -623,11 +636,6 @@ immediate_or_a: expression { $$ = $1; - if ($$.value == 0) { - stop("Immediate value of 0 not valid for opcode", - EX_DATAERR); - /* NOTREACHED */ - } } | T_A { @@ -1443,6 +1451,26 @@ add_conditional(symbol_t *symbol) symlist_add(&patch_functions, symbol, SYMLIST_INSERT_HEAD); } +static void +add_version(const char *verstring) +{ + const char prefix[] = " * "; + int newlen; + int oldlen; + + newlen = strlen(verstring) + strlen(prefix); + oldlen = 0; + if (versions != NULL) + oldlen = strlen(versions); + versions = realloc(versions, newlen + oldlen + 2); + if (versions == NULL) + stop("Can't allocate version string", EX_SOFTWARE); + strcpy(&versions[oldlen], prefix); + strcpy(&versions[oldlen + strlen(prefix)], verstring); + versions[newlen + oldlen] = '\n'; + versions[newlen + oldlen + 1] = '\0'; +} + void yyerror(const char *string) { diff --git a/sys/dev/aic7xxx/aicasm/aicasm_scan.l b/sys/dev/aic7xxx/aicasm/aicasm_scan.l index 7bfe505846f1..1ec85ed85cf9 100644 --- a/sys/dev/aic7xxx/aicasm/aicasm_scan.l +++ b/sys/dev/aic7xxx/aicasm/aicasm_scan.l @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: //depot/src/aic7xxx/aicasm/aicasm_scan.l#4 $ + * $Id: //depot/src/aic7xxx/aicasm/aicasm_scan.l#5 $ * * $FreeBSD$ */ @@ -54,6 +54,7 @@ char string_buf[MAX_STR_CONST]; char *string_buf_ptr; int parren_count; +int quote_count; %} PATH [-/A-Za-z0-9_.]*[./][-/A-Za-z0-9_.]* @@ -63,6 +64,7 @@ SPACE [ \t]+ %x COMMENT %x CEXPR %x INCLUDE +%x STRING %% \n { ++yylineno; } @@ -94,8 +96,9 @@ if[ \t]*\( { } \n { ++yylineno; } [^()\n]+ { - char *yptr = yytext; + char *yptr; + yptr = yytext; while (*yptr != '\0') { /* Remove duplicate spaces */ if (*yptr == '\t') @@ -109,6 +112,25 @@ if[ \t]*\( { } } +VERSION { return T_VERSION; } +\" { + string_buf_ptr = string_buf; + BEGIN STRING; + } +[^"]+ { + char *yptr; + + yptr = yytext; + while (*yptr) + *string_buf_ptr++ = *yptr++; + } +\" { + /* All done */ + BEGIN INITIAL; + *string_buf_ptr = '\0'; + yylval.str = string_buf; + return T_STRING; + } {SPACE} ; /* Register/SCB/SRAM definition keywords */ @@ -175,7 +197,7 @@ nop { return T_NOP; } else { return T_ELSE; } /* Allowed Symbols */ -[-+,:()~|&."{};<>[\]!] { return yytext[0]; } +[-+,:()~|&."{};<>[\]!=] { return yytext[0]; } /* Number processing */ 0[0-7]* { @@ -194,17 +216,36 @@ else { return T_ELSE; } } /* Include Files */ -#include { return T_INCLUDE; BEGIN INCLUDE;} -[<>\"] { return yytext[0]; } -{PATH} { yylval.str = strdup(yytext); return T_PATH; } -; { BEGIN INITIAL; return yytext[0]; } +#include{SPACE} { + BEGIN INCLUDE; + quote_count = 0; + return T_INCLUDE; + } +[<] { return yytext[0]; } +[>] { BEGIN INITIAL; return yytext[0]; } +[\"] { + if (quote_count != 0) + BEGIN INITIAL; + quote_count++; + return yytext[0]; + } . { stop("Invalid include line", EX_DATAERR); } /* For parsing C include files with #define foo */ #define { yylval.value = TRUE; return T_CONST; } /* Throw away macros */ #define[^\n]*[()]+[^\n]* ; -{PATH} { yylval.str = strdup(yytext); return T_PATH; } +{PATH} { + char *yptr; + + yptr = yytext; + string_buf_ptr = string_buf; + while (*yptr) + *string_buf_ptr++ = *yptr++; + yylval.str = string_buf; + *string_buf_ptr = '\0'; + return T_PATH; + } {WORD} { yylval.sym = symtable_get(yytext); return T_SYMBOL; } diff --git a/sys/dev/aic7xxx/aicasm/aicasm_symbol.c b/sys/dev/aic7xxx/aicasm/aicasm_symbol.c index 974c8c4825c8..e0af1a8183be 100644 --- a/sys/dev/aic7xxx/aicasm/aicasm_symbol.c +++ b/sys/dev/aic7xxx/aicasm/aicasm_symbol.c @@ -28,7 +28,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: //depot/src/aic7xxx/aicasm/aicasm_symbol.c#4 $ + * $Id: //depot/src/aic7xxx/aicasm/aicasm_symbol.c#7 $ * * $FreeBSD$ */ @@ -36,7 +36,7 @@ #include #ifdef __linux__ -#include +#include "aicdb.h" #else #include #endif @@ -389,8 +389,10 @@ symtable_dump(FILE *ofile) /* Output what we have */ fprintf(ofile, "/* - * DO NOT EDIT - This file is automatically generated. - */\n"); + * DO NOT EDIT - This file is automatically generated + * from the following source files: + * +%s */\n", versions); while (SLIST_FIRST(®isters) != NULL) { symbol_node_t *curnode; u_int8_t value;