Add error on misused define.

This commit is contained in:
Wilson Snyder 2020-01-11 09:16:26 -05:00
parent fe9cf9bd42
commit fe94f9891b
7 changed files with 51 additions and 0 deletions

View File

@ -5,6 +5,8 @@ The contributors that suggested a given feature are shown in []. Thanks!
* Verilator 4.027 devel
**** Add error on misused define. [Topa Tota]
* Verilator 4.026 2020-01-11

View File

@ -244,6 +244,11 @@ bom [\357\273\277]
// Note paren level 0 means before "(" of starting args
// Level 1 means "," between arguments
// Level 2+ means one inside the () of an argument
if (LEXP->m_parenLevel == 1) { // Starting (
if (!VString::isWhitespace(LEXP->m_defValue)) {
yyerrorf("Illegal text before '(' that starts define arguments");
}
}
if (LEXP->m_parenLevel>1) {
appendDefValue(yytext, yyleng); FL_BRK;
} else {

View File

@ -114,6 +114,13 @@ string VString::spaceUnprintable(const string& str) {
return out;
}
bool VString::isWhitespace(const string& str) {
for (string::const_iterator pos = str.begin(); pos != str.end(); ++pos) {
if (!isspace(*pos)) return false;
}
return true;
}
//######################################################################
// VHashSha256

View File

@ -74,6 +74,8 @@ public:
// Replace any unprintable with space
// This includes removing tabs, so column tracking is correct
static string spaceUnprintable(const string& str);
// Return true if only whitespace or ""
static bool isWhitespace(const string& str);
};
//######################################################################

View File

@ -0,0 +1,7 @@
%Error: t/t_pp_defparen_bad.v:9: Illegal text before '(' that starts define arguments
( 1,2)
^
%Error: t/t_pp_defparen_bad.v:9: syntax error, unexpected '('
((val 1) + (2))
^
%Error: Exiting due to

View File

@ -0,0 +1,19 @@
#!/usr/bin/perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2003 by Wilson Snyder. This program is free software; you can
# redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
scenarios(vlt => 1);
lint(
verilator_flags2 => ["-Wpedantic"],
fails => 1,
expect_filename => $Self->{golden_filename},
);
ok(1);
1;

View File

@ -0,0 +1,9 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2020 by Wilson Snyder.
`define test(a1,a2) ((a1) + (a2))
`test val
( 1,2)