diff options
| author | Aditya Naik | 2022-11-10 13:41:00 -0800 |
|---|---|---|
| committer | GitHub | 2022-11-10 21:41:00 +0000 |
| commit | c51fcfea32b6c73e623657442460fb782ff0733b (patch) | |
| tree | e4719e6423be01014a6256ff2493039cd66e4cfd /core/src/main/scala/chisel3/VerificationStatement.scala | |
| parent | 17c04998d8cd5eeb4eff9506465fd2d6892793d2 (diff) | |
Warn on S-interpolator usage for assert, assume and printf (backport #2751) (#2757)
* Add internal methods to maintain binary compatibility
Co-authored-by: Megan Wachs <megan@sifive.com>
Co-authored-by: Jack Koenig <koenig@sifive.com>
Diffstat (limited to 'core/src/main/scala/chisel3/VerificationStatement.scala')
| -rw-r--r-- | core/src/main/scala/chisel3/VerificationStatement.scala | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/core/src/main/scala/chisel3/VerificationStatement.scala b/core/src/main/scala/chisel3/VerificationStatement.scala index 10cece60..a0040d78 100644 --- a/core/src/main/scala/chisel3/VerificationStatement.scala +++ b/core/src/main/scala/chisel3/VerificationStatement.scala @@ -48,7 +48,7 @@ object assert extends VerifPrintMacrosDoc { )( implicit sourceInfo: SourceInfo, compileOptions: CompileOptions - ): Assert = macro _applyMacroWithStringMessage + ): Assert = macro _applyMacroWithInterpolatorCheck /** Checks for a condition to be valid in the circuit at all times. If the * condition evaluates to false, the circuit simulation stops with an error. @@ -79,6 +79,32 @@ object assert extends VerifPrintMacrosDoc { def apply(cond: Bool)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Assert = macro _applyMacroWithNoMessage + import VerificationStatement._ + + /** @group VerifPrintMacros */ + def _applyMacroWithInterpolatorCheck( + c: blackbox.Context + )(cond: c.Tree, + message: c.Tree, + data: c.Tree* + )(sourceInfo: c.Tree, + compileOptions: c.Tree + ): c.Tree = { + import c.universe._ + message match { + case q"scala.StringContext.apply(..$_).s(..$_)" => + c.warning( + c.enclosingPosition, + "The s-interpolator prints the Scala .toString of Data objects rather than the value " + + "of the hardware wire during simulation. Use the cf-interpolator instead. If you want " + + "an elaboration time check, call assert with a Boolean condition." + ) + case _ => + } + val apply_impl_do = symbolOf[this.type].asClass.module.info.member(TermName("_applyWithSourceLinePrintable")) + q"$apply_impl_do($cond, ${getLine(c)}, _root_.scala.Some(_root_.chisel3.Printable.pack($message, ..$data)))($sourceInfo, $compileOptions)" + } + /** An elaboration-time assertion. Calls the built-in Scala assert function. */ def apply(cond: Boolean, message: => String): Unit = Predef.assert(cond, message) @@ -88,8 +114,6 @@ object assert extends VerifPrintMacrosDoc { /** Named class for assertions. */ final class Assert private[chisel3] () extends VerificationStatement - import VerificationStatement._ - /** @group VerifPrintMacros */ @deprecated( "This method has been deprecated in favor of _applyMacroWithStringMessage. Please use the same.", @@ -215,7 +239,7 @@ object assume extends VerifPrintMacrosDoc { )( implicit sourceInfo: SourceInfo, compileOptions: CompileOptions - ): Assume = macro _applyMacroWithStringMessage + ): Assume = macro _applyMacroWithInterpolatorCheck /** Assumes a condition to be valid in the circuit at all times. * Acts like an assertion in simulation and imposes a declarative @@ -257,6 +281,30 @@ object assume extends VerifPrintMacrosDoc { import VerificationStatement._ /** @group VerifPrintMacros */ + def _applyMacroWithInterpolatorCheck( + c: blackbox.Context + )(cond: c.Tree, + message: c.Tree, + data: c.Tree* + )(sourceInfo: c.Tree, + compileOptions: c.Tree + ): c.Tree = { + import c.universe._ + message match { + case q"scala.StringContext.apply(..$_).s(..$_)" => + c.warning( + c.enclosingPosition, + "The s-interpolator prints the Scala .toString of Data objects rather than the value " + + "of the hardware wire during simulation. Use the cf-interpolator instead. If you want " + + "an elaboration time check, call assert with a Boolean condition." + ) + case _ => + } + val apply_impl_do = symbolOf[this.type].asClass.module.info.member(TermName("_applyWithSourceLinePrintable")) + q"$apply_impl_do($cond, ${getLine(c)}, _root_.scala.Some(_root_.chisel3.Printable.pack($message, ..$data)))($sourceInfo, $compileOptions)" + } + + /** @group VerifPrintMacros */ @deprecated( "This method has been deprecated in favor of _applyMacroWithStringMessage. Please use the same.", "Chisel 3.5" |
