summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala4
-rw-r--r--src/test/scala/chiselTests/Vec.scala40
2 files changed, 43 insertions, 1 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
index a561e7d5..be874042 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala
@@ -73,7 +73,9 @@ object Vec {
def doConnect(sink: T, source: T) = {
// TODO: this looks bad, and should feel bad. Replace with a better abstraction.
- val hasDirectioned = vec.sample_element match {
+ // NOTE: Must use elts.head instead of vec.sample_element because vec.sample_element has
+ // WireBinding which does not have a direction
+ val hasDirectioned = elts.head match {
case t: Aggregate => t.flatten.exists(_.dir != Direction.Unspecified)
case t: Element => t.dir != Direction.Unspecified
}
diff --git a/src/test/scala/chiselTests/Vec.scala b/src/test/scala/chiselTests/Vec.scala
index 438cf515..2ece7c88 100644
--- a/src/test/scala/chiselTests/Vec.scala
+++ b/src/test/scala/chiselTests/Vec.scala
@@ -147,6 +147,42 @@ class ZeroEntryVecTester extends BasicTester {
stop()
}
+class PassthroughModuleIO extends Bundle {
+ val in = Input(UInt(32.W))
+ val out = Output(UInt(32.W))
+}
+
+class PassthroughModule extends Module {
+ val io = IO(new PassthroughModuleIO)
+ io.out := io.in
+}
+
+class PassthroughModuleTester extends Module {
+ val io = IO(Flipped(new PassthroughModuleIO))
+ // This drives the input of a PassthroughModule
+ io.in := 123.U
+ assert(io.out === 123.U)
+}
+
+
+class ModuleIODynamicIndexTester(n: Int) extends BasicTester {
+ val duts = Vec.fill(n)(Module(new PassthroughModule).io)
+ val tester = Module(new PassthroughModuleTester)
+
+ val (cycle, done) = Counter(true.B, n)
+ for ((m, i) <- duts.zipWithIndex) {
+ when (cycle =/= i.U) {
+ m.in := 0.U // default
+ assert(m.out === 0.U)
+ }
+ }
+ // only connect one dut per cycle
+ duts(cycle) <> tester.io
+ assert(duts(cycle).out === 123.U)
+
+ when (done) { stop() }
+}
+
class VecSpec extends ChiselPropSpec {
// Disable shrinking on error.
implicit val noShrinkListVal = Shrink[List[Int]](_ => Stream.empty)
@@ -204,4 +240,8 @@ class VecSpec extends ChiselPropSpec {
property("A Vec with zero entries should compile and have zero width") {
assertTesterPasses{ new ZeroEntryVecTester }
}
+
+ property("Dynamic indexing of a Vec of Module IOs should work") {
+ assertTesterPasses{ new ModuleIODynamicIndexTester(4) }
+ }
}