diff options
| author | Jack Koenig | 2017-12-13 20:05:58 -0800 |
|---|---|---|
| committer | edwardcwang | 2017-12-13 22:09:55 -0800 |
| commit | 66f958d5b856b1633e18c567bb0f838c2291f4f6 (patch) | |
| tree | f328582acd22aab04b092d3f1b39f19dc7dcdb32 /chiselFrontend | |
| parent | 0a9258d0c2a787c84a970355e39a3e8f58a12021 (diff) | |
Expand Printable documentation
Diffstat (limited to 'chiselFrontend')
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/Printable.scala | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Printable.scala b/chiselFrontend/src/main/scala/chisel3/core/Printable.scala index f6e63936..8c35c33a 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Printable.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Printable.scala @@ -14,12 +14,39 @@ import java.util.{ /** Superclass of things that can be printed in the resulting circuit * - * Usually created using the custom string interpolator p"..." - * TODO Add support for names of Modules - * Currently impossible because unpack is called before the name is selected - * Could be implemented by adding a new format specifier to Firrtl (eg. %m) - * TODO Should we provide more functions like map and mkPrintable? + * Usually created using the custom string interpolator `p"..."`. Printable string interpolation is + * similar to [[https://docs.scala-lang.org/overviews/core/string-interpolation.html String + * interpolation in Scala]] For example: + * {{{ + * printf(p"The value of wire = \$wire\n") + * }}} + * This is equivalent to writing: + * {{{ + * printf(p"The value of wire = %d\n", wire) + * }}} + * All Chisel data types have a method `.toPrintable` that gives a default pretty print that can be + * accessed via `p"..."`. This works even for aggregate types, for example: + * {{{ + * val myVec = VecInit(5.U, 10.U, 13.U) + * printf(p"myVec = \$myVec\n") + * // myVec = Vec(5, 10, 13) + * + * val myBundle = Wire(new Bundle { + * val foo = UInt() + * val bar = UInt() + * }) + * myBundle.foo := 3.U + * myBundle.bar := 11.U + * printf(p"myBundle = \$myBundle\n") + * // myBundle = Bundle(a -> 3, b -> 11) + * }}} + * Users can override the default behavior of `.toPrintable` in custom [[Bundle]] and [[Record]] + * types. */ +// TODO Add support for names of Modules +// Currently impossible because unpack is called before the name is selected +// Could be implemented by adding a new format specifier to Firrtl (eg. %m) +// TODO Should we provide more functions like map and mkPrintable? sealed abstract class Printable { /** Unpack into format String and a List of String arguments (identifiers) * @note This must be called after elaboration when Chisel nodes actually |
