From 1d81119e4b50d1b130ea5df6f4ba076b7f27c9ac Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Mon, 23 Mar 2020 09:29:02 -0700 Subject: 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.--- .../scala/chiselTests/NamingAnnotationTest.scala | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src') 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) + } } -- cgit v1.2.3