Check for a negative repeat value.

This patch adds checks for a negative repeat value and prints
an error message under this condition.
This commit is contained in:
Cary R 2008-03-25 15:17:47 -07:00 committed by Stephen Williams
parent 7bc9742710
commit 8c1cca423d
4 changed files with 22 additions and 0 deletions

View File

@ -655,6 +655,14 @@ NetExpr* PEConcat::elaborate_expr(Design*des, NetScope*scope,
des->errors += 1;
}
if (rep->value().is_negative()) {
cerr << get_fileline() << ": error: Concatenation repeat "
<< "may not be negative (" << rep->value().as_long()
<< ")." << endl;
des->errors += 1;
return 0;
}
repeat = rep;
}

View File

@ -1578,6 +1578,14 @@ NetNet* PEConcat::elaborate_net(Design*des, NetScope*scope,
return 0;
}
if (erep->value().is_negative()) {
cerr << get_fileline() << ": error: Concatenation repeat "
<< "may not be negative (" << erep->value().as_long()
<< ")." << endl;
des->errors += 1;
return 0;
}
repeat = erep->value().as_ulong();
delete etmp;

View File

@ -429,6 +429,11 @@ bool verinum::is_zero() const
return true;
}
bool verinum::is_negative() const
{
return (bits_[nbits_-1] == V1) && has_sign();
}
verinum pad_to_width(const verinum&that, unsigned width)
{
if (that.len() >= width)

View File

@ -71,6 +71,7 @@ class verinum {
// A number is "defined" if there are no x or z bits in its value.
bool is_defined() const;
bool is_zero() const;
bool is_negative() const;
// A number is "a string" if its value came directly from
// an ASCII description instead of a number value.