cornell-zhang/heterocl

How to tell if hcl.assert_ fired programmatically?

jcasas00 opened this issue · 6 comments

hcl.assert_ terminates the LLVM execution when it fires. However, there doesn't seem to be any indication at the top-level that the hcl.assert_ fired. Can it raise an exception HCLAssert (for example) ?

Hmmmm... I'll see if I can enable the return value of the top function. If the return value is non-zero then the program is wrong.

@jcasas00 I proposed a solution in #414. Please see if this is similar to what you have in mind.

Yes, this is pretty much what I was envisioning.

Please check #414. Now it is merged.

I tried #414 and it indeed raises an exception.
One thing though, while the assert error message is printed, the string associated with the caught exception seem to be always "[Assert] Assert Failed!!!" (which we already know by being in the except block). Is it possible to have the actual assertion message also be passed to the exception object?

For example:

    try:
        f(dram, addr)
    except hcl.debug.AssertError as e:
        print ("Got exception: " + str(e))

Output:

Invalid index=3                                                # this is printed by the hcl.assert_
Got exception: [Assert] Assert Failed!!             # could str(e) also be the same assert_ message string (instead of printing)?

Right, ideally we want to return the error message. For now, it would take some extra work to implement that. I'll mark it as enhancement.