Add statement splitter utility#5158
Conversation
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
|
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.
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.
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 <vladimir.still@altera.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
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
beforestatement, while the rest (starting from the matching statemet) is in anafterstatement.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: