summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/Mem.scala
diff options
context:
space:
mode:
authorJack Koenig2020-10-22 18:40:54 -0700
committerGitHub2020-10-22 18:40:54 -0700
commit0745dedefea901df029e65aa59846d8b561dfd31 (patch)
treec887b28eaa896af282ad91809fac5c511aac3b8a /src/test/scala/chiselTests/Mem.scala
parent26deb7703389b78a9b2a61f7e191f3f0e2a6623b (diff)
Use Data refs for name prefixing with aggregate elements (#1616)
* Use Data refs for name prefixing with aggregate elements Vecs set the refs of their elements upon construction of those elements. In the past, Records haven't set their elements refs until module close, but it can be done sooner. Doing it upon binding means that refs will at least be available for Records used in hardware elements. Since only bound Data can be connected to anyway, Aggregate elements being connected to will always have a ref which we can then use for creating naming prefixes. * Add tighter correctness checks * Handle more cases in connection prefixing Add support for forcing setRef to override a previous setting. This is only used by BlackBox ports which need to drop their io prefix. Also add a Try() around Data.bindingToString which sometimes throws exceptions when being used to .toString a Data in an error message. * Strip trailing spaces in names in compiler plugin
Diffstat (limited to 'src/test/scala/chiselTests/Mem.scala')
-rw-r--r--src/test/scala/chiselTests/Mem.scala53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/Mem.scala b/src/test/scala/chiselTests/Mem.scala
index b66ec42f..8bcd3aac 100644
--- a/src/test/scala/chiselTests/Mem.scala
+++ b/src/test/scala/chiselTests/Mem.scala
@@ -96,6 +96,51 @@ class HugeCMemTester(size: BigInt) extends BasicTester {
}
}
+class SyncReadMemBundleTester extends BasicTester {
+ val (cnt, _) = Counter(true.B, 5)
+ val tpe = new Bundle {
+ val foo = UInt(2.W)
+ }
+ val mem = SyncReadMem(2, tpe)
+ val rdata = mem.read(cnt - 1.U, cnt =/= 0.U)
+
+ switch (cnt) {
+ is (0.U) {
+ val w = Wire(tpe)
+ w.foo := 3.U
+ mem.write(cnt, w)
+ }
+ is (1.U) {
+ val w = Wire(tpe)
+ w.foo := 2.U
+ mem.write(cnt, w)
+ }
+ is (2.U) { assert(rdata.foo === 3.U) }
+ is (3.U) { assert(rdata.foo === 2.U) }
+ is (4.U) { stop() }
+ }
+}
+
+class MemBundleTester extends BasicTester {
+ val tpe = new Bundle {
+ val foo = UInt(2.W)
+ }
+ val mem = Mem(2, tpe)
+
+ // Circuit style tester is definitely the wrong abstraction here
+ val (cnt, wrap) = Counter(true.B, 2)
+ mem(0) := {
+ val w = Wire(tpe)
+ w.foo := 1.U
+ w
+ }
+
+ when (cnt === 1.U) {
+ assert(mem.read(0.U).foo === 1.U)
+ stop()
+ }
+}
+
class MemorySpec extends ChiselPropSpec {
property("Mem of Vec should work") {
assertTesterPasses { new MemVecTester }
@@ -105,6 +150,14 @@ class MemorySpec extends ChiselPropSpec {
assertTesterPasses { new SyncReadMemTester }
}
+ property("SyncReadMems of Bundles should work") {
+ assertTesterPasses { new SyncReadMemBundleTester }
+ }
+
+ property("Mems of Bundles should work") {
+ assertTesterPasses { new MemBundleTester }
+ }
+
property("SyncReadMem write collision behaviors should work") {
assertTesterPasses { new SyncReadMemWriteCollisionTester }
}