Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to tell if hcl.assert_ fired programmatically? #413

Open
jcasas00 opened this issue Sep 2, 2021 · 6 comments
Open

How to tell if hcl.assert_ fired programmatically? #413

jcasas00 opened this issue Sep 2, 2021 · 6 comments

Comments

@jcasas00
Copy link

jcasas00 commented Sep 2, 2021

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) ?

@seanlatias
Copy link
Collaborator

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.

@seanlatias
Copy link
Collaborator

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

@jcasas00
Copy link
Author

jcasas00 commented Sep 2, 2021

Yes, this is pretty much what I was envisioning.

@seanlatias
Copy link
Collaborator

Please check #414. Now it is merged.

@jcasas00
Copy link
Author

jcasas00 commented Sep 7, 2021

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)?

@seanlatias
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants