From 3cc6e74e38a4c50b7ea049fe657efcefa63ad512 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Mon, 30 Sep 2019 13:14:40 -0700 Subject: [PATCH] Have $readmem() print a warning if there are too many digits in words. If there are more digits than needed to fill a word, print a warning message. The excess bits are thrown away, so there is no need for an error. --- vpi/sys_readmem.c | 6 ++--- vpi/sys_readmem_lex.h | 4 ++-- vpi/sys_readmem_lex.lex | 52 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/vpi/sys_readmem.c b/vpi/sys_readmem.c index 0922214cf..4d4f37b9a 100644 --- a/vpi/sys_readmem.c +++ b/vpi/sys_readmem.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2018 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2019 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -332,9 +332,9 @@ static PLI_INT32 sys_readmem_calltf(ICARUS_VPI_CONST PLI_BYTE8*name) /* Configure the readmem lexer */ if (strcmp(name,"$readmemb") == 0) - sys_readmem_start_file(file, 1, wwid, value.value.vector); + sys_readmem_start_file(callh, file, 1, wwid, value.value.vector); else - sys_readmem_start_file(file, 0, wwid, value.value.vector); + sys_readmem_start_file(callh, file, 0, wwid, value.value.vector); /*======================================== Read memory file */ diff --git a/vpi/sys_readmem_lex.h b/vpi/sys_readmem_lex.h index 6531b8f1c..35b0c8f8c 100644 --- a/vpi/sys_readmem_lex.h +++ b/vpi/sys_readmem_lex.h @@ -1,7 +1,7 @@ #ifndef IVL_sys_readmem_lex_H #define IVL_sys_readmem_lex_H /* - * Copyright (c) 1999-2014 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2014,2019 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -28,7 +28,7 @@ extern char *readmem_error_token; -extern void sys_readmem_start_file(FILE*in, int bin_flag, +extern void sys_readmem_start_file(vpiHandle callh, FILE*in, int bin_flag, unsigned width, struct t_vpi_vecval*val); extern int readmemlex(void); diff --git a/vpi/sys_readmem_lex.lex b/vpi/sys_readmem_lex.lex index c7f4c53ef..9640d0c7a 100644 --- a/vpi/sys_readmem_lex.lex +++ b/vpi/sys_readmem_lex.lex @@ -4,7 +4,7 @@ %{ /* - * Copyright (c) 1999-2017 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2017,2019 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -57,6 +57,12 @@ char *readmem_error_token = 0; . { readmem_error_token = yytext; return MEM_ERROR; } %% + /* The call_handle is the handle for the call to the $readmem() + system task. This is used for adding line numbers to warnings and + error messages. */ +static vpiHandle call_handle = 0; +static int too_many_digits_warning = 0; + static unsigned word_width = 0; static struct t_vpi_vecval*vecval = 0; @@ -134,6 +140,26 @@ static void make_hex_value(void) word_max -= 32; } } + + /* If there are more text digits then needed to fill the + memory word, count those digits and print a warning + message. Print that warning only once per call to + $readmemh() so that the user isn't flooded. */ + int count_extra_digits = 0; + while (end > beg) { + end -= 1; + if (*end == '_') continue; + count_extra_digits += 1; + } + + if (count_extra_digits && too_many_digits_warning==0) { + vpi_printf("WARNING: %s:%d: Excess hex digits (%d of '%s') while reading %d-bit words.\n", + vpi_get_str(vpiFile, call_handle), + vpi_get(vpiLineNo, call_handle), + count_extra_digits, beg, + word_width); + too_many_digits_warning += 1; + } } static void make_bin_value(void) @@ -181,11 +207,33 @@ static void make_bin_value(void) word_max -= 32; } } + + /* If there are more text digits then needed to fill the + memory word, count those digits and print a warning + message. Print that warning only once per call to + $readmem() so that the user isn't flooded. */ + int count_extra_digits = 0; + while (end > beg) { + end -= 1; + if (*end == '_') continue; + count_extra_digits += 1; + } + + if (count_extra_digits && too_many_digits_warning==0) { + vpi_printf("WARNING: %s:%d: Excess binary digits (%d of '%s') while reading %d-bit words.\n", + vpi_get_str(vpiFile, call_handle), + vpi_get(vpiLineNo, call_handle), + count_extra_digits, beg, + word_width); + too_many_digits_warning += 1; + } } -void sys_readmem_start_file(FILE*in, int bin_flag, +void sys_readmem_start_file(vpiHandle callh, FILE*in, int bin_flag, unsigned width, struct t_vpi_vecval *vv) { + call_handle = callh; + too_many_digits_warning = 0; yyrestart(in); BEGIN(bin_flag? BIN : HEX); word_width = width;