summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/experimental/hierarchy/InstanceSpec.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/scala/chiselTests/experimental/hierarchy/InstanceSpec.scala')
-rw-r--r--src/test/scala/chiselTests/experimental/hierarchy/InstanceSpec.scala91
1 files changed, 90 insertions, 1 deletions
diff --git a/src/test/scala/chiselTests/experimental/hierarchy/InstanceSpec.scala b/src/test/scala/chiselTests/experimental/hierarchy/InstanceSpec.scala
index 45d1f85f..8d8f7ea5 100644
--- a/src/test/scala/chiselTests/experimental/hierarchy/InstanceSpec.scala
+++ b/src/test/scala/chiselTests/experimental/hierarchy/InstanceSpec.scala
@@ -43,6 +43,29 @@ class InstanceSpec extends ChiselFunSpec with Utils {
val (chirrtl, _) = getFirrtlAndAnnos(new Top)
chirrtl.serialize should include("inst i0 of AddOne")
}
+ it("0.3: BlackBoxes should be supported") {
+ class Top extends Module {
+ val in = IO(Input(UInt(32.W)))
+ val out = IO(Output(UInt(32.W)))
+ val io = IO(new Bundle {
+ val in = Input(UInt(32.W))
+ val out = Output(UInt(32.W))
+ })
+ val definition = Definition(new AddOneBlackBox)
+ val i0 = Instance(definition)
+ val i1 = Instance(definition)
+ i0.io.in := in
+ out := i0.io.out
+ io <> i1.io
+ }
+ val chirrtl = getFirrtlAndAnnos(new Top)._1.serialize
+ chirrtl should include("inst i0 of AddOneBlackBox")
+ chirrtl should include("inst i1 of AddOneBlackBox")
+ chirrtl should include("i0.in <= in")
+ chirrtl should include("out <= i0.out")
+ chirrtl should include("i1.in <= io.in")
+ chirrtl should include("io.out <= i1.out")
+ }
}
describe("1: Annotations on instances in same chisel compilation") {
it("1.0: should work on a single instance, annotating the instance") {
@@ -298,7 +321,18 @@ class InstanceSpec extends ChiselFunSpec with Utils {
annos should contain(MarkAnnotation("~Top|Top/i:HasEither>x".rt, "xright"))
annos should contain(MarkAnnotation("~Top|Top/i:HasEither>y".rt, "yleft"))
}
- it("3.12: should properly support val modifiers") {
+ it("3.12: should work on tuple2") {
+ class Top() extends Module {
+ val i = Instance(Definition(new HasTuple2()))
+ mark(i.xy._1, "x")
+ mark(i.xy._2, "y")
+ }
+ val (_, annos) = getFirrtlAndAnnos(new Top)
+ annos should contain(MarkAnnotation("~Top|Top/i:HasTuple2>x".rt, "x"))
+ annos should contain(MarkAnnotation("~Top|Top/i:HasTuple2>y".rt, "y"))
+ }
+
+ it("3.13: should properly support val modifiers") {
class SupClass extends Module {
val value = 10
val overriddenVal = 10
@@ -320,6 +354,16 @@ class InstanceSpec extends ChiselFunSpec with Utils {
@public override final lazy val y: Int = 4
}
}
+ it("3.13: should work with Mems/SyncReadMems") {
+ class Top() extends Module {
+ val i = Instance(Definition(new HasMems()))
+ mark(i.mem, "Mem")
+ mark(i.syncReadMem, "SyncReadMem")
+ }
+ val (_, annos) = getFirrtlAndAnnos(new Top)
+ annos should contain(MarkAnnotation("~Top|Top/i:HasMems>mem".rt, "Mem"))
+ annos should contain(MarkAnnotation("~Top|Top/i:HasMems>syncReadMem".rt, "SyncReadMem"))
+ }
}
describe("4: toInstance") {
it("4.0: should work on modules") {
@@ -695,6 +739,51 @@ class InstanceSpec extends ChiselFunSpec with Utils {
annos should contain(e)
}
}
+
+ it("7.4: should work on Views of BlackBoxes") {
+ @instantiable
+ class MyBlackBox extends BlackBox {
+ @public val io = IO(new Bundle {
+ val in = Input(UInt(8.W))
+ val out = Output(UInt(8.W))
+ })
+ @public val innerView = io.viewAs
+ @public val foo = io.in.viewAs[UInt]
+ @public val bar = io.out.viewAs[UInt]
+ }
+ class Top extends RawModule {
+ val foo = IO(Input(UInt(8.W)))
+ val bar = IO(Output(UInt(8.W)))
+ val i = Instance(Definition(new MyBlackBox))
+ val outerView = i.io.viewAs
+ i.foo := foo
+ bar := i.bar
+ mark(i.foo, "i.foo")
+ mark(i.bar, "i.bar")
+ mark(i.innerView.in, "i.innerView.in")
+ mark(outerView.out, "outerView.out")
+ }
+ val inst = "~Top|Top/i:MyBlackBox"
+ val expectedAnnos = List(
+ s"$inst>in".rt -> "i.foo",
+ s"$inst>out".rt -> "i.bar",
+ s"$inst>in".rt -> "i.innerView.in",
+ s"$inst>out".rt -> "outerView.out"
+ )
+ val expectedLines = List(
+ "i.in <= foo",
+ "bar <= i.out"
+ )
+ val (chirrtl, annos) = getFirrtlAndAnnos(new Top)
+ val text = chirrtl.serialize
+ for (line <- expectedLines) {
+ text should include(line)
+ }
+ for (e <- expectedAnnos.map(MarkAnnotation.tupled)) {
+ annos should contain(e)
+ }
+ }
+
}
describe("8: @instantiable and @public should compose with CloneModuleAsRecord") {