aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorKevin Laeufer2022-12-15 17:09:14 -0500
committerGitHub2022-12-15 14:09:14 -0800
commit135739f0c7ef3f6404ba7115f77c7d7b913f6748 (patch)
tree5de3fb957eff020a10bd665ae411f63b8e2675ed /src/main
parent64ac2d2cb866f5c3e30544bb1087dd374b57fdcb (diff)
0-bit literals (#2544)
* allow for zero-width integer literals * CheckWidths: ensure that width is non-negative
Diffstat (limited to 'src/main')
-rw-r--r--src/main/scala/firrtl/passes/CheckWidths.scala8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/main/scala/firrtl/passes/CheckWidths.scala b/src/main/scala/firrtl/passes/CheckWidths.scala
index a9f44421..02d35740 100644
--- a/src/main/scala/firrtl/passes/CheckWidths.scala
+++ b/src/main/scala/firrtl/passes/CheckWidths.scala
@@ -121,9 +121,13 @@ object CheckWidths extends Pass {
// This is a leaf check of the "local" width-correctness of one expression node, so no recursion.
expr match {
case e @ UIntLiteral(v, w: IntWidth) if math.max(1, v.bitLength) > w.width =>
- errors.append(new WidthTooSmall(info, target.serialize, v))
+ if (w.width > 0 || (w.width == 0 && v != 0)) { // UInt<0>(0) is allowed
+ errors.append(new WidthTooSmall(info, target.serialize, v))
+ }
case e @ SIntLiteral(v, w: IntWidth) if v.bitLength + 1 > w.width =>
- errors.append(new WidthTooSmall(info, target.serialize, v))
+ if (w.width > 0 || (w.width == 0 && v != 0)) { // SInt<0>(0) is allowed
+ errors.append(new WidthTooSmall(info, target.serialize, v))
+ }
case e @ DoPrim(op, Seq(a, b), _, tpe) =>
(op, a.tpe, b.tpe) match {
case (Squeeze, IntervalType(Closed(la), Closed(ua), _), IntervalType(Closed(lb), Closed(ub), _))