diff options
| author | Jack Koenig | 2022-01-10 10:39:52 -0800 |
|---|---|---|
| committer | Jack Koenig | 2022-01-10 15:53:55 -0800 |
| commit | 3131c0daad41dea78bede4517669e376c41a325a (patch) | |
| tree | 55baed78a6a01f80ff3952a08233ca553a19964f /core/src/main/scala/chisel3/VerificationStatement.scala | |
| parent | dd36f97a82746cec0b25b94651581fe799e24579 (diff) | |
Apply scalafmt
Command:
sbt scalafmtAll
Diffstat (limited to 'core/src/main/scala/chisel3/VerificationStatement.scala')
| -rw-r--r-- | core/src/main/scala/chisel3/VerificationStatement.scala | 148 |
1 files changed, 118 insertions, 30 deletions
diff --git a/core/src/main/scala/chisel3/VerificationStatement.scala b/core/src/main/scala/chisel3/VerificationStatement.scala index 23adc192..bfdfc26e 100644 --- a/core/src/main/scala/chisel3/VerificationStatement.scala +++ b/core/src/main/scala/chisel3/VerificationStatement.scala @@ -12,6 +12,7 @@ import chisel3.internal.sourceinfo.SourceInfo import scala.reflect.macros.blackbox object assert { + /** 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. * @@ -33,34 +34,62 @@ object assert { * that */ // Macros currently can't take default arguments, so we need two functions to emulate defaults. - def apply(cond: Bool, message: String, data: Bits*)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Assert = macro _applyMacroWithMessage - def apply(cond: Bool)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Assert = macro _applyMacroWithNoMessage + def apply( + cond: Bool, + message: String, + data: Bits* + )( + implicit sourceInfo: SourceInfo, + compileOptions: CompileOptions + ): Assert = macro _applyMacroWithMessage + def apply(cond: Bool)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Assert = + macro _applyMacroWithNoMessage /** An elaboration-time assertion. Calls the built-in Scala assert function. */ def apply(cond: Boolean, message: => String): Unit = Predef.assert(cond, message) + /** An elaboration-time assertion. Calls the built-in Scala assert function. */ def apply(cond: Boolean): Unit = Predef.assert(cond, "") /** Named class for assertions. */ - final class Assert private[chisel3]() extends VerificationStatement + final class Assert private[chisel3] () extends VerificationStatement import VerificationStatement._ - def _applyMacroWithMessage(c: blackbox.Context)(cond: c.Tree, message: c.Tree, data: c.Tree*)(sourceInfo: c.Tree, compileOptions: c.Tree): c.Tree = { + def _applyMacroWithMessage( + c: blackbox.Context + )(cond: c.Tree, + message: c.Tree, + data: c.Tree* + )(sourceInfo: c.Tree, + compileOptions: c.Tree + ): c.Tree = { import c.universe._ val apply_impl_do = symbolOf[this.type].asClass.module.info.member(TermName("_applyWithSourceLine")) q"$apply_impl_do($cond, ${getLine(c)}, _root_.scala.Some($message), ..$data)($sourceInfo, $compileOptions)" } - def _applyMacroWithNoMessage(c: blackbox.Context)(cond: c.Tree)(sourceInfo: c.Tree, compileOptions: c.Tree): c.Tree = { + def _applyMacroWithNoMessage( + c: blackbox.Context + )(cond: c.Tree + )(sourceInfo: c.Tree, + compileOptions: c.Tree + ): c.Tree = { import c.universe._ val apply_impl_do = symbolOf[this.type].asClass.module.info.member(TermName("_applyWithSourceLine")) q"$apply_impl_do($cond, ${getLine(c)}, _root_.scala.None)($sourceInfo, $compileOptions)" } /** Used by our macros. Do not call directly! */ - def _applyWithSourceLine(cond: Bool, line: SourceLineInfo, message: Option[String], data: Bits*) - (implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Assert = { + def _applyWithSourceLine( + cond: Bool, + line: SourceLineInfo, + message: Option[String], + data: Bits* + )( + implicit sourceInfo: SourceInfo, + compileOptions: CompileOptions + ): Assert = { val id = new Assert() when(!Module.reset.asBool()) { Builder.pushCommand(Verification(id, Formal.Assert, sourceInfo, Module.clock.ref, cond.ref, "")) @@ -70,8 +99,8 @@ object assert { } } - object assume { + /** Assumes a condition to be valid in the circuit at all times. * Acts like an assertion in simulation and imposes a declarative * assumption on the state explored by formal tools. @@ -91,34 +120,62 @@ object assume { * @note See [[printf.apply(fmt:String* printf]] for format string documentation */ // Macros currently can't take default arguments, so we need two functions to emulate defaults. - def apply(cond: Bool, message: String, data: Bits*)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Assume = macro _applyMacroWithMessage - def apply(cond: Bool)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Assume = macro _applyMacroWithNoMessage + def apply( + cond: Bool, + message: String, + data: Bits* + )( + implicit sourceInfo: SourceInfo, + compileOptions: CompileOptions + ): Assume = macro _applyMacroWithMessage + def apply(cond: Bool)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Assume = + macro _applyMacroWithNoMessage /** An elaboration-time assumption. Calls the built-in Scala assume function. */ def apply(cond: Boolean, message: => String): Unit = Predef.assume(cond, message) + /** An elaboration-time assumption. Calls the built-in Scala assume function. */ def apply(cond: Boolean): Unit = Predef.assume(cond, "") /** Named class for assumptions. */ - final class Assume private[chisel3]() extends VerificationStatement + final class Assume private[chisel3] () extends VerificationStatement import VerificationStatement._ - def _applyMacroWithMessage(c: blackbox.Context)(cond: c.Tree, message: c.Tree, data: c.Tree*)(sourceInfo: c.Tree, compileOptions: c.Tree): c.Tree = { + def _applyMacroWithMessage( + c: blackbox.Context + )(cond: c.Tree, + message: c.Tree, + data: c.Tree* + )(sourceInfo: c.Tree, + compileOptions: c.Tree + ): c.Tree = { import c.universe._ val apply_impl_do = symbolOf[this.type].asClass.module.info.member(TermName("_applyWithSourceLine")) q"$apply_impl_do($cond, ${getLine(c)}, _root_.scala.Some($message), ..$data)($sourceInfo, $compileOptions)" } - def _applyMacroWithNoMessage(c: blackbox.Context)(cond: c.Tree)(sourceInfo: c.Tree, compileOptions: c.Tree): c.Tree = { + def _applyMacroWithNoMessage( + c: blackbox.Context + )(cond: c.Tree + )(sourceInfo: c.Tree, + compileOptions: c.Tree + ): c.Tree = { import c.universe._ val apply_impl_do = symbolOf[this.type].asClass.module.info.member(TermName("_applyWithSourceLine")) q"$apply_impl_do($cond, ${getLine(c)}, _root_.scala.None)($sourceInfo, $compileOptions)" } /** Used by our macros. Do not call directly! */ - def _applyWithSourceLine(cond: Bool, line: SourceLineInfo, message: Option[String], data: Bits*) - (implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Assume = { + def _applyWithSourceLine( + cond: Bool, + line: SourceLineInfo, + message: Option[String], + data: Bits* + )( + implicit sourceInfo: SourceInfo, + compileOptions: CompileOptions + ): Assume = { val id = new Assume() when(!Module.reset.asBool()) { Builder.pushCommand(Verification(id, Formal.Assume, sourceInfo, Module.clock.ref, cond.ref, "")) @@ -128,8 +185,8 @@ object assume { } } - object cover { + /** Declares a condition to be covered. * At ever clock event, a counter is incremented iff the condition is active * and reset is inactive. @@ -146,29 +203,48 @@ object cover { * @param message a string describing the cover event */ // Macros currently can't take default arguments, so we need two functions to emulate defaults. - def apply(cond: Bool, message: String)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Cover = macro _applyMacroWithMessage - def apply(cond: Bool)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Cover = macro _applyMacroWithNoMessage + def apply(cond: Bool, message: String)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Cover = + macro _applyMacroWithMessage + def apply(cond: Bool)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Cover = + macro _applyMacroWithNoMessage /** Named class for cover statements. */ - final class Cover private[chisel3]() extends VerificationStatement + final class Cover private[chisel3] () extends VerificationStatement import VerificationStatement._ - def _applyMacroWithNoMessage(c: blackbox.Context)(cond: c.Tree)(sourceInfo: c.Tree, compileOptions: c.Tree): c.Tree = { + def _applyMacroWithNoMessage( + c: blackbox.Context + )(cond: c.Tree + )(sourceInfo: c.Tree, + compileOptions: c.Tree + ): c.Tree = { import c.universe._ val apply_impl_do = symbolOf[this.type].asClass.module.info.member(TermName("_applyWithSourceLine")) q"$apply_impl_do($cond, ${getLine(c)}, _root_.scala.None)($sourceInfo, $compileOptions)" } - def _applyMacroWithMessage(c: blackbox.Context)(cond: c.Tree, message: c.Tree)(sourceInfo: c.Tree, compileOptions: c.Tree): c.Tree = { + def _applyMacroWithMessage( + c: blackbox.Context + )(cond: c.Tree, + message: c.Tree + )(sourceInfo: c.Tree, + compileOptions: c.Tree + ): c.Tree = { import c.universe._ val apply_impl_do = symbolOf[this.type].asClass.module.info.member(TermName("_applyWithSourceLine")) q"$apply_impl_do($cond, ${getLine(c)}, _root_.scala.Some($message))($sourceInfo, $compileOptions)" } /** Used by our macros. Do not call directly! */ - def _applyWithSourceLine(cond: Bool, line: SourceLineInfo, message: Option[String]) - (implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Cover = { + def _applyWithSourceLine( + cond: Bool, + line: SourceLineInfo, + message: Option[String] + )( + implicit sourceInfo: SourceInfo, + compileOptions: CompileOptions + ): Cover = { val id = new Cover() when(!Module.reset.asBool()) { Builder.pushCommand(Verification(id, Formal.Cover, sourceInfo, Module.clock.ref, cond.ref, "")) @@ -178,30 +254,34 @@ object cover { } object stop { + /** Terminate execution, indicating success. * * @param message a string describing why the simulation was stopped */ def apply(message: String = "")(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Stop = { val stp = new Stop() - when (!Module.reset.asBool) { + when(!Module.reset.asBool) { pushCommand(Stop(stp, sourceInfo, Builder.forcedClock.ref, 0)) } stp } /** Terminate execution with a failure code. */ - @deprecated("Non-zero return codes are not well supported. Please use assert(false.B) if you want to indicate a failure.", "Chisel 3.5") + @deprecated( + "Non-zero return codes are not well supported. Please use assert(false.B) if you want to indicate a failure.", + "Chisel 3.5" + ) def apply(code: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Stop = { val stp = new Stop() - when (!Module.reset.asBool) { + when(!Module.reset.asBool) { pushCommand(Stop(stp, sourceInfo, Builder.forcedClock.ref, code)) } stp } /** Named class for [[stop]]s. */ - final class Stop private[chisel3]()extends VerificationStatement + final class Stop private[chisel3] () extends VerificationStatement } /** Base class for all verification statements: Assert, Assume, Cover, Stop and Printf. */ @@ -220,8 +300,16 @@ private object VerificationStatement { } // creates a printf to inform the user of a failed assertion or assumption - def failureMessage(kind: String, lineInfo: SourceLineInfo, cond: Bool, message: Option[String], data: Seq[Bits]) - (implicit sourceInfo: SourceInfo, compileOptions: CompileOptions) : Unit = { + def failureMessage( + kind: String, + lineInfo: SourceLineInfo, + cond: Bool, + message: Option[String], + data: Seq[Bits] + )( + implicit sourceInfo: SourceInfo, + compileOptions: CompileOptions + ): Unit = { val (filename, line, content) = lineInfo val lineMsg = s"$filename:$line $content".replaceAll("%", "%%") val fmt = message match { @@ -230,7 +318,7 @@ private object VerificationStatement { case None => s"$kind failed\n at $lineMsg\n" } when(!cond) { - printf.printfWithoutReset(fmt, data:_*) + printf.printfWithoutReset(fmt, data: _*) } } } |
