summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main/scala/chisel3/core/Printf.scala
diff options
context:
space:
mode:
authorJim Lawson2016-06-20 11:08:46 -0700
committerJim Lawson2016-06-20 11:08:46 -0700
commitd408d73a171535bd7c2ba9d0037c194022b8a62f (patch)
tree81885a99ec56e89532bc3fa338f22b163dcc4d1f /chiselFrontend/src/main/scala/chisel3/core/Printf.scala
parentb5a534914795d9d17f4dfe623525f1b804e4c60f (diff)
Rename chisel3 package.
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/core/Printf.scala')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Printf.scala36
1 files changed, 36 insertions, 0 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Printf.scala b/chiselFrontend/src/main/scala/chisel3/core/Printf.scala
new file mode 100644
index 00000000..a7970816
--- /dev/null
+++ b/chiselFrontend/src/main/scala/chisel3/core/Printf.scala
@@ -0,0 +1,36 @@
+// See LICENSE for license details.
+
+package chisel.core
+
+import scala.language.experimental.macros
+
+import chisel.internal._
+import chisel.internal.Builder.pushCommand
+import chisel.internal.firrtl._
+import chisel.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[core] 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)))
+ }
+}