summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZachary Yedidia2022-08-25 12:04:37 -0700
committerGitHub2022-08-25 19:04:37 +0000
commitdf5a95454ff0414d1d3ce16d06dbe27b152e3751 (patch)
tree2d8112b29ea20bd54ecffcf15818cff8fbaa4028
parent998913f9379440db26b6aeeaa09e7a11d7615351 (diff)
Backport of eager error messages for annotations (3.5.x) (#2700) (#2705)
-rw-r--r--src/main/scala/chisel3/util/experimental/ForceNames.scala3
-rw-r--r--src/main/scala/chisel3/util/experimental/decode/decoder.scala2
-rw-r--r--src/test/scala/chiselTests/experimental/ForceNames.scala17
3 files changed, 21 insertions, 1 deletions
diff --git a/src/main/scala/chisel3/util/experimental/ForceNames.scala b/src/main/scala/chisel3/util/experimental/ForceNames.scala
index 53ee2bd2..3070a210 100644
--- a/src/main/scala/chisel3/util/experimental/ForceNames.scala
+++ b/src/main/scala/chisel3/util/experimental/ForceNames.scala
@@ -3,6 +3,7 @@
package chisel3.util.experimental
import chisel3.experimental.{annotate, ChiselAnnotation, RunFirrtlTransform}
+import chisel3.internal.Builder
import firrtl.Mappers._
import firrtl._
import firrtl.annotations._
@@ -24,6 +25,7 @@ object forceName {
* @param name Name to force to
*/
def apply[T <: chisel3.Element](signal: T, name: String): T = {
+ if (!signal.isSynthesizable) Builder.deprecated(s"Using forceName '$name' on non-hardware value $signal")
annotate(new ChiselAnnotation with RunFirrtlTransform {
def toFirrtl = ForceNameAnnotation(signal.toTarget, name)
override def transformClass: Class[_ <: Transform] = classOf[ForceNamesTransform]
@@ -37,6 +39,7 @@ object forceName {
* @param signal Signal to name
*/
def apply[T <: chisel3.Element](signal: T): T = {
+ if (!signal.isSynthesizable) Builder.deprecated(s"Using forceName on non-hardware value $signal")
annotate(new ChiselAnnotation with RunFirrtlTransform {
def toFirrtl = ForceNameAnnotation(signal.toTarget, signal.toTarget.ref)
override def transformClass: Class[_ <: Transform] = classOf[ForceNamesTransform]
diff --git a/src/main/scala/chisel3/util/experimental/decode/decoder.scala b/src/main/scala/chisel3/util/experimental/decode/decoder.scala
index 4feda672..067dd6f8 100644
--- a/src/main/scala/chisel3/util/experimental/decode/decoder.scala
+++ b/src/main/scala/chisel3/util/experimental/decode/decoder.scala
@@ -6,6 +6,7 @@ import chisel3._
import chisel3.experimental.{annotate, ChiselAnnotation}
import chisel3.util.{pla, BitPat}
import chisel3.util.experimental.{getAnnotations, BitSet}
+import chisel3.internal.Builder
import firrtl.annotations.Annotation
import logger.LazyLogging
@@ -30,6 +31,7 @@ object decoder extends LazyLogging {
val (plaInput, plaOutput) =
pla(minimizedTable.table.toSeq, BitPat(minimizedTable.default.value.U(minimizedTable.default.getWidth.W)))
+ assert(plaOutput.isSynthesizable, s"Using DecodeTableAnnotation on non-hardware value $plaOutput")
annotate(new ChiselAnnotation {
override def toFirrtl: Annotation =
DecodeTableAnnotation(plaOutput.toTarget, truthTable.toString, minimizedTable.toString)
diff --git a/src/test/scala/chiselTests/experimental/ForceNames.scala b/src/test/scala/chiselTests/experimental/ForceNames.scala
index 233b4a5f..9ba825c4 100644
--- a/src/test/scala/chiselTests/experimental/ForceNames.scala
+++ b/src/test/scala/chiselTests/experimental/ForceNames.scala
@@ -59,7 +59,7 @@ object ForceNamesHierarchy {
}
}
-class ForceNamesSpec extends ChiselFlatSpec {
+class ForceNamesSpec extends ChiselFlatSpec with Utils {
def run[T <: RawModule](
dut: => T,
@@ -110,4 +110,19 @@ class ForceNamesSpec extends ChiselFlatSpec {
)
}
}
+
+ "Force Name of non-hardware value" should "warn" in {
+ class Example extends Module {
+ val tpe = UInt(8.W)
+ forceName(tpe, "foobar")
+
+ val in = IO(Input(tpe))
+ val out = IO(Output(tpe))
+ out := in
+ }
+
+ val (log, foo) = grabLog(chisel3.stage.ChiselStage.elaborate(new Example))
+ log should include("deprecated")
+ log should include("Using forceName 'foobar' on non-hardware value UInt<8>")
+ }
}