summaryrefslogtreecommitdiff
path: root/chiselFrontend
diff options
context:
space:
mode:
authorJack Koenig2017-12-22 09:30:21 -0800
committerGitHub2017-12-22 09:30:21 -0800
commitcb7fcd2b18135230dc40f3c7bb98685e7ffde9d5 (patch)
tree6b268520c6dcc9b91129d07017e9713d143e6149 /chiselFrontend
parent08dfb23c97ee8cd0a01e51511fcd156a7da61c02 (diff)
Fixes format strings in assertions. Fixes #540 (#542)
Diffstat (limited to 'chiselFrontend')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Assert.scala11
1 files changed, 7 insertions, 4 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Assert.scala b/chiselFrontend/src/main/scala/chisel3/core/Assert.scala
index 7f67f244..43a74192 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Assert.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Assert.scala
@@ -23,9 +23,10 @@ object assert { // scalastyle:ignore object.name
* and single reset).
*
* @param cond condition, assertion fires (simulation fails) when false
- * @param message optional message to print when the assertion fires
+ * @param message optional format string to print when the assertion fires
* @param data optional bits to print in the message formatting
*
+ * @note See [[printf.apply(fmt:String* printf]] for format string documentation
* @note currently cannot be used in core Chisel / libraries because macro
* defs need to be compiled first and the SBT project is not set up to do
* that
@@ -51,12 +52,14 @@ object assert { // scalastyle:ignore object.name
}
def apply_impl_do(cond: Bool, line: String, message: Option[String], data: Bits*)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions) {
+ val escLine = line.replaceAll("%", "%%")
when (!(cond || Module.reset.toBool)) {
val fmt = message match {
- case Some(str) => s"Assertion failed: $str\n at $line\n"
- case None => s"Assertion failed\n at $line\n"
+ case Some(msg) =>
+ s"Assertion failed: $msg\n at $escLine\n"
+ case None => s"Assertion failed\n at $escLine\n"
}
- printf.printfWithoutReset(fmt.replaceAll("%", "%%"), data:_*)
+ printf.printfWithoutReset(fmt, data:_*)
pushCommand(Stop(sourceInfo, Node(Builder.forcedClock), 1))
}
}