summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests
diff options
context:
space:
mode:
authorJack Koenig2020-03-23 09:29:02 -0700
committerGitHub2020-03-23 16:29:02 +0000
commit1d81119e4b50d1b130ea5df6f4ba076b7f27c9ac (patch)
treea076e2dc86c302eab088f0d4c79aa35014a80b4f /src/test/scala/chiselTests
parent5d269ce3296cb1aeeb39350d5cb324515b6dbc36 (diff)
Add NoChiselNamePrefix to ignore instances in @chiselName (#1383)
Add trait chisel3.experimental.NoChiselNamePrefix which causes @chiselName to skip naming of the instance effectively preventing it from prefixing any vals inside the instance. It can be applied to classes such that all instances of that class have this property, or to individual instances (via creating an anonymous class inline). Also add basic ScalaDoc for NoChiselNamePrefix and chiselName.
Diffstat (limited to 'src/test/scala/chiselTests')
-rw-r--r--src/test/scala/chiselTests/NamingAnnotationTest.scala32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/NamingAnnotationTest.scala b/src/test/scala/chiselTests/NamingAnnotationTest.scala
index e35c77c1..a02dfe56 100644
--- a/src/test/scala/chiselTests/NamingAnnotationTest.scala
+++ b/src/test/scala/chiselTests/NamingAnnotationTest.scala
@@ -203,6 +203,32 @@ class PartialNamedModule extends NamedModuleTester {
val test = innerNamedFunction()
}
+@chiselName
+class NoChiselNamePrefixTester extends NamedModuleTester {
+ @chiselName
+ class NoChiselNamePrefixClass extends chisel3.experimental.NoChiselNamePrefix {
+ val a = expectName(1.U +& 2.U, "a")
+ }
+ val inst = new NoChiselNamePrefixClass
+ @chiselName
+ class NormalClass {
+ val b = 1.U +& 2.U
+ }
+ val foo = new NormalClass
+ expectName(foo.b, "foo_b")
+ val bar = new NormalClass with chisel3.experimental.NoChiselNamePrefix
+ expectName(bar.b, "b")
+
+ // Check that we're not matching by name but actual type
+ trait NoChiselNamePrefix
+ @chiselName
+ class FakeNoChiselNamePrefix extends NoChiselNamePrefix {
+ val c = 1.U +& 2.U
+ }
+ val fizz = new FakeNoChiselNamePrefix
+ expectName(fizz.c, "fizz_c")
+}
+
/** A simple test that checks the recursive function val naming annotation both compiles and
* generates the expected names.
@@ -240,4 +266,10 @@ class NamingAnnotationSpec extends ChiselPropSpec {
property("NonBuilderFunction should run outside a Builder context") {
NonNamedHelper.NonBuilderFunction() should be (2)
}
+
+ property("NoChiselNamePrefix should prevent prefixing when using @chiselName") {
+ var module: NoChiselNamePrefixTester = null
+ elaborate { module = new NoChiselNamePrefixTester; module }
+ assert(module.getNameFailures().isEmpty)
+ }
}