summaryrefslogtreecommitdiff
path: root/core/src/main/scala/chisel3/experimental/Trace.scala
diff options
context:
space:
mode:
authorJack2022-11-11 06:53:04 +0000
committerJack2022-11-11 06:53:04 +0000
commit3ce953c81f06519351c48277e3474b5720ec07ff (patch)
treeac79dcb80d0528c2ae86ca21da4cf424715ab645 /core/src/main/scala/chisel3/experimental/Trace.scala
parentadccde9998c91875e5490cff6d5822ffacc593ed (diff)
parentc8046636a25474be4c547c6fe9c6d742ea7b1d13 (diff)
Merge branch '3.5.x' into 3.5-release
Diffstat (limited to 'core/src/main/scala/chisel3/experimental/Trace.scala')
-rw-r--r--core/src/main/scala/chisel3/experimental/Trace.scala50
1 files changed, 46 insertions, 4 deletions
diff --git a/core/src/main/scala/chisel3/experimental/Trace.scala b/core/src/main/scala/chisel3/experimental/Trace.scala
index 4ab615a5..eb2ed46a 100644
--- a/core/src/main/scala/chisel3/experimental/Trace.scala
+++ b/core/src/main/scala/chisel3/experimental/Trace.scala
@@ -1,7 +1,7 @@
package chisel3.experimental
import chisel3.internal.HasId
-import chisel3.{Aggregate, Data, Element, Module}
+import chisel3.{Aggregate, Data, Element, Module, RawModule}
import firrtl.AnnotationSeq
import firrtl.annotations.{Annotation, CompleteTarget, SingleTargetAnnotation}
import firrtl.transforms.DontTouchAllTargets
@@ -22,13 +22,22 @@ import firrtl.transforms.DontTouchAllTargets
object Trace {
/** Trace a Instance name. */
- def traceName(x: Module): Unit = {
+ @deprecated("switch to traceNameV2 (until Chisel 3.6)", "3.5.5")
+ def traceName(x: Module): Unit = traceName(x: RawModule)
+
+ /** Trace a Instance name. */
+ @deprecated("switch to traceNameV2 (until Chisel 3.6)", "3.5.5")
+ def traceName(x: RawModule): Unit = {
annotate(new ChiselAnnotation {
def toFirrtl: Annotation = TraceNameAnnotation(x.toAbsoluteTarget, x.toAbsoluteTarget)
})
}
- /** Trace a Data name. */
+ /** Trace a Data name. This adds "don't touch" semantics to anything traced. */
+ @deprecated(
+ "switch to traceNameV2 (until Chisel 3.6) and add dontTouch if you want \"don't touch\" behavior",
+ "3.5.5"
+ )
def traceName(x: Data): Unit = {
x match {
case aggregate: Aggregate =>
@@ -43,7 +52,29 @@ object Trace {
}
}
- /** An Annotation that records the original target annotate from Chisel.
+ /** Trace an Instance name. */
+ def traceNameV2(x: RawModule): Unit = {
+ annotate(new ChiselAnnotation {
+ def toFirrtl: Annotation = TraceAnnotation(x.toAbsoluteTarget, x.toAbsoluteTarget)
+ })
+ }
+
+ /** Trace a Data name. This does NOT add "don't touch" semantics to the traced data. If you want this behavior, use an explicit [[chisel3.dontTouch]]. */
+ def traceNameV2(x: Data): Unit = {
+ x match {
+ case aggregate: Aggregate =>
+ annotate(new ChiselAnnotation {
+ def toFirrtl: Annotation = TraceAnnotation(aggregate.toAbsoluteTarget, aggregate.toAbsoluteTarget)
+ })
+ aggregate.elementsIterator.foreach(traceNameV2)
+ case element: Element =>
+ annotate(new ChiselAnnotation {
+ def toFirrtl: Annotation = TraceAnnotation(element.toAbsoluteTarget, element.toAbsoluteTarget)
+ })
+ }
+ }
+
+ /** An Annotation that records the original target annotate from Chisel. This adds don't touch behavior.
*
* @param target target that should be renamed by [[firrtl.RenameMap]] in the firrtl transforms.
* @param chiselTarget original annotated target in Chisel, which should not be changed or renamed in FIRRTL.
@@ -54,6 +85,16 @@ object Trace {
def duplicate(n: T): Annotation = this.copy(target = n)
}
+ /** An Annotation that records the original target annotate from Chisel. This does NOT add don't touch behavior.
+ *
+ * @param target target that should be renamed by [[firrtl.RenameMap]] in the firrtl transforms.
+ * @param chiselTarget original annotated target in Chisel, which should not be changed or renamed in FIRRTL.
+ */
+ private case class TraceAnnotation[T <: CompleteTarget](target: T, chiselTarget: T)
+ extends SingleTargetAnnotation[T] {
+ def duplicate(n: T): Annotation = this.copy(target = n)
+ }
+
/** Get [[CompleteTarget]] of the target `x` for `annos`.
* This API can be used to find the final reference to a signal or module which is marked by `traceName`
*/
@@ -65,5 +106,6 @@ object Trace {
*/
def finalTargetMap(annos: AnnotationSeq): Map[CompleteTarget, Seq[CompleteTarget]] = annos.collect {
case TraceNameAnnotation(t, chiselTarget) => chiselTarget -> t
+ case TraceAnnotation(t, chiselTarget) => chiselTarget -> t
}.groupBy(_._1).map { case (k, v) => k -> v.map(_._2) }
}