@@ -800,28 +800,18 @@ by the design of the hardware.
800
800
801
801
### Restrictions on code within actions
802
802
803
- These restrictions are actually restrictions of the ` p4c ` compiler, not of
804
- ` simple_switch ` . Anyone interested in enhancing ` p4c ` to remove these
805
- restrictions should see the issues below.
803
+ After 2024-Nov-08 when this change was made to the ` p4c ` BMv2 back
804
+ end:
806
805
807
- The P4_16 language specification v1.1.0 permits ` if ` statements within action
808
- declarations. ` p4c ` , when compiling for the target BMv2 simple_switch, supports
809
- some kinds of ` if ` statements, in particular ones that can be transformed into
810
- assignments using the ternary ` condition ? true_expr : false_expr ` operator.
811
- This is supported:
806
+ + https://github.com/p4lang/p4c/pull/4999
812
807
813
- ```
814
- action foo() {
815
- meta.b = meta.b + 5;
816
- if (hdr.ethernet.etherType == 7) {
817
- hdr.ethernet.dstAddr = 1;
818
- } else {
819
- hdr.ethernet.dstAddr = 2;
820
- }
821
- }
822
- ```
808
+ arbitrary ` if ` statements, even ` if ` statements nested within other
809
+ ` if ` statements, should be supported correctly.
823
810
824
- but this is not, as of 2022-Jan-18:
811
+ Before that change was made to ` p4c ` , there were significant
812
+ restrictions on the kinds of ` if ` statements that were supported
813
+ within the bodies of a P4 ` action ` , when compiling for BMv2. For
814
+ example, the following ` action ` definition was not supported:
825
815
826
816
```
827
817
action foo() {
@@ -834,24 +824,6 @@ but this is not, as of 2022-Jan-18:
834
824
}
835
825
```
836
826
837
- Given the following text from the P4_16 language specification, it is likely
838
- that there are other P4 implementations that have limited or no support for ` if `
839
- statements within actions:
840
-
841
- No `switch` statements are allowed within an action --- the grammar permits
842
- them, but a semantic check should reject them. Some targets may impose
843
- additional restrictions on action bodies --- e.g., only allowing
844
- straight-line code, with no conditional statements or expressions.
845
-
846
- Thus P4 programs using ` if ` statements within actions are likely to be less
847
- portable than programs that avoid doing so.
848
-
849
- As mentioned above, enhancing ` p4c ` would enable a larger variety of ` if `
850
- statements within actions to be supported.
851
-
852
- * [ p4c issue #644 ] ( https://github.com/p4lang/p4c/issues/644 )
853
- * [ behavioral-model issue #379 ] ( https://github.com/p4lang/behavioral-model/pull/379 )
854
-
855
827
856
828
### Restrictions on code in the ` ComputeChecksum ` control
857
829
0 commit comments