2017-07-07 19:48:16 +02:00
|
|
|
// See LICENSE.SiFive for license details.
|
|
|
|
|
|
|
|
package freechips.rocketchip.util
|
2017-02-04 01:21:33 +01:00
|
|
|
|
|
|
|
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) }:_*)
|
2018-03-02 00:19:12 +01:00
|
|
|
override def cloneType: this.type = (new HeterogeneousBag(elts.map(_.chiselCloneType))).asInstanceOf[this.type]
|
2017-08-15 00:48:42 +02:00
|
|
|
|
|
|
|
// 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)
|
2017-02-04 01:21:33 +01:00
|
|
|
}
|
2017-09-15 23:44:07 +02:00
|
|
|
|
|
|
|
object HeterogeneousBag
|
|
|
|
{
|
|
|
|
def fromNode[D <: Data, E](elts: Seq[(D, E)]) = new HeterogeneousBag(elts.map(_._1.cloneType))
|
|
|
|
}
|