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
This commit is contained in:
parent
7063595315
commit
2d0fbde8e7
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=79873
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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 <value> T_NUMBER
|
||||
|
||||
%token <str> T_PATH
|
||||
%token <str> T_PATH T_STRING
|
||||
|
||||
%token <sym> T_CEXPR
|
||||
|
||||
%token T_EOF T_INCLUDE
|
||||
%token T_EOF T_INCLUDE T_VERSION
|
||||
|
||||
%token <value> 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)
|
||||
{
|
||||
|
@ -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]*\( {
|
||||
}
|
||||
<CEXPR>\n { ++yylineno; }
|
||||
<CEXPR>[^()\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;
|
||||
}
|
||||
<STRING>[^"]+ {
|
||||
char *yptr;
|
||||
|
||||
yptr = yytext;
|
||||
while (*yptr)
|
||||
*string_buf_ptr++ = *yptr++;
|
||||
}
|
||||
<STRING>\" {
|
||||
/* 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;}
|
||||
<INCLUDE>[<>\"] { return yytext[0]; }
|
||||
<INCLUDE>{PATH} { yylval.str = strdup(yytext); return T_PATH; }
|
||||
<INCLUDE>; { BEGIN INITIAL; return yytext[0]; }
|
||||
#include{SPACE} {
|
||||
BEGIN INCLUDE;
|
||||
quote_count = 0;
|
||||
return T_INCLUDE;
|
||||
}
|
||||
<INCLUDE>[<] { return yytext[0]; }
|
||||
<INCLUDE>[>] { BEGIN INITIAL; return yytext[0]; }
|
||||
<INCLUDE>[\"] {
|
||||
if (quote_count != 0)
|
||||
BEGIN INITIAL;
|
||||
quote_count++;
|
||||
return yytext[0];
|
||||
}
|
||||
<INCLUDE>. { 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; }
|
||||
<INITIAL,INCLUDE>{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; }
|
||||
|
||||
|
@ -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 <sys/types.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <db1/db.h>
|
||||
#include "aicdb.h"
|
||||
#else
|
||||
#include <db.h>
|
||||
#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;
|
||||
|
Loading…
Reference in New Issue
Block a user