-
Notifications
You must be signed in to change notification settings - Fork 445
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
Add support for verify statements in bmv2 backend #234
Conversation
With version 2.1, the bmv2 JSON supports declaring parser errors as well as verify statements in the parser's body. See https://github.com/p4lang/behavioral-model/pull/259/files#diff-418314966c57fea403ba29bf6b0793c7 for more information. In this pull request, we add a visitor pass which assigns a numerical value to each error declared in the P4 input. The mapping error name <-> value is added to the JSON under the 'errors' key. verify statements are then handled when converting parser states to JSON, as per the bmv2 JSON description. Later on, we will be able to handle references to error constants in expressions in controls. This will be done by substituting the numerical value for the error constant in expressions, and otherwise using regular bmv2 expressions. The error code produced by the parser will need to be exposed as a metadata field though. So for now only references to error constants in verify statements are supported.
@mbudiu-vmw please let me know if I didn't implement this in a satisfactory way |
} | ||
{ | ||
auto error = mce->arguments->at(1); | ||
BUG_CHECK(error->is<IR::Member>(), "Error when processing verify"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be an ::error instead of a bug. One can declare variables with an error type, and one could use here an expression with an error result. The ::error message should indicate that only constant error values are supported in verify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in #243
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, though I agree with Mihai's comment about error vs BUG_CHECK -- if the user could write a program that causes that, it should be an error. BUG_CHECK is for internal compiler consistency checks that should never happen.
@ChrisDodd I was going to add the requested fix today... I guess I'll open a new PR |
As requested in review for PR #234
As requested in review for PR #234
As requested in review for PR #234
With version 2.1, the bmv2 JSON supports declaring parser errors as well
as verify statements in the parser's body. See
https://github.com/p4lang/behavioral-model/pull/259/files#diff-418314966c57fea403ba29bf6b0793c7
for more information.
In this pull request, we add a visitor pass which assigns a numerical
value to each error declared in the P4 input. The mapping error name <->
value is added to the JSON under the 'errors' key. verify statements are
then handled when converting parser states to JSON, as per the bmv2 JSON
description.
Later on, we will be able to handle references to error constants in
expressions in controls. This will be done by substituting the numerical
value for the error constant in expressions, and otherwise using regular
bmv2 expressions. The error code produced by the parser will need to be
exposed as a metadata field though. So for now only references to error
constants in verify statements are supported.