-
Notifications
You must be signed in to change notification settings - Fork 444
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
[WIP] Add example implementation for bounded foreach-style loops #4558
Conversation
No sema, no tests, just straight implementation
Tagging @jafingerhut and @ChrisDodd |
@@ -231,6 +231,7 @@ inline std::ostream& operator<<(std::ostream& out, const P4::Token& t) { | |||
ELSE ENTRIES ENUM ERROR EXIT EXTERN HEADER HEADER_UNION IF IN INOUT | |||
INT KEY LIST SELECT MATCH_KIND TYPE OUT PACKAGE PARSER PRAGMA PRIORITY RETURN | |||
STATE STRING STRUCT SWITCH TABLE TRANSITION TUPLE TYPEDEF VARBIT VALUESET VOID | |||
%token<Token> FOREACH BREAK CONTINUE |
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.
This is structured in a way to simplify review. It could be merged into the token list above
Another part missed here from downstream: type inference check that types of loop index variable is compatible with the range. |
Are the changes here merged into #4562? Can this be closed? |
There were minor syntax changes ( |
For #4120 and p4lang/p4-spec#1261
This is an example implementation for foreach-style bounded loops. It contains no tests (as they are written for dowstream backend) and some sema checks are certainly lacking, but still shows the intention. One thing that is currently missed is the use-def changes, I have not ported them to upstream, but will re-add shortly. Certainly changes to other passes might be required (e.g. copyprop).
The PR has some tricks how to handle loop index variable in order to play nicely with the existing code.
Examples of supported code: