@@ -72,7 +72,7 @@ sealed abstract class Printable {
7272
7373object Printable {
7474
75- private [chisel3] def isNoArgSpecifier (c : Char ): Boolean = c == '%' || c == 'm'
75+ private [chisel3] def isNoArgSpecifier (c : Char ): Boolean = c == '%' || c == 'm' || c == 'T'
7676
7777 /** Pack standard printf fmt, args* style into Printable
7878 */
@@ -102,7 +102,7 @@ object Printable {
102102 while (iter < fmt.size) {
103103 // Encountered % which is either
104104 // 1. Describing a format specifier.
105- // 2. %% or %m
105+ // 2. %%, %m, or %T
106106 // 3. Dangling percent - most likely due to a typo - intended literal percent or forgot the specifier.
107107 // Try to give meaningful error reports
108108 if (fmt(iter) == '%' ) {
@@ -193,10 +193,10 @@ object Printable {
193193 /** Resolve Printables that are resolved at Chisel-time */
194194 private [chisel3] def resolve (pable : Printable , ctx : Component )(implicit info : SourceInfo ): Printable =
195195 pable.map {
196- case Name (data) => PString (data.ref.name)
197- case FullName (data) => PString (data.ref.fullName(ctx))
198- case HierarchicalModuleName => PString (" {{HierarchicalModuleName}} " )
199- case other => other
196+ case Name (data) => PString (data.ref.name)
197+ case FullName (data) => PString (data.ref.fullName(ctx))
198+ case s : SpecialFirrtlSubstitution => PString (s.substitutionString )
199+ case other => other
200200 }
201201}
202202
@@ -377,11 +377,28 @@ case object Percent extends Printable {
377377 final def unpack : (String , Seq [Data ]) = (" %%" , List .empty)
378378}
379379
380+ /** Printable with special representation in FIRRTL
381+ *
382+ * @note The name of the singleton object exactly matches the FIRRTL value.
383+ */
384+ sealed trait SpecialFirrtlSubstitution { self : Singleton with Printable =>
385+ private [chisel3] final def substitutionString : String = " {{" + this .getClass.getSimpleName.dropRight(1 ) + " }}"
386+ }
387+
380388/** Represents the hierarchical name in the Verilog (`%m`) */
381- case object HierarchicalModuleName extends Printable {
389+ case object HierarchicalModuleName extends Printable with SpecialFirrtlSubstitution {
382390 @ deprecated(" Use unpack with no arguments instead." , " Chisel 7.0.0" )
383391 final def unpack (ctx : Component )(implicit info : SourceInfo ): (String , Iterable [String ]) = (" %m" , List .empty)
384392 @ deprecated(" Use unpack with no arguments instead." , " Chisel 7.0.0" )
385393 final def unpackArgs : Seq [Bits ] = List .empty
386394 final def unpack : (String , Seq [Data ]) = (" %m" , List .empty)
387395}
396+
397+ /** Represents the simulation time in the Verilog, similar to `%t` + `$time` */
398+ case object SimulationTime extends Printable with SpecialFirrtlSubstitution {
399+ @ deprecated(" Use unpack with no arguments instead." , " Chisel 7.0.0" )
400+ final def unpack (ctx : Component )(implicit info : SourceInfo ): (String , Iterable [String ]) = (" %T" , List .empty)
401+ @ deprecated(" Use unpack with no arguments instead." , " Chisel 7.0.0" )
402+ final def unpackArgs : Seq [Bits ] = List .empty
403+ final def unpack : (String , Seq [Data ]) = (" %T" , List .empty)
404+ }
0 commit comments