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

Fix bmv2/json generation crashes for p4_16 code converted from p4_14 #124

Merged
merged 1 commit into from
Oct 31, 2016

Conversation

ChrisDodd
Copy link
Contributor

  • refactor the code, moving repeated arguments into the JsonConverter
    object
  • support for Tuple types
  • support for nested structs
  • skips things related to checksums that were crashing (TODO)

result->emplace("name", nameFromAnnotation(st->annotations, st->name.name));
result->emplace("id", nextId("header_types"));
auto fields = mkArrayField(result, "fields");
void JsonConverter::pushFields(cstring prefix, const IR::Type_StructLike *st,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this works - the rest of the code won't handle correctly references to the inner struct. Consider:

struct S { bit x; }
struct T { S s1; S s2; }
T t;
t.s1 = t.s2;

I think that we need additional passes to properly rewrite the code that may access the inner structures.

I am also not sure this will properly handle arrays within structs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this just covers not crashing in the json generation -- it won't generate correct json for things like struct assignments that bmv2 can't handle (or more precisely, it will generate json with struct assignments that bmv2 will then reject). Actually handling struct (and tuple) assignment requires breaking them down into multiple assignments, which is a problem for tuples as we don't have a P4 syntax for accessing a field out of a tuple.

field->append(8 - padding);
field->append(false);
}
return result;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you want to add padding except for the outer struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When it's a struct of headers, each header needs to be individually padded out to bytes. When it's just metadata I don't think any padding is required, but it was being done anyway before.

return name;
}

cstring JsonConverter::createJsonType(const IR::Type_Tuple *tt) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this interact correctly with functions which expect a field_list? Field lists are compiled into tuples, which here are converted into structs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should only be called for things that are being converted into bmv2 actions (where the bmv2 is expected to evaluate the expressions), which need to be structs as it doesn't understand tuples. Builtin things (extern methods) should not end calling this.

- refactor the code, moving repeated arguments into the JsonConverter
  object
- support for Tuple types
- support for nested structs
- skips things related to checksums that were crashing (TODO)
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