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

Add support for verify statements in bmv2 backend #234

Merged
merged 1 commit into from
Jan 18, 2017

Conversation

antoninbas
Copy link
Member

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.

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.
@antoninbas
Copy link
Member Author

@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");
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in #243

Copy link
Contributor

@ChrisDodd ChrisDodd left a 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 ChrisDodd merged commit 644aa90 into master Jan 18, 2017
@antoninbas
Copy link
Member Author

@ChrisDodd I was going to add the requested fix today... I guess I'll open a new PR

antoninbas added a commit that referenced this pull request Jan 19, 2017
antoninbas added a commit that referenced this pull request Jan 19, 2017
ChrisDodd pushed a commit that referenced this pull request Jan 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants