Skip to content

Commit

Permalink
Fix assignment from 0-entry Vec: add test (#580)
Browse files Browse the repository at this point in the history
* Partially revert 8e4ddc6

It was an incomplete fix for handling Vec(0).

* Fix assignment from 0-entry Vec: add test

375e2b6 introduced a regression for bundles
containing zero-entry Vecs.  Until zero-width UInts are supported, the
zero-entry Vecs need to be flattened out before doing asUInt/asTypeOf on
a bundle.  Undoing that commit's replacement of Data.flatten with
Aggregate.getElements is the best interim fix.
  • Loading branch information
aswaterman committed Apr 15, 2017
1 parent da8dad1 commit bb12fe7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 2 additions & 3 deletions chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
Expand Up @@ -24,13 +24,13 @@ sealed abstract class Aggregate extends Data {
pushCommand(BulkConnect(sourceInfo, this.lref, that.lref))

override def do_asUInt(implicit sourceInfo: SourceInfo): UInt = {
SeqUtils.do_asUInt(getElements.map(_.asUInt()))
SeqUtils.do_asUInt(flatten.map(_.asUInt()))
}
private[core] override def connectFromBits(that: Bits)(implicit sourceInfo: SourceInfo,
compileOptions: CompileOptions): Unit = {
var i = 0
val bits = Wire(UInt(this.width), init=that) // handles width padding
for (x <- getElements) {
for (x <- flatten) {
x.connectFromBits(bits(i + x.getWidth - 1, i))
i += x.getWidth
}
Expand Down Expand Up @@ -501,7 +501,6 @@ 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
Expand Down
5 changes: 5 additions & 0 deletions src/test/scala/chiselTests/Vec.scala
Expand Up @@ -144,6 +144,11 @@ class ZeroEntryVecTester extends BasicTester {
require(0.U.asTypeOf(bundleWithZeroEntryVec).getWidth == 1)
require(bundleWithZeroEntryVec.asUInt.getWidth == 1)

val m = Module(new Module {
val io = IO(Output(bundleWithZeroEntryVec.cloneType))
})
Wire(init = m.io.bar)

stop()
}

Expand Down

0 comments on commit bb12fe7

Please sign in to comment.