mirror of
https://github.com/verilator/verilator.git
synced 2025-04-05 12:12:39 +00:00
Improve hex too many digits error (#5419).
This commit is contained in:
parent
cdfb2221bb
commit
0ec5e02ce1
@ -247,15 +247,7 @@ void V3Number::create(const char* sourcep) {
|
||||
product.opMul(*this, ten);
|
||||
opAdd(product, addend);
|
||||
if (product.bitsValue(width(), 4)) { // Overflowed
|
||||
static int warned = 0;
|
||||
v3error("Too many digits for "
|
||||
<< width() << " bit number: " << sourcep << '\n'
|
||||
<< ((!sized() && !warned++) ? (
|
||||
V3Error::warnMore() + "... As that number was unsized"
|
||||
+ " ('d...) it is limited to 32 bits"
|
||||
" (IEEE 1800-2023 5.7.1)\n"
|
||||
+ V3Error::warnMore() + "... Suggest adding a size to it.")
|
||||
: ""));
|
||||
warnTooMany(sourcep);
|
||||
while (*(cp + 1)) cp++; // Skip ahead so don't get multiple warnings
|
||||
}
|
||||
}
|
||||
@ -291,7 +283,7 @@ void V3Number::create(const char* sourcep) {
|
||||
for (const char* cp = value_startp + std::strlen(value_startp) - 1; cp >= value_startp;
|
||||
cp--) {
|
||||
if (*cp != '_' && *cp != '0' && obit >= width()) {
|
||||
v3error("Too many digits for " << width() << " bit number: " << sourcep);
|
||||
warnTooMany(sourcep);
|
||||
break;
|
||||
}
|
||||
switch (std::tolower(base)) {
|
||||
@ -379,6 +371,18 @@ void V3Number::create(const char* sourcep) {
|
||||
// m_value[0]);
|
||||
}
|
||||
|
||||
void V3Number::warnTooMany(const string& value) {
|
||||
static int warned = 0;
|
||||
v3error("Too many digits for "
|
||||
<< width() << " bit number: '" << value << "'\n"
|
||||
<< ((!sized() && !warned++)
|
||||
? (V3Error::warnMore() + "... As that number was unsized"
|
||||
+ " ('...) it is limited to 32 bits"
|
||||
" (IEEE 1800-2023 5.7.1)\n"
|
||||
+ V3Error::warnMore() + "... Suggest adding a size to it.")
|
||||
: ""));
|
||||
}
|
||||
|
||||
void V3Number::nodep(AstNode* nodep) VL_MT_STABLE {
|
||||
m_nodep = nodep;
|
||||
if (!nodep) return;
|
||||
|
@ -558,6 +558,7 @@ private:
|
||||
string displayed(const string& vformat) const VL_MT_STABLE {
|
||||
return displayed(m_fileline, vformat);
|
||||
}
|
||||
void warnTooMany(const string& value);
|
||||
|
||||
public:
|
||||
void v3errorEnd(const std::ostringstream& sstr) const VL_RELEASE(V3Error::s().m_mutex);
|
||||
|
@ -1,16 +1,16 @@
|
||||
%Error: t/t_const_overflow_bad.v:9:34: Too many digits for 94 bit number: 94'd123456789012345678901234567890
|
||||
%Error: t/t_const_overflow_bad.v:9:34: Too many digits for 94 bit number: '94'd123456789012345678901234567890'
|
||||
9 | parameter [200:0] TOO_SMALL = 94'd123456789012345678901234567890;
|
||||
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
%Error: t/t_const_overflow_bad.v:11:31: Too many digits for 8 bit number: 8'habc
|
||||
%Error: t/t_const_overflow_bad.v:11:31: Too many digits for 8 bit number: '8'habc'
|
||||
11 | parameter [200:0] SMALLH = 8'habc;
|
||||
| ^~~~~~
|
||||
%Error: t/t_const_overflow_bad.v:12:31: Too many digits for 6 bit number: 6'o1234
|
||||
%Error: t/t_const_overflow_bad.v:12:31: Too many digits for 6 bit number: '6'o1234'
|
||||
12 | parameter [200:0] SMALLO = 6'o1234;
|
||||
| ^~~~~~~
|
||||
%Error: t/t_const_overflow_bad.v:13:31: Too many digits for 3 bit number: 3'b1111
|
||||
%Error: t/t_const_overflow_bad.v:13:31: Too many digits for 3 bit number: '3'b1111'
|
||||
13 | parameter [200:0] SMALLB = 3'b1111;
|
||||
| ^~~~~~~
|
||||
%Error: t/t_const_overflow_bad.v:19:35: Too many digits for 129 bit number: 129'hdeadbeefc001f00ddeadbeefc001f00ddeadbeefc001f00ddeadbeefc001f00d
|
||||
%Error: t/t_const_overflow_bad.v:19:35: Too many digits for 129 bit number: '129'hdeadbeefc001f00ddeadbeefc001f00ddeadbeefc001f00ddeadbeefc001f00d'
|
||||
19 | parameter [128:0] ALSO_SMALL = 129'hdeadbeefc001f00ddeadbeefc001f00ddeadbeefc001f00ddeadbeefc001f00d;
|
||||
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
%Error: Exiting due to
|
||||
|
@ -1,6 +1,18 @@
|
||||
%Error: t/t_lint_unsized_bad.v:8:22: Too many digits for 32 bit number: 'd123456789123456789123456789
|
||||
... As that number was unsized ('d...) it is limited to 32 bits (IEEE 1800-2023 5.7.1)
|
||||
%Error: t/t_lint_unsized_bad.v:8:22: Too many digits for 32 bit number: ''d123456789123456789123456789'
|
||||
... As that number was unsized ('...) it is limited to 32 bits (IEEE 1800-2023 5.7.1)
|
||||
... Suggest adding a size to it.
|
||||
8 | bit [256:0] num = 'd123456789123456789123456789;
|
||||
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
%Error: t/t_lint_unsized_bad.v:9:22: Too many digits for 32 bit number: ''h123456789123456789123456789'
|
||||
9 | bit [256:0] num = 'h123456789123456789123456789;
|
||||
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
%Error: t/t_lint_unsized_bad.v:10:22: Illegal character in octal constant
|
||||
10 | bit [256:0] num = 'o123456789123456789123456789;
|
||||
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
%Error: t/t_lint_unsized_bad.v:10:22: Too many digits for 32 bit number: ''o123456789123456789123456789'
|
||||
10 | bit [256:0] num = 'o123456789123456789123456789;
|
||||
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
%Error: t/t_lint_unsized_bad.v:11:22: Too many digits for 32 bit number: ''b10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010'
|
||||
11 | bit [256:0] num = 'b10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010;
|
||||
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
%Error: Exiting due to
|
||||
|
@ -6,4 +6,7 @@
|
||||
|
||||
module t;
|
||||
bit [256:0] num = 'd123456789123456789123456789;
|
||||
bit [256:0] num = 'h123456789123456789123456789;
|
||||
bit [256:0] num = 'o123456789123456789123456789;
|
||||
bit [256:0] num = 'b10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010;
|
||||
endmodule
|
||||
|
@ -16,7 +16,7 @@
|
||||
%Error: t/t_number_bad.v:17:33: Illegal character in binary constant: 4
|
||||
17 | parameter logic [3:0] FOO7 = 1'b1?4'hF:4'h1;
|
||||
| ^~~~~~
|
||||
%Error: t/t_number_bad.v:17:33: Too many digits for 1 bit number: 1'b1?4
|
||||
%Error: t/t_number_bad.v:17:33: Too many digits for 1 bit number: '1'b1?4'
|
||||
17 | parameter logic [3:0] FOO7 = 1'b1?4'hF:4'h1;
|
||||
| ^~~~~~
|
||||
%Error: t/t_number_bad.v:17:39: syntax error, unexpected INTEGER NUMBER, expecting ';'
|
||||
|
Loading…
Reference in New Issue
Block a user