Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Commit

Permalink
Support Bundle literal peek
Browse files Browse the repository at this point in the history
  • Loading branch information
ducky64 committed Nov 14, 2019
1 parent b6ea7e9 commit 454cd8a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/main/scala/chisel3/tester/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package chisel3
import scala.language.implicitConversions
import chisel3.tester.internal._
import chisel3.experimental.{DataMirror, Direction, FixedPoint}
import chisel3.experimental.BundleLiterals._
import chisel3.util._

class NotLiteralException(message: String) extends Exception(message)
Expand Down Expand Up @@ -61,6 +62,12 @@ package object tester {
val multiplier = math.pow(2, x.binaryPoint.get)
(Context().backend.peekBits(x, stale).toDouble / multiplier).F(x.binaryPoint).asInstanceOf[T]
}
case (x: Bundle) => {
val elementValueFns = x.elements.map { case (name: String, elt: Data) =>
(y: Bundle) => (y.elements(name), elt.peekWithStale(stale))
}.toSeq
chiselTypeOf(x).Lit(elementValueFns: _*).asInstanceOf[T]
}
case x => throw new LiteralTypeException(s"don't know how to peek $x")
}

Expand Down
19 changes: 11 additions & 8 deletions src/test/scala/chisel3/tests/BundleLiteralsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,20 @@ class BundleLiteralsSpec extends FlatSpec with ChiselScalatestTester with Matche
}
}

// peek on bundle not supported yet, this test will fail and should
// be altered when BundleLiteral peeking works
// it is not altogether what the use case is for peeking a bundle
// possibly to poke that value somewhere else
// this should be considered when peeking Bundles is supported
ignore should "return a BundleLiteral when peeking" in {
it should "return a Bundle literal when peeking" in {
test(new PassthroughModule(new DoubleElements)) { c =>
c.in.poke(chiselTypeOf(c.in).Lit(_.a -> 0.U, _.b -> 1.U))
val output = c.out.peek()
output.a === 0.U should be(true.B)
output.a === 1.U should be(true.B)
output.a.litValue should be (0)
output.b.litValue should be (1)
}
}

it should "roundtrip Bundle literals" in {
test(new PassthroughModule(new DoubleElements)) { c =>
c.in.poke(chiselTypeOf(c.in).Lit(_.a -> 0.U, _.b -> 1.U))
c.in.poke(c.out.peek())
c.out.expect(chiselTypeOf(c.in).Lit(_.a -> 0.U, _.b -> 1.U))
}
}
}

0 comments on commit 454cd8a

Please sign in to comment.