From fc9ea62d38ac49813975e494cf5a376a08011b2e Mon Sep 17 00:00:00 2001 From: "Wesley W. Terpstra" Date: Fri, 3 Feb 2017 16:21:33 -0800 Subject: [PATCH] HeterogeneousBag: a handy container for differently parameterized bundles --- src/main/scala/util/HeterogeneousBag.scala | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/main/scala/util/HeterogeneousBag.scala diff --git a/src/main/scala/util/HeterogeneousBag.scala b/src/main/scala/util/HeterogeneousBag.scala new file mode 100644 index 00000000..1aaff08d --- /dev/null +++ b/src/main/scala/util/HeterogeneousBag.scala @@ -0,0 +1,13 @@ +package util + +import Chisel._ +import chisel3.core.Record +import scala.collection.immutable.ListMap + +final case class HeterogeneousBag[T <: Data](elts: Seq[T]) extends Record with collection.IndexedSeq[T] { + def apply(x: Int) = elts(x) + def length = elts.length + + val elements = ListMap(elts.zipWithIndex.map { case (n,i) => (i.toString, n) }:_*) + override def cloneType: this.type = (new HeterogeneousBag(elts.map(_.cloneType))).asInstanceOf[this.type] +}