diff options
| -rw-r--r-- | src/test/scala/chiselTests/BetterNamingTests.scala | 12 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/RecordSpec.scala | 30 |
2 files changed, 33 insertions, 9 deletions
diff --git a/src/test/scala/chiselTests/BetterNamingTests.scala b/src/test/scala/chiselTests/BetterNamingTests.scala index c2bea118..301ab5d3 100644 --- a/src/test/scala/chiselTests/BetterNamingTests.scala +++ b/src/test/scala/chiselTests/BetterNamingTests.scala @@ -44,6 +44,12 @@ class IterableNaming extends NamedModuleTester { val list = stream.take(8).toList } +class DigitFieldNamesInRecord extends NamedModuleTester { + val wire = Wire(new CustomBundle("0" -> UInt(32.W), "1" -> UInt(32.W))) + expectName(wire("0"), "wire.0") + expectName(wire("1"), "wire.1") +} + /* Better Naming Tests * * These tests are intended to validate that Chisel picks better names @@ -63,4 +69,10 @@ class BetterNamingTests extends ChiselFlatSpec { elaborate { module = new IterableNaming; module } assert(module.getNameFailures() == Nil) } + + it should "allow digits to be field names in Records" in { + var module: DigitFieldNamesInRecord = null + elaborate { module = new DigitFieldNamesInRecord; module } + assert(module.getNameFailures() == Nil) + } } diff --git a/src/test/scala/chiselTests/RecordSpec.scala b/src/test/scala/chiselTests/RecordSpec.scala index c65693ed..3a2b3910 100644 --- a/src/test/scala/chiselTests/RecordSpec.scala +++ b/src/test/scala/chiselTests/RecordSpec.scala @@ -7,16 +7,17 @@ import chisel3.testers.BasicTester import chisel3.util.{Counter, Queue} import scala.collection.immutable.ListMap +// An example of how Record might be extended +// In this case, CustomBundle is a Record constructed from a Tuple of (String, Data) +// it is a possible implementation of a programmatic "Bundle" +// (and can by connected to MyBundle below) +final class CustomBundle(elts: (String, Data)*) extends Record { + val elements = ListMap(elts map { case (field, elt) => field -> elt.chiselCloneType }: _*) + def apply(elt: String): Data = elements(elt) + override def cloneType = (new CustomBundle(elements.toList: _*)).asInstanceOf[this.type] +} + trait RecordSpecUtils { - // An example of how Record might be extended - // In this case, CustomBundle is a Record constructed from a Tuple of (String, Data) - // it is a possible implementation of a programmatic "Bundle" - // (and can by connected to MyBundle below) - final class CustomBundle(elts: (String, Data)*) extends Record { - val elements = ListMap(elts map { case (field, elt) => field -> elt.chiselCloneType }: _*) - def apply(elt: String): Data = elements(elt) - override def cloneType = (new CustomBundle(elements.toList: _*)).asInstanceOf[this.type] - } class MyBundle extends Bundle { val foo = UInt(32.W) val bar = UInt(32.W) @@ -82,6 +83,13 @@ trait RecordSpecUtils { assert(mod.io("out").asUInt === 1234.U) stop() } + + class RecordDigitTester extends BasicTester { + val wire = Wire(new CustomBundle("0" -> UInt(32.W))) + wire("0") := 123.U + assert(wire("0").asUInt === 123.U) + stop() + } } class RecordSpec extends ChiselFlatSpec with RecordSpecUtils { @@ -107,6 +115,10 @@ class RecordSpec extends ChiselFlatSpec with RecordSpecUtils { assertTesterPasses { new RecordIOTester } } + they should "support digits as names of fields" in { + assertTesterPasses { new RecordDigitTester } + } + "Bulk connect on Record" should "check that the fields match" in { (the [ChiselException] thrownBy { elaborate { new MyModule(fooBarType, new CustomBundle("bar" -> UInt(32.W))) } |
