summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests
diff options
context:
space:
mode:
authormergify[bot]2022-11-04 18:20:07 +0000
committerGitHub2022-11-04 18:20:07 +0000
commit4149157df6531d124483d992daf96cf4e62a0f0c (patch)
tree76b4e80517168c5d0704e24c097a3c176417a811 /src/test/scala/chiselTests
parent0750bc2f46d49c8fdfd0c07a2ac80c74311b3f15 (diff)
Add PartialDataView.supertype (backport #2826) (#2827)
* Add PartialDataView.supertype (#2826) This factory method makes it easy to create PartialDataViews from a Bundle type to its supertype. Because of the typing relationship, there is no need to provide a mapping between fields. The only thing necessary is to provide a function for constructing an instance of the supertype from an instance of the subtype. (cherry picked from commit 251d454a224e5a961438ba0ea41134d7da7a5992) # Conflicts: # core/src/main/scala/chisel3/experimental/dataview/package.scala # src/test/scala/chiselTests/experimental/DataView.scala * Resolve backport conflicts Co-authored-by: Jack Koenig <koenig@sifive.com>
Diffstat (limited to 'src/test/scala/chiselTests')
-rw-r--r--src/test/scala/chiselTests/experimental/DataView.scala22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/experimental/DataView.scala b/src/test/scala/chiselTests/experimental/DataView.scala
index ac8357f0..3673778b 100644
--- a/src/test/scala/chiselTests/experimental/DataView.scala
+++ b/src/test/scala/chiselTests/experimental/DataView.scala
@@ -177,6 +177,28 @@ class DataViewSpec extends ChiselFlatSpec {
chirrtl should include("fooOut.foo <= barIn.foo")
}
+ it should "be easy to make a PartialDataView viewing a Bundle as a Parent Bundle type" in {
+ class Foo(x: Int) extends Bundle {
+ val foo = UInt(x.W)
+ }
+ class Bar(val x: Int) extends Foo(x) {
+ val bar = UInt(x.W)
+ }
+ implicit val view = PartialDataView.supertype[Bar, Foo](b => new Foo(b.x))
+ class MyModule extends Module {
+ val fooIn = IO(Input(new Foo(8)))
+ val barOut = IO(Output(new Bar(8)))
+ barOut.viewAs[Foo] := fooIn
+
+ val barIn = IO(Input(new Bar(8)))
+ val fooOut = IO(Output(new Foo(8)))
+ fooOut := barIn.viewAs[Foo]
+ }
+ val chirrtl = ChiselStage.emitChirrtl(new MyModule)
+ chirrtl should include("barOut.foo <= fooIn.foo")
+ chirrtl should include("fooOut.foo <= barIn.foo")
+ }
+
it should "error if viewing a parent Bundle as a child Bundle type" in {
assertTypeError("""
class Foo extends Bundle {