summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZachary Yedidia2022-08-23 17:20:12 -0700
committerGitHub2022-08-24 00:20:12 +0000
commitc3b06d773f1fabd2519d6c705d68381d13f1c07f (patch)
tree3607efa0d3c83b4885621b21af73ce372ee824f9
parent1c5bd39a192272877cf4b8dc3d26a9284eb0c05d (diff)
Backport .toTarget deprecation warning information (3.5.x) (#2697)
-rw-r--r--core/src/main/scala/chisel3/internal/Builder.scala14
-rw-r--r--src/test/scala/chiselTests/RecordSpec.scala2
-rw-r--r--src/test/scala/chiselTests/ToTargetSpec.scala17
3 files changed, 30 insertions, 3 deletions
diff --git a/core/src/main/scala/chisel3/internal/Builder.scala b/core/src/main/scala/chisel3/internal/Builder.scala
index 07d8e7f7..07fc80eb 100644
--- a/core/src/main/scala/chisel3/internal/Builder.scala
+++ b/core/src/main/scala/chisel3/internal/Builder.scala
@@ -249,10 +249,20 @@ private[chisel3] trait HasId extends InstanceId {
// Builder.deprecated mechanism, we have to create our own one off ErrorLog and print the
// warning right away.
// It's especially bad because --warnings-as-errors does not work with these warnings
+ val nameGuess = _computeName(None) match {
+ case Some(name) => s": '$name'"
+ case None => ""
+ }
+ val parentGuess = _parent match {
+ case Some(ViewParent) => s", in module '${reifyParent.pathName}'"
+ case Some(p) => s", in module '${p.pathName}'"
+ case None => ""
+ }
val errors = new ErrorLog(false)
val logger = new _root_.logger.Logger(this.getClass.getName)
- val msg = "Accessing the .instanceName or .toTarget of non-hardware Data is deprecated. " +
- "This will become an error in Chisel 3.6."
+ val msg =
+ "Accessing the .instanceName or .toTarget of non-hardware Data is deprecated" + nameGuess + parentGuess + ". " +
+ "This will become an error in Chisel 3.6."
errors.deprecated(msg, None)
errors.checkpoint(logger)
_computeName(None).get
diff --git a/src/test/scala/chiselTests/RecordSpec.scala b/src/test/scala/chiselTests/RecordSpec.scala
index 5aa872b0..718c1acb 100644
--- a/src/test/scala/chiselTests/RecordSpec.scala
+++ b/src/test/scala/chiselTests/RecordSpec.scala
@@ -228,7 +228,7 @@ class RecordSpec extends ChiselFlatSpec with RecordSpecUtils with Utils {
var m: SingleElementRecordModule = null
ChiselStage.elaborate { m = new SingleElementRecordModule; m }
val (log, q) = grabLog(m.r.toTarget)
- log should include(".toTarget of non-hardware Data is deprecated.")
+ log should include(".toTarget of non-hardware Data is deprecated")
assert(q.toString == "~SingleElementRecordModule|SingleElementRecordModule>r")
}
diff --git a/src/test/scala/chiselTests/ToTargetSpec.scala b/src/test/scala/chiselTests/ToTargetSpec.scala
index dc4ec448..de46cdcb 100644
--- a/src/test/scala/chiselTests/ToTargetSpec.scala
+++ b/src/test/scala/chiselTests/ToTargetSpec.scala
@@ -49,4 +49,21 @@ class ToTargetSpec extends ChiselFlatSpec with Utils {
val q = m.q.toTarget.toString
assert(q == s"~$mn|Queue")
}
+
+ it should "warn on non-hardware types and provide information" in {
+ class Example extends Module {
+ val tpe = UInt(8.W)
+
+ val in = IO(Input(tpe))
+ val out = IO(Output(tpe))
+ out := in
+ }
+
+ var e: Example = null
+ chisel3.stage.ChiselStage.elaborate { e = new Example; e }
+ val (log, foo) = grabLog(e.tpe.toTarget)
+ log should include(
+ "Accessing the .instanceName or .toTarget of non-hardware Data is deprecated: 'tpe', in module 'Example'"
+ )
+ }
}