Skip to content

Commit

Permalink
verification: guard statements with module reset (#1891) (#1892)
Browse files Browse the repository at this point in the history
(cherry picked from commit 4d8fed0)

Co-authored-by: Kevin Laeufer <laeufer@cs.berkeley.edu>
  • Loading branch information
mergify[bot] and ekiwi authored Apr 29, 2021
1 parent ed51be7 commit 3897ba4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
24 changes: 13 additions & 11 deletions core/src/main/scala/chisel3/experimental/verification/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

package chisel3.experimental

import chisel3.{Bool, CompileOptions}
import chisel3._
import chisel3.internal.Builder
import chisel3.internal.Builder.pushCommand
import chisel3.internal.firrtl.{Formal, Verification}
import chisel3.internal.sourceinfo.SourceInfo

Expand All @@ -13,29 +12,32 @@ package object verification {
def apply(predicate: Bool, msg: String = "")(
implicit sourceInfo: SourceInfo,
compileOptions: CompileOptions): Unit = {
val clock = Builder.forcedClock
pushCommand(Verification(Formal.Assert, sourceInfo, clock.ref,
predicate.ref, msg))
when (!Module.reset.asBool) {
val clock = Module.clock
Builder.pushCommand(Verification(Formal.Assert, sourceInfo, clock.ref, predicate.ref, msg))
}
}
}

object assume {
def apply(predicate: Bool, msg: String = "")(
implicit sourceInfo: SourceInfo,
compileOptions: CompileOptions): Unit = {
val clock = Builder.forcedClock
pushCommand(Verification(Formal.Assume, sourceInfo, clock.ref,
predicate.ref, msg))
when (!Module.reset.asBool) {
val clock = Module.clock
Builder.pushCommand(Verification(Formal.Assume, sourceInfo, clock.ref, predicate.ref, msg))
}
}
}

object cover {
def apply(predicate: Bool, msg: String = "")(
implicit sourceInfo: SourceInfo,
compileOptions: CompileOptions): Unit = {
val clock = Builder.forcedClock
pushCommand(Verification(Formal.Cover, sourceInfo, clock.ref,
predicate.ref, msg))
val clock = Module.clock
when (!Module.reset.asBool) {
Builder.pushCommand(Verification(Formal.Cover, sourceInfo, clock.ref, predicate.ref, msg))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,15 @@ class VerificationSpec extends ChiselPropSpec {
property("basic equality check should work") {
val fir = ChiselStage.emitChirrtl(new VerificationModule)
val lines = fir.split("\n").map(_.trim)

// reset guard around the verification statement
assertContains(lines, "when _T_2 : @[VerificationSpec.scala 16:15]")
assertContains(lines, "cover(clock, _T, UInt<1>(\"h1\"), \"\") @[VerificationSpec.scala 16:15]")
assertContains(lines, "assume(clock, _T_2, UInt<1>(\"h1\"), \"\") @[VerificationSpec.scala 18:18]")
assertContains(lines, "assert(clock, _T_3, UInt<1>(\"h1\"), \"\") @[VerificationSpec.scala 19:18]")

assertContains(lines, "when _T_6 : @[VerificationSpec.scala 18:18]")
assertContains(lines, "assume(clock, _T_4, UInt<1>(\"h1\"), \"\") @[VerificationSpec.scala 18:18]")

assertContains(lines, "when _T_9 : @[VerificationSpec.scala 19:18]")
assertContains(lines, "assert(clock, _T_7, UInt<1>(\"h1\"), \"\") @[VerificationSpec.scala 19:18]")
}
}

0 comments on commit 3897ba4

Please # to comment.