-
Notifications
You must be signed in to change notification settings - Fork 449
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
Generalized array support #5115
base: main
Are you sure you want to change the base?
Conversation
74a47dc
to
618c817
Compare
Relax the requirement that IR::Type_Stack element types are headers, which allows using arrays of any type, though non-headers cannot support push/pop/last/next stuff which looks at header valid bits. Signed-off-by: Chris Dodd <[email protected]>
- this allows declaring arrays as in C (eg, `bit<8> data[16];`) rather than in the java style previously required (`bit<8> [16] data;`) Signed-off-by: Chris Dodd <[email protected]>
Nice! The test cases look interesting. As usual (unforunately), I haven't attempted to review the C++ implementation code. What is the behavior if you attempt to use an index expression that is not a compile-time known value? I could imagine trying to allow that if the index expression type was |
The frontend/midend won't do anything about it, but I would imaging that many targets would be unable to support non-constant indexes and the backend would reject it. It is not clear what a target that could support non-constant indexes could/should do about out of range indexes. In all of this, an array is the same as a header stack. This really just makes header stacks a special case of arrays -- they support some additional functions that arrays of non-header/header union types do not. |
Signed-off-by: Chris Dodd <[email protected]>
629eb4e
to
176cee2
Compare
header data_t { | ||
bit<32> f1; | ||
bit<32> f2; | ||
bit<16> h1; | ||
bit<16> h2; | ||
bit<8>[16] arr; | ||
} |
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.
Could you please add positive and/or error test cases similar to the following to demonstrate what is expected when the array type is an array type or contains array types?
struct S {
bit<16> f1;
bit<8>[16] nested_arr;
bit<16> f2;
}
header data_t {
bit<32> f1;
bit<32> f2;
bit<16> h1;
bit<16> h2;
S[16] arr;
}
...
hdr.data.arr[x].nested_arr[y] = ...;
... = hdr.data.arr[z].nested_arr[w];
...
and (if the grammar allows it (I did not look very closely at changes to p4parser.ypp
)):
header data_t {
bit<32> f1;
bit<32> f2;
bit<16> h1;
bit<16> h2;
bit<8>[16][16] arr;
}
...
hdr.data.arr[x][y] = ...;
... = hdr.data.arr[z][w];
...
First change relaxes frontend checks to allow arrays in general as per p4lang/p4-spec#1320. Non-header arrays only support indexing, not any other header stack operations
Second change adds support for C-style array declarators, with the array size after the name instead of before it.