Open pataei opened 1 year ago
discussed this with Ryan and we're wondering why P4 limits the underlying type of an enum to bit<W>
and int<W>
, instead of limiting them to be int<exp>
or ibt<exp>
and requiring exp
to be compile-time-known. @jnfoster do you know?
This isn't the only place where P4 spec is more restrictive for fixed-length integers. See #397
Petr4 defines a wider range of enum as well-formed compared to P4 spec. Specifically, Petr4 only checks that the underlying type is well-formed whereas P4 spec states that the underlying type can only be one of
bit<w>
,int<w>
, or a type name defined bytypedef
where the base type is a fixed-length (signed or unsigned) integer. Note that Petr4 does check this when a serializable enum is being defined.Petr4 code
The following is the related block of code for checking if a type is well-formed:
The following is the block of code for declaring a serializable enum, however, even here Petr4 doesn't check that the argument passed to the underlying type is constant, that is, Petr4 allows
bit<exp>
as the underlying type whereas P4 spec only allowsbit<w>
:P4 spec (v1.2.3)
Enumeration types states that: "The symbol typeRef in the grammar above must be one of the following types:
Quick fix
Add the check of
assert_runtime_numeric
and define a helper such asis_constant
that checks thatexp
inbit<exp>
orint<exp>
is a constant.