diff --git a/jtag/ChangeLog b/jtag/ChangeLog index d33c8a70..5107b223 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,13 @@ +2008-05-26 Arnim Laeuger + + [adding svf progress output] (Steve Franks) + * src/svf/svf_bison.y (svf_bison_init): hand down parameters for scanner + initialization + * src/svf/svf_flex.l: output progress indicator upon newline detection + * src/svf/svf.c (svf_run): caluclate number of lines and pass result + to scanner initialization + * src/svf/svf.h: added "extra" data type for scanner + 2008-05-26 Kolja Waschk * src/bus/avr32.c, src/bus/buses.c, src/bus/buses.h, diff --git a/jtag/src/svf/svf.c b/jtag/src/svf/svf.c index 6c4a7061..53d2b1a4 100644 --- a/jtag/src/svf/svf.c +++ b/jtag/src/svf/svf.c @@ -1019,6 +1019,22 @@ svf_run(chain_t *chain, FILE *SVF_FILE, int stop_on_mismatch) const sxr_t sxr_default = { {0.0, NULL, NULL, NULL, NULL}, 1, 1}; parser_priv_t priv; + int c = ~EOF; + int num_lines; + + /* get number of lines in svf file so we can give user some feedback on long + files or slow cables */ + rewind( SVF_FILE ); + num_lines = 0; + while (EOF != c) { + c = fgetc( SVF_FILE ); + if ('\n' == c) + num_lines++; + } + rewind( SVF_FILE ); + if (0 == num_lines) + /* avoid those annoying divide/0 crashes */ + num_lines++; /* initialize - part @@ -1101,7 +1117,7 @@ svf_run(chain_t *chain, FILE *SVF_FILE, int stop_on_mismatch) /* select SIR instruction */ part_set_instruction(priv.part, "SIR"); - if (svf_bison_init(&priv, SVF_FILE)) { + if (svf_bison_init(&priv, SVF_FILE, num_lines, 0)) { svfparse(&priv, chain); svf_bison_deinit(&priv); } diff --git a/jtag/src/svf/svf.h b/jtag/src/svf/svf.h index e429e215..8d8970eb 100644 --- a/jtag/src/svf/svf.h +++ b/jtag/src/svf/svf.h @@ -102,12 +102,18 @@ struct parser_priv { }; typedef struct parser_priv parser_priv_t; +struct scanner_extra { + int num_lines; + int print_progress; +}; +typedef struct scanner_extra scanner_extra_t; + struct YYLTYPE; -void *svf_flex_init(FILE *); +void *svf_flex_init(FILE *, int, int); void svf_flex_deinit(void *); -int svf_bison_init(parser_priv_t *, FILE *); +int svf_bison_init(parser_priv_t *, FILE *, int, int); void svf_bison_deinit(parser_priv_t *); void svf_endxr(parser_priv_t *, enum generic_irdr_coding, int); diff --git a/jtag/src/svf/svf_bison.y b/jtag/src/svf/svf_bison.y index b27cb994..b4cfa843 100644 --- a/jtag/src/svf/svf_bison.y +++ b/jtag/src/svf/svf_bison.y @@ -437,7 +437,7 @@ svf_free_ths_params(struct ths_params *params) int -svf_bison_init(parser_priv_t *priv_data, FILE *f) +svf_bison_init(parser_priv_t *priv_data, FILE *f, int num_lines, int print_progress) { const struct svf_parser_params params = { {0.0, NULL, NULL, NULL, NULL}, @@ -447,7 +447,7 @@ svf_bison_init(parser_priv_t *priv_data, FILE *f) priv_data->parser_params = params; - if ((priv_data->scanner = svf_flex_init(f)) == NULL) + if ((priv_data->scanner = svf_flex_init(f, num_lines, print_progress)) == NULL) return 0; else return 1; diff --git a/jtag/src/svf/svf_flex.l b/jtag/src/svf/svf_flex.l index 1954393e..740f4f15 100644 --- a/jtag/src/svf/svf_flex.l +++ b/jtag/src/svf/svf_flex.l @@ -38,21 +38,23 @@ #include "svf.h" #include "svf_bison.h" +#define YY_EXTRA_TYPE scanner_extra_t * + static int map_keyw_ident(YYSTYPE *, char *); static void align_string(char *); static void fix_yylloc(YYLTYPE *, char *); -static void fix_yylloc_nl(YYLTYPE *, char *); -#define FIX_YYLLOC(lloc, text) fix_yylloc(lloc, text); -#define FIX_YYLLOC_NL(lloc, text) fix_yylloc_nl(lloc, text); +static void fix_yylloc_nl(YYLTYPE *, char *, YY_EXTRA_TYPE); int yywrap(yyscan_t scanner) { return(1); } -#define YY_USER_INIT do { yylloc->first_line = yylloc->last_line = yylloc->first_column = yylloc->last_column = 0; } while (0) - +#define YY_USER_INIT { \ + yylloc->first_line = yylloc->last_line = yylloc->first_column = yylloc->last_column = 0; \ +} + %} %pointer @@ -72,7 +74,7 @@ COMMENT (!.*)|("//".*)[^\n] /* token is a keyword or identifier */ int keyw; - FIX_YYLLOC(yylloc, yytext); + fix_yylloc(yylloc, yytext); keyw = map_keyw_ident(yylval, yytext); /* enable detection of VECTOR_STRING when this is a PIO command */ @@ -88,7 +90,7 @@ COMMENT (!.*)|("//".*)[^\n] /* token is a real number */ yylval->dvalue = strtod(yytext, (char **) NULL); - FIX_YYLLOC(yylloc, yytext); + fix_yylloc(yylloc, yytext); return(NUMBER); } /* end of real number */ @@ -103,7 +105,7 @@ COMMENT (!.*)|("//".*)[^\n] /* token is a vector string */ char *cstring; - FIX_YYLLOC_NL(yylloc, yytext); + fix_yylloc_nl(yylloc, yytext, yyget_extra(yyscanner)); align_string(yytext); cstring = calloc(strlen(yytext) + 1, sizeof(char)); @@ -117,7 +119,7 @@ COMMENT (!.*)|("//".*)[^\n] /* token is a hexadecimal value (2) */ char *cstring; - FIX_YYLLOC_NL(yylloc, yytext); + fix_yylloc_nl(yylloc, yytext, yyget_extra(yyscanner)); align_string(yytext); cstring = calloc(strlen(yytext) + 1, sizeof(char)); @@ -129,19 +131,19 @@ COMMENT (!.*)|("//".*)[^\n] {WSPACE}+ { /* token is a white space character */ - FIX_YYLLOC(yylloc, yytext); + fix_yylloc(yylloc, yytext); } /* end of white space */ {COMMENT} { /* token is a comment */ - FIX_YYLLOC(yylloc, yytext); + fix_yylloc(yylloc, yytext); } /* end of comment */ [()] { /* left or right parenthes */ - FIX_YYLLOC(yylloc, yytext); + fix_yylloc(yylloc, yytext); return(yytext[0]); } /* end of left or right parenthesis */ @@ -161,7 +163,7 @@ COMMENT (!.*)|("//".*)[^\n] /* release expect_vector */ BEGIN(INITIAL); - FIX_YYLLOC(yylloc, yytext); + fix_yylloc(yylloc, yytext); return(yytext[0]); } /* end of statement character */ @@ -293,7 +295,7 @@ fix_yylloc(YYLTYPE * mylloc, char *str) static void -fix_yylloc_nl(YYLTYPE * mylloc, char *str) +fix_yylloc_nl(YYLTYPE * mylloc, char *str, YY_EXTRA_TYPE extra) { char *p; @@ -303,6 +305,8 @@ fix_yylloc_nl(YYLTYPE * mylloc, char *str) if (*p == '\n') { mylloc->last_column = 0; ++mylloc->last_line; + if (extra->print_progress) + printf( _("\rParsing (%3.0d%%)"), ((mylloc->last_line * 100) + 1) / extra->num_lines); } else { ++mylloc->last_column; } @@ -310,8 +314,9 @@ fix_yylloc_nl(YYLTYPE * mylloc, char *str) } -void *svf_flex_init(FILE *f) +void *svf_flex_init(FILE *f, int num_lines, int print_progress) { + YY_EXTRA_TYPE extra; yyscan_t scanner; /* get our scanner structure */ @@ -320,11 +325,26 @@ void *svf_flex_init(FILE *f) yyset_in(f, scanner); + if (!(extra = (scanner_extra_t *)malloc(sizeof(scanner_extra_t)))) { + printf( _("Out of memory, %s line %i\n"), __FILE__, __LINE__ ); + yylex_destroy(scanner); + return NULL; + } + + extra->num_lines = num_lines; + extra->print_progress = print_progress; + + yyset_extra(extra, scanner); + return scanner; } void svf_flex_deinit(void *scanner) { + YY_EXTRA_TYPE extra = yyget_extra(scanner); + if (extra->print_progress) + printf("\n"); + free(extra); yylex_destroy(scanner); }