From 8e4ddc62db448b613ae327792e72defca4d115d4 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Mon, 27 Mar 2017 15:50:32 -0700 Subject: Support Vec(0) fields in Bundles, just like Option[Data]; add test This also allows asUInt/asTypeOf to work properly on those Bundles, even though zero-width wire support is lacking. --- chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala | 1 + src/test/scala/chiselTests/Vec.scala | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala index d2953aa3..a561e7d5 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala @@ -499,6 +499,7 @@ class Bundle extends Record { * be one, otherwise returns None. */ private def getBundleField(m: java.lang.reflect.Method): Option[Data] = m.invoke(this) match { + case v: Vec[_] if v.isEmpty => None case d: Data => Some(d) case Some(d: Data) => Some(d) case _ => None diff --git a/src/test/scala/chiselTests/Vec.scala b/src/test/scala/chiselTests/Vec.scala index 80c4040d..438cf515 100644 --- a/src/test/scala/chiselTests/Vec.scala +++ b/src/test/scala/chiselTests/Vec.scala @@ -136,6 +136,14 @@ class OneBitUnitRegVecTester extends BasicTester { class ZeroEntryVecTester extends BasicTester { require(Vec(0, Bool()).getWidth == 0) + + val bundleWithZeroEntryVec = new Bundle { + val foo = Bool() + val bar = Vec(0, Bool()) + } + require(0.U.asTypeOf(bundleWithZeroEntryVec).getWidth == 1) + require(bundleWithZeroEntryVec.asUInt.getWidth == 1) + stop() } -- cgit v1.2.3