import chisel3._ import chisel3.experimental.{ChiselAnnotation, annotate} import circt.stage.ChiselStage import firrtl.AnnotationSeq import firrtl.annotations.{ReferenceTarget, SingleTargetAnnotation} import firrtl.options.CustomFileEmission case class MyMetaString(target: ReferenceTarget, string: String, version: Float = 1.0f) extends SingleTargetAnnotation[ReferenceTarget] with CustomFileEmission { def targets = Seq(target) def duplicate(n: ReferenceTarget) = { println("duplicate") this.copy() } //def getBytes: Iterable[Byte] = string.getBytes protected def baseFileName(annotations: AnnotationSeq): String = "my_meta" protected def suffix: Option[String] = Some(".tvcd") def getBytes: Iterable[Byte] = s"Annotated signal: ${target.serialize} -> $string $version".getBytes } object mark { def apply[T <: Data](x: T): T = { annotate(new ChiselAnnotation { def toFirrtl = MyMetaString(x.toTarget, x.pathName) }) x } } class Foo extends Module { val in = IO(Input(UInt(3.W))) val out = IO(Output(UInt(2.W))) out := in mark(in) } object Main extends App { /* Run Chisel, but not the Scala FIRRTL Compiler. */ println((ChiselStage).emitSystemVerilog(new Foo)) ChiselStage.emitSystemVerilogFile(new Foo) }