summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/naming
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/scala/chiselTests/naming')
-rw-r--r--src/test/scala/chiselTests/naming/NamePluginSpec.scala38
-rw-r--r--src/test/scala/chiselTests/naming/PrefixSpec.scala114
-rw-r--r--src/test/scala/chiselTests/naming/ReflectiveNamingSpec.scala161
3 files changed, 308 insertions, 5 deletions
diff --git a/src/test/scala/chiselTests/naming/NamePluginSpec.scala b/src/test/scala/chiselTests/naming/NamePluginSpec.scala
index 18359fd2..a787bb80 100644
--- a/src/test/scala/chiselTests/naming/NamePluginSpec.scala
+++ b/src/test/scala/chiselTests/naming/NamePluginSpec.scala
@@ -3,6 +3,7 @@
package chiselTests.naming
import chisel3._
+import chisel3.stage.ChiselStage
import chisel3.aop.Select
import chisel3.experimental.{prefix, treedump}
import chiselTests.{ChiselFlatSpec, Utils}
@@ -69,6 +70,24 @@ class NamePluginSpec extends ChiselFlatSpec with Utils {
}
}
+ "Scala plugin" should "name verification ops" in {
+ class Test extends Module {
+ val foo, bar = IO(Input(UInt(8.W)))
+
+ {
+ val x1 = chisel3.assert(1.U === 1.U)
+ val x2 = cover(foo =/= bar)
+ val x3 = chisel3.assume(foo =/= 123.U)
+ val x4 = printf("foo = %d\n", foo)
+ }
+ }
+ val chirrtl = ChiselStage.emitChirrtl(new Test)
+ (chirrtl should include).regex("assert.*: x1")
+ (chirrtl should include).regex("cover.*: x2")
+ (chirrtl should include).regex("assume.*: x3")
+ (chirrtl should include).regex("printf.*: x4")
+ }
+
"Naming on option" should "work" in {
class Test extends Module {
@@ -321,4 +340,23 @@ class NamePluginSpec extends ChiselFlatSpec with Utils {
Select.wires(top).map(_.instanceName) should be(List("a_b_c", "a_b", "a"))
}
}
+
+ behavior.of("Unnamed values (aka \"Temporaries\")")
+
+ they should "be declared by starting the name with '_'" in {
+ class Test extends Module {
+ {
+ val a = {
+ val b = {
+ val _c = Wire(UInt(3.W))
+ 4.U // literal so there is no name
+ }
+ b
+ }
+ }
+ }
+ aspectTest(() => new Test) { top: Test =>
+ Select.wires(top).map(_.instanceName) should be(List("_a_b_c"))
+ }
+ }
}
diff --git a/src/test/scala/chiselTests/naming/PrefixSpec.scala b/src/test/scala/chiselTests/naming/PrefixSpec.scala
index f9a78f0e..6d52407e 100644
--- a/src/test/scala/chiselTests/naming/PrefixSpec.scala
+++ b/src/test/scala/chiselTests/naming/PrefixSpec.scala
@@ -3,6 +3,7 @@
package chiselTests.naming
import chisel3._
+import chisel3.stage.ChiselStage
import chisel3.aop.Select
import chisel3.experimental.{dump, noPrefix, prefix, treedump}
import chiselTests.{ChiselPropSpec, Utils}
@@ -232,18 +233,46 @@ class PrefixSpec extends ChiselPropSpec with Utils {
}
}
- property("Prefixing should be the prefix during the last call to autoName/suggestName") {
+ property("Prefixing should NOT be influenced by suggestName") {
class Test extends Module {
{
val wire = {
- val x = Wire(UInt(3.W)).suggestName("mywire")
- x
+ val x = Wire(UInt(3.W)) // wire_x
+ Wire(UInt(3.W)).suggestName("foo")
+ }
+ }
+ }
+ aspectTest(() => new Test) { top: Test =>
+ Select.wires(top).map(_.instanceName) should be(List("wire_x", "foo"))
+ }
+ }
+
+ property("Prefixing should be influenced by the \"current name\" of the signal") {
+ class Test extends Module {
+ {
+ val wire = {
+ val y = Wire(UInt(3.W)).suggestName("foo")
+ val x = Wire(UInt(3.W)) // wire_x
+ y
+ }
+
+ val wire2 = Wire(UInt(3.W))
+ wire2 := {
+ val x = Wire(UInt(3.W)) // wire2_x
+ x + 1.U
+ }
+ wire2.suggestName("bar")
+
+ val wire3 = Wire(UInt(3.W))
+ wire3.suggestName("fizz")
+ wire3 := {
+ val x = Wire(UInt(3.W)) // fizz_x
+ x + 1.U
}
}
}
aspectTest(() => new Test) { top: Test =>
- Select.wires(top).map(_.instanceName) should be(List("mywire"))
- Select.wires(top).map(_.instanceName) shouldNot be(List("wire_mywire"))
+ Select.wires(top).map(_.instanceName) should be(List("foo", "wire_x", "bar", "wire2_x", "fizz", "fizz_x"))
}
}
@@ -391,6 +420,81 @@ class PrefixSpec extends ChiselPropSpec with Utils {
aspectTest(() => new Test) { top: Test =>
Select.wires(top).map(_.instanceName) should be(List("x", "x_w_w", "x_w_w_w", "x_w_w_w_w"))
}
+ }
+
+ property("Prefixing should work for verification ops") {
+ class Test extends Module {
+ val foo, bar = IO(Input(UInt(8.W)))
+
+ {
+ val x5 = {
+ val x1 = chisel3.assert(1.U === 1.U)
+ val x2 = cover(foo =/= bar)
+ val x3 = chisel3.assume(foo =/= 123.U)
+ val x4 = printf("foo = %d\n", foo)
+ x1
+ }
+ }
+ }
+ val chirrtl = ChiselStage.emitChirrtl(new Test)
+ (chirrtl should include).regex("assert.*: x5")
+ (chirrtl should include).regex("cover.*: x5_x2")
+ (chirrtl should include).regex("assume.*: x5_x3")
+ (chirrtl should include).regex("printf.*: x5_x4")
+ }
+ property("Leading '_' in val names should be ignored in prefixes") {
+ class Test extends Module {
+ {
+ val a = {
+ val _b = {
+ val c = Wire(UInt(3.W))
+ 4.U // literal because there is no name
+ }
+ _b
+ }
+ }
+ }
+ aspectTest(() => new Test) { top: Test =>
+ Select.wires(top).map(_.instanceName) should be(List("a_b_c"))
+ }
+ }
+
+ // This checks that we don't just blanket ignore leading _ in prefixes
+ property("User-specified prefixes with '_' should be respected") {
+ class Test extends Module {
+ {
+ val a = {
+ val _b = prefix("_b") {
+ val c = Wire(UInt(3.W))
+ }
+ 4.U
+ }
+ }
+ }
+ aspectTest(() => new Test) { top: Test =>
+ Select.wires(top).map(_.instanceName) should be(List("a__b_c"))
+ }
+ }
+
+ property("Leading '_' in signal names should be ignored in prefixes from connections") {
+ class Test extends Module {
+ {
+ val a = {
+ val b = {
+ val _c = IO(Output(UInt(3.W))) // port so not selected as wire
+ _c := {
+ val d = Wire(UInt(3.W))
+ d
+ }
+ 4.U // literal so there is no name
+ }
+ b
+ }
+ }
+ }
+ aspectTest(() => new Test) { top: Test =>
+ Select.wires(top).map(_.instanceName) should be(List("a_b_c_d"))
+ }
}
}
diff --git a/src/test/scala/chiselTests/naming/ReflectiveNamingSpec.scala b/src/test/scala/chiselTests/naming/ReflectiveNamingSpec.scala
new file mode 100644
index 00000000..baa991dd
--- /dev/null
+++ b/src/test/scala/chiselTests/naming/ReflectiveNamingSpec.scala
@@ -0,0 +1,161 @@
+// SPDX-License-Identifier: Apache-2.0
+
+package chiselTests.naming
+
+import chisel3._
+import chiselTests.{ChiselFlatSpec, Utils}
+
+class ReflectiveNamingSpec extends ChiselFlatSpec with Utils {
+
+ behavior.of("Reflective naming")
+
+ private def emitChirrtl(gen: => RawModule): String = {
+ // Annoyingly need to emit files to use CLI
+ val targetDir = createTestDirectory(this.getClass.getSimpleName).toString
+ val args = Array("--warn:reflective-naming", "-td", targetDir)
+ (new chisel3.stage.ChiselStage).emitChirrtl(gen, args)
+ }
+
+ it should "NOT warn when no names are changed" in {
+ class Example extends Module {
+ val foo, bar = IO(Input(UInt(8.W)))
+ val out = IO(Output(UInt(8.W)))
+
+ val sum = foo +& bar
+ out := sum
+ }
+ val (log, chirrtl) = grabLog(emitChirrtl(new Example))
+ log should equal("")
+ chirrtl should include("node sum = add(foo, bar)")
+ }
+
+ it should "warn when changing the name of a node" in {
+ class Example extends Module {
+ val foo, bar = IO(Input(UInt(8.W)))
+ val out = IO(Output(UInt(8.W)))
+
+ val sum = foo +& bar
+ val fuzz = sum
+ out := sum
+ }
+ val (log, chirrtl) = grabLog(emitChirrtl(new Example))
+ log should include("'sum' is renamed by reflection to 'fuzz'")
+ chirrtl should include("node fuzz = add(foo, bar)")
+ }
+
+ // This also checks correct prefix reversing
+ it should "warn when changing the name of a node with a prefix in the name" in {
+ class Example extends Module {
+ val foo, bar = IO(Input(UInt(8.W)))
+ val out = IO(Output(UInt(8.W)))
+
+ // This is sketch, don't do this
+ var fuzz = 0.U
+ out := {
+ val sum = {
+ val node = foo +& bar
+ fuzz = node
+ node +% 0.U
+ }
+ sum
+ }
+ }
+ val (log, chirrtl) = grabLog(emitChirrtl(new Example))
+ log should include("'out_sum_node' is renamed by reflection to 'fuzz'")
+ chirrtl should include("node fuzz = add(foo, bar)")
+ }
+
+ it should "warn when changing the name of a Module instance" in {
+ import chisel3.util._
+ class Example extends Module {
+ val enq = IO(Flipped(Decoupled(UInt(8.W))))
+ val deq = IO(Decoupled(UInt(8.W)))
+
+ val q = Module(new Queue(UInt(8.W), 4))
+ q.io.enq <> enq
+ deq <> q.io.deq
+
+ val fuzz = q
+ }
+ val (log, chirrtl) = grabLog(emitChirrtl(new Example))
+ log should include("'q' is renamed by reflection to 'fuzz'")
+ chirrtl should include("inst fuzz of Queue")
+ }
+
+ it should "warn when changing the name of an Instance" in {
+ import chisel3.experimental.hierarchy.{Definition, Instance}
+ import chiselTests.experimental.hierarchy.Examples.AddOne
+ class Example extends Module {
+ val defn = Definition(new AddOne)
+ val inst = Instance(defn)
+ val fuzz = inst
+ }
+ val (log, chirrtl) = grabLog(emitChirrtl(new Example))
+ log should include("'inst' is renamed by reflection to 'fuzz'")
+ chirrtl should include("inst fuzz of AddOne")
+ }
+
+ it should "warn when changing the name of a Mem" in {
+ class Example extends Module {
+ val mem = SyncReadMem(8, UInt(8.W))
+
+ val fuzz = mem
+ }
+ val (log, chirrtl) = grabLog(emitChirrtl(new Example))
+ log should include("'mem' is renamed by reflection to 'fuzz'")
+ chirrtl should include("smem fuzz")
+ }
+
+ it should "NOT warn when changing the name of a verification statement" in {
+ class Example extends Module {
+ val in = IO(Input(UInt(8.W)))
+ val z = chisel3.assert(in =/= 123.U)
+ val fuzz = z
+ }
+ val (log, chirrtl) = grabLog(emitChirrtl(new Example))
+ log should equal("")
+ // But the name is actually changed
+ (chirrtl should include).regex("assert.*: fuzz")
+ }
+
+ it should "NOT warn when \"naming\" a literal" in {
+ class Example extends Module {
+ val out = IO(Output(UInt(8.W)))
+
+ val sum = 0.U
+ val fuzz = sum
+ out := sum
+ }
+ val (log, chirrtl) = grabLog(emitChirrtl(new Example))
+ log should equal("")
+ chirrtl should include("out <= UInt")
+ }
+
+ it should "NOT warn when \"naming\" a field of an Aggregate" in {
+ class Example extends Module {
+ val io = IO(new Bundle {
+ val in = Input(UInt(8.W))
+ val out = Output(UInt(8.W))
+ })
+ val in = io.in
+ val out = io.out
+ out := in
+ }
+ val (log, chirrtl) = grabLog(emitChirrtl(new Example))
+ log should equal("")
+ chirrtl should include("io.out <= io.in")
+ }
+
+ it should "NOT warn when \"naming\" unbound Data" in {
+ class Example extends Module {
+ val in = IO(Input(UInt(8.W)))
+ val out = IO(Output(UInt(8.W)))
+ val z = UInt(8.W)
+ val a = z
+ out := in
+ }
+ val (log, chirrtl) = grabLog(emitChirrtl(new Example))
+ log should equal("")
+ chirrtl should include("out <= in")
+ }
+}