1
0
rocket-chip/src/main/scala/util/HeterogeneousBag.scala
Wesley W. Terpstra 710a782145 HeterogenousBag: empty bags were being combined! (#956)
This lead to strange firrtl errors when you had two empty
HeterogeneousBags in the same Bundle.
2017-08-14 15:48:42 -07:00

20 lines
715 B
Scala

// See LICENSE.SiFive for license details.
package freechips.rocketchip.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]
// IndexedSeq has its own hashCode/equals that we must not use
override def hashCode: Int = super[Record].hashCode
override def equals(that: Any): Boolean = super[Record].equals(that)
}