Search code examples
riscvchisel

How to make assertions in Chisel be just warnings and not stop simulation


We have added assertions to our Chisel code, but we only want them to warn, not stop the simulation. Is there a way to tell Chisel to do this?

For example:

assert(x(1) =/= nxt_val(1))

We want this to just give us a warning, so we can collect the log, to find places where clock gating is most effective.


Solution

  • Can you just write a method that you pass the condition and perhaps a behavior flag.

    object warnAssert {
      def apply(condition: Bool, message: String = "", isFatal: Boolean = false) {
        (isFatal, message.isEmpty) {
          case (true, true)   => assert(condition)
          case (true, false)  => assert(condition, message)
          case (false, _) => when(bool) { printf("Warning: %s\n", message) // line number should get included here
        }
      }
    }