Closed hesingh closed 4 years ago
A correction to Andy's previous comment: bmv2 already supports dynamic indices for header stacks. This is done using the
dereference_header_stack
binary operand in the bmv2 JSON (see the doc), which takes as parameters the name of the header stack and an expression evaluating to a valid index for that header stack.
Now that I changed p4c bmv2 backend to support dynamic indices, the expression is a JsonObject. If you see this behavioral-model code,
the code is incomplete to handle a expression if the expression type is objectValue. asString() fails on this line of code:
with type_ == 7 which is objectValue. So, even this json code is incomplete.
If you believe you have a BMv2 JSON file that contains what you've been told is correct for variable array indices, and it is leading to some kind of misbehavior in simple_switch, I would recommend creating a separate issue for the behavioral-model repo, attach the BMv2 JSON file you think should work, and details about what is going wrong.
I do think the JSON file from new p4c code with expression as a JsonObject is correct and the beharioral-model should support the expression being a JsonObject. I have filed this issue.
I am using a header stack in v1model p4-16 code. The index into the header stack array is obtained from a header in the packet and index copied to metadata. Obviously, the header is parsed in the parser. p4c-bm2-ss fails because the index is not a compile-time constant. So, how is such code supposed to work? The p4test backend does not care and compiles the code fine.