diff options
| author | Jim Lawson | 2016-06-03 12:38:28 -0700 |
|---|---|---|
| committer | Jim Lawson | 2016-06-03 12:38:28 -0700 |
| commit | 9dd286b8613beba58e053ed00d15877d3a4b02c9 (patch) | |
| tree | 6ae9268d8e7e6532e5b8a0f3ad51d6c345623376 /chiselFrontend/src/main/scala/Chisel/Printf.scala | |
| parent | 70271cd8c3811cb518e81d1d5eb3ed20cb1e2063 (diff) | |
| parent | fd53af8642237998e23456a3fd1648ac84607db0 (diff) | |
Merge branch 'master' into front_end_dependency
Diffstat (limited to 'chiselFrontend/src/main/scala/Chisel/Printf.scala')
| -rw-r--r-- | chiselFrontend/src/main/scala/Chisel/Printf.scala | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/chiselFrontend/src/main/scala/Chisel/Printf.scala b/chiselFrontend/src/main/scala/Chisel/Printf.scala new file mode 100644 index 00000000..f068f637 --- /dev/null +++ b/chiselFrontend/src/main/scala/Chisel/Printf.scala @@ -0,0 +1,36 @@ +// See LICENSE for license details. + +package Chisel + +import scala.language.experimental.macros + +import internal._ +import internal.Builder.pushCommand +import internal.firrtl._ +import internal.sourceinfo.SourceInfo + +object printf { // scalastyle:ignore object.name + /** Prints a message in simulation. + * + * Does not fire when in reset (defined as the encapsulating Module's + * reset). If your definition of reset is not the encapsulating Module's + * reset, you will need to gate this externally. + * + * May be called outside of a Module (like defined in a function), so + * functions using printf make the standard Module assumptions (single clock + * and single reset). + * + * @param fmt printf format string + * @param data format string varargs containing data to print + */ + def apply(fmt: String, data: Bits*)(implicit sourceInfo: SourceInfo) { + when (!(Builder.dynamicContext.currentModule.get.reset)) { + printfWithoutReset(fmt, data:_*) + } + } + + private[Chisel] def printfWithoutReset(fmt: String, data: Bits*)(implicit sourceInfo: SourceInfo) { + val clock = Builder.dynamicContext.currentModule.get.clock + pushCommand(Printf(sourceInfo, Node(clock), fmt, data.map((d: Bits) => d.ref))) + } +} |
