diff options
Diffstat (limited to 'src/test/scala')
4 files changed, 48 insertions, 2 deletions
diff --git a/src/test/scala/chiselTests/experimental/hierarchy/Annotations.scala b/src/test/scala/chiselTests/experimental/hierarchy/Annotations.scala index 2c1d2e9e..ec71fe09 100644 --- a/src/test/scala/chiselTests/experimental/hierarchy/Annotations.scala +++ b/src/test/scala/chiselTests/experimental/hierarchy/Annotations.scala @@ -4,10 +4,11 @@ package chiselTests.experimental.hierarchy import _root_.firrtl.annotations._ import chisel3.experimental.{annotate, BaseModule} -import chisel3.Data +import chisel3.{Data, MemBase} import chisel3.experimental.hierarchy.{Definition, Hierarchy, Instance} -object Annotations { +// These annotations exist purely for testing purposes +private[hierarchy] object Annotations { case class MarkAnnotation(target: IsMember, tag: String) extends SingleTargetAnnotation[IsMember] { def duplicate(n: IsMember): Annotation = this.copy(target = n) } @@ -19,7 +20,12 @@ object Annotations { extends chisel3.experimental.ChiselAnnotation { def toFirrtl = if (isAbsolute) MarkAnnotation(d.toAbsoluteTarget, tag) else MarkAnnotation(d.toTarget, tag) } + case class MarkChiselMemAnnotation[T <: Data](m: MemBase[T], tag: String, isAbsolute: Boolean) + extends chisel3.experimental.ChiselAnnotation { + def toFirrtl = if (isAbsolute) MarkAnnotation(m.toAbsoluteTarget, tag) else MarkAnnotation(m.toTarget, tag) + } def mark(d: Data, tag: String): Unit = annotate(MarkChiselAnnotation(d, tag, false)) + def mark[T <: Data](d: MemBase[T], tag: String): Unit = annotate(MarkChiselMemAnnotation(d, tag, false)) def mark[B <: BaseModule](d: Hierarchy[B], tag: String): Unit = annotate(MarkChiselHierarchyAnnotation(d, tag, true)) def amark(d: Data, tag: String): Unit = annotate(MarkChiselAnnotation(d, tag, true)) def amark[B <: BaseModule](d: Hierarchy[B], tag: String): Unit = annotate(MarkChiselHierarchyAnnotation(d, tag, true)) diff --git a/src/test/scala/chiselTests/experimental/hierarchy/DefinitionSpec.scala b/src/test/scala/chiselTests/experimental/hierarchy/DefinitionSpec.scala index 05344360..6ff4a3eb 100644 --- a/src/test/scala/chiselTests/experimental/hierarchy/DefinitionSpec.scala +++ b/src/test/scala/chiselTests/experimental/hierarchy/DefinitionSpec.scala @@ -339,6 +339,29 @@ class DefinitionSpec extends ChiselFunSpec with Utils { annos should contain(MarkAnnotation("~Top|HasTuple2>x".rt, "x")) annos should contain(MarkAnnotation("~Top|HasTuple2>y".rt, "y")) } + it("3.13: should work on Mems/SyncReadMems") { + class Top() extends Module { + val i = Definition(new HasMems()) + mark(i.mem, "Mem") + mark(i.syncReadMem, "SyncReadMem") + } + val (_, annos) = getFirrtlAndAnnos(new Top) + annos should contain(MarkAnnotation("~Top|HasMems>mem".rt, "Mem")) + annos should contain(MarkAnnotation("~Top|HasMems>syncReadMem".rt, "SyncReadMem")) + } + it("3.14: should not create memory ports") { + class Top() extends Module { + val i = Definition(new HasMems()) + i.mem(0) := 100.U // should be illegal! + } + val failure = intercept[ChiselException] { + getFirrtlAndAnnos(new Top) + } + assert( + failure.getMessage == + "Cannot create a memory port in a different module (Top) than where the memory is (HasMems)." + ) + } } describe("4: toDefinition") { it("4.0: should work on modules") { diff --git a/src/test/scala/chiselTests/experimental/hierarchy/Examples.scala b/src/test/scala/chiselTests/experimental/hierarchy/Examples.scala index 10c0464d..aff0a771 100644 --- a/src/test/scala/chiselTests/experimental/hierarchy/Examples.scala +++ b/src/test/scala/chiselTests/experimental/hierarchy/Examples.scala @@ -258,4 +258,10 @@ object Examples { val i10 = Instance(tpDef1) val i11 = Instance(tpDef1) } + + @instantiable + class HasMems() extends Module { + @public val mem = Mem(8, UInt(32.W)) + @public val syncReadMem = SyncReadMem(8, UInt(32.W)) + } } diff --git a/src/test/scala/chiselTests/experimental/hierarchy/InstanceSpec.scala b/src/test/scala/chiselTests/experimental/hierarchy/InstanceSpec.scala index 9683d648..407a7237 100644 --- a/src/test/scala/chiselTests/experimental/hierarchy/InstanceSpec.scala +++ b/src/test/scala/chiselTests/experimental/hierarchy/InstanceSpec.scala @@ -331,6 +331,17 @@ 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.foreach { x => println(x.serialize) } + 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") { |
