Skip to content

Commit

Permalink
Implement varargs MixedVec API
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardcwang committed Aug 22, 2018
1 parent 7fb304f commit bedf5eb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/scala/chisel3/util/MixedVec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ object MixedVecInit {
}
hetVecWire
}

/**
* Construct a new wire with the given bound values.
* This is analogous to [[chisel3.core.VecInit]].
* @return MixedVec with given values assigned
*/
def apply[T <: Data](val0: T, vals: T*): MixedVec[T] = apply(val0 +: vals.toSeq)
}

object MixedVec {
Expand All @@ -34,6 +41,19 @@ object MixedVec {
*/
def apply[T <: Data](eltsIn: Seq[T]): MixedVec[T] = new MixedVec(eltsIn)

/**
* Create a MixedVec from that holds the given types.
* The types passed to this constructor must be Chisel types.
* @return MixedVec with the given types.
*/
def apply[T <: Data](val0: T, vals: T*): MixedVec[T] = new MixedVec(val0 +: vals.toSeq)

/**
* Create a new MixedVec from an unbound MixedVec type.
* @return MixedVec with the given types.
*/
def apply[T <: Data](mixedVec: MixedVec[T]): MixedVec[T] = new MixedVec(mixedVec.elts)

/**
* Create a MixedVec from the type of the given Vec.
* For example, given a Vec(2, UInt(8.W)), this creates MixedVec(Seq.fill(2){UInt(8.W)}).
Expand Down
19 changes: 19 additions & 0 deletions src/test/scala/chiselTests/MixedVecSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,25 @@ class MixedVecSpec extends ChiselPropSpec {
implicit val noShrinkListVal = Shrink[List[Int]](_ => Stream.empty)
implicit val noShrinkInt = Shrink[Int](_ => Stream.empty)

property("MixedVec varargs API should work") {
assertTesterPasses {
new BasicTester {
val wire = Wire(MixedVec(UInt(1.W), UInt(8.W)))
wire(0) := 1.U
wire(1) := 101.U

chisel3.assert(wire(0) === 1.U)
chisel3.assert(wire(1) + 1.U === 102.U)

val wireInit = MixedVecInit(1.U, 101.U)
chisel3.assert(wireInit(0) === 1.U)
chisel3.assert(wireInit(1) + 1.U === 102.U)

stop()
}
}
}

property("MixedVecs should be assignable") {
forAll(safeUIntN(8)) { case (w: Int, v: List[Int]) =>
assertTesterPasses {
Expand Down

0 comments on commit bedf5eb

Please sign in to comment.