lkolbly / ripstop

Apache License 2.0
0 stars 0 forks source link

Runtime Assertions #13

Open lkolbly opened 2 years ago

lkolbly commented 2 years ago

In #12 we introduced the notion of assertions which are checked at simulation time. But, we can also synthesize the assertion logic, and check it at runtime (a so-called "debug" build). Broadly speaking, in debug builds, we would add an asserted output to every module. An assert(x) call would synthesize into a latch, something like:

if x[t-1] {
   assert[t] = 1;
}

Once the line asserts, it never de-asserts (until reset). Additionally, a module's assert line triggers if any instantiated sub-modules assert: This enables the user to monitor the top-level assert line to see if any module asserts.

We can also add a traceback to indicate which module asserted. For example, a 31-bit integer which goes along with the assert line. Every assert would have a unique identifier which gets assigned when it asserts - we can provide a debug tool which reads the 31-bit integer and a map file to provide the exact line number of the assertion:

$ ripstop decode-assert my-map.map 0x123456
Condition `assert(x > 5)` failed in some_module.rp:321
Module hierarchy:
- top_module:top.rp:43
- some_lower_module as foobar#5:top.rp:901
- leaf as leaf0:some_module.rp:321