From cb7fcd2b18135230dc40f3c7bb98685e7ffde9d5 Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Fri, 22 Dec 2017 09:30:21 -0800 Subject: Fixes format strings in assertions. Fixes #540 (#542) --- chiselFrontend/src/main/scala/chisel3/core/Assert.scala | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'chiselFrontend') 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)) } } -- cgit v1.2.3