-
Notifications
You must be signed in to change notification settings - Fork 454
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
Add statement splitter utility #5158
Conversation
Signed-off-by: Vladimír Štill <[email protected]>
Signed-off-by: Vladimír Štill <[email protected]>
Signed-off-by: Vladimír Štill <[email protected]>
Signed-off-by: Vladimír Štill <[email protected]>
Signed-off-by: Vladimír Štill <[email protected]>
Signed-off-by: Vladimír Štill <[email protected]>
Would try to enable this with p4test just to see whether there are any failures. Excluding ref file mismatches ofc. Edit: Oh I see, this is a very targeted pass. Hard to test broadly. In your example, the input would be the particular |
Yes, it is not even a pass that is exposed, just the function. Intended to be used in other passes. In the example, condition would be something like [](const auto *stmt, const auto *) {
if (const auto *mcs = stmt->to<IR::MethodCallStatement>()) {
if (const auto *apply = P4::MethodCall::resolve(mcs, refMap)->to<P4::ApplyMethod>()) {
return apply->apllyObject->is<IR::P4Table>();
}
}
return false;
} |
return false; | ||
} | ||
|
||
for (size_t i = 0, sz = bs->components.size(); i < sz; i++) { |
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.
We generally prefer C++ for statements like
for (auto &el : bc->components) {
here the &
in only necessary in a Transform/Modifier where you're changing the block statement. In an Inspector you can leave it out.
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.
yes, but I do need the index in the body of the loop, and in absence of a good range adapter like Python's enumerate
, I prefer to fall back to C style loop in this cases, compared to e.g. using pointer distance to recover the index.
Signed-off-by: Vladimír Štill <[email protected]>
Signed-off-by: Vladimír Štill <[email protected]>
Signed-off-by: Vladimír Štill <[email protected]>
Signed-off-by: Vladimír Štill <[email protected]>
Add functionality for splitting statements. Split given statement so that on all control-flow paths all the statements up to the first one matching predicate are in a
before
statement, while the rest (starting from the matching statemet) is in anafter
statement.The visiting order is a bit tricky, but it should work for any code without loops and without non-spec branching constructs. Not currently used in P4C, but I think this is worth having as it can be useful for some targets.
E.g.
====>
splitting on table calls:
before:
after:
and finally hoisted declarations: