p4lang / p4c

P4_16 reference compiler
https://p4.org/
Apache License 2.0
673 stars 444 forks source link

Example P4 program with for loop iterating over elements of list that is unrolled? #4966

Open jafingerhut opened 2 weeks ago

jafingerhut commented 2 weeks ago

I have not yet found an example of a loop starting with for (typeRef var in listExpr) { ... } that is unrolled.

It seems like that kind of loop would be the easiest to unroll, since the exact number of iterations is guaranteed to be a compile-time constant value, i.e. the number of elements in the list expression, and all P4 list expressions have a compile-time known number of elements.

ChrisDodd commented 2 weeks ago

currently the ForInLoop code in unrollLoops can only handle ranges. Adding lists of integers should be trivial -- lists of complex things would be trickier.