From 07c493c796ad183c1727425e8fb59a6fb0e98394 Mon Sep 17 00:00:00 2001 From: Tim Edwards Date: Wed, 1 Jul 2020 14:28:00 -0400 Subject: [PATCH] Corrected the verilog parser's behavior with respect to string definitions: Now correctly parses everything from the definition name to the end of line as the definition value. Also: The search for definitions in the body of the text does not reject non-alphanumerics "_" and "$" in the definition name, without which definition names containing those characters will go unrecongized. Have not yet extended this to multi-line definition values. --- base/netfile.c | 19 +++++++++++++++++-- base/netfile.h | 1 + base/verilog.c | 11 +++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/base/netfile.c b/base/netfile.c index e6f13d8..77350a4 100644 --- a/base/netfile.c +++ b/base/netfile.c @@ -329,7 +329,7 @@ int GetNextLineNoNewline(char *delimiter) for (s = line; *s != '\0'; s++) { if (*s == '`') { w = s + 1; - while (isalnum(*w)) w++; + while (isalnum(*w) || (*w == '_') || (*w == '$')) w++; e = *w; *w = '\0'; kl = (struct property *)HashLookup(s + 1, definitions); @@ -365,7 +365,7 @@ int GetNextLineNoNewline(char *delimiter) for (s = line; *s != '\0'; s++) { if (*s == '`') { w = s + 1; - while (isalnum(*w)) w++; + while (isalnum(*w) || (*w == '_') || (*w == '$')) w++; e = *w; *w = '\0'; kl = (struct property *)HashLookup(s + 1, definitions); @@ -496,6 +496,21 @@ void GetNextLine(char *delimiter) } while (nexttok == NULL); } +/*----------------------------------------------------------------------*/ +/* Return a pointer to the line at the position of nexttok */ +/*----------------------------------------------------------------------*/ + +char *GetLineAtTok() +{ + char *lpos; + + if (nexttok == NULL) return NULL; + if (line == NULL) return NULL; + + lpos = strstr(line, nexttok); + return lpos; +} + /*----------------------------------------------------------------------*/ /* if nexttok is already NULL, force scanner to read new line */ /*----------------------------------------------------------------------*/ diff --git a/base/netfile.h b/base/netfile.h index 3fe7ffe..32e0437 100644 --- a/base/netfile.h +++ b/base/netfile.h @@ -31,6 +31,7 @@ extern struct hashdict *definitions; extern char *nexttok; #define SKIPTO(a) do {SkipTok(NULL);} while (!match(nexttok,a)) extern char *strdtok(char *pstring, char *delim1, char *delim2); +extern char *GetLineAtTok(); extern void SkipTok(char *delimiter); extern void SkipTokNoNewline(char *delimiter); extern void SkipTokComments(char *delimiter); diff --git a/base/verilog.c b/base/verilog.c index 0acce53..80a91d7 100644 --- a/base/verilog.c +++ b/base/verilog.c @@ -1115,10 +1115,17 @@ skip_endmodule: kl->slop.dval = 0.01; // One percent default } else { - /* Treat the parameter as a string */ + char *toks; + + /* Treat the parameter as a string; BUT pull everything to */ + /* EOL, not just the current token. */ + toks = GetLineAtTok(); + kl->type = PROP_STRING; - kl->pdefault.string = strsave(nexttok); + kl->pdefault.string = strsave(toks); kl->slop.dval = 0.0; + + SkipNewLine(VLOG_DELIMITERS); } if (kl) HashPtrInstall(kl->key, kl, &verilogdefs); }