Skip to content
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 Doxygen comments for the ParserControlFlow pass. #551

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions frontends/p4/parserControlFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,6 @@ limitations under the License.

namespace P4 {

/* convert
state s {
statement1;
statement2;
if (exp)
statement3;
else
statement4;
statement5;
transition selectExpression;
}

into 4 states:

state s {
statement1;
statement2;
transition select(exp) {
true: s_true;
false: s_false;
}
}

state s_true {
statement3;
transition s_join;
}

state s_false {
statement4;
transition s_join;
}

state s_join {
statement5;
transition selectExpression;
}

*/

const IR::Node* DoRemoveParserControlFlow::postorder(IR::ParserState* state) {
LOG1("Visiting " << dbp(state));
// TODO: we keep annotations on the first state,
Expand Down
57 changes: 54 additions & 3 deletions frontends/p4/parserControlFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,57 @@ limitations under the License.

namespace P4 {

// Converts if statements in parsers into transitions.
// This should be run after variables have been moved to the "top" of
// the parser.
/** @brief Converts if statements in parsers into transitions.
*
* For example, this code snippet:
*
```
state s {
statement1;
statement2;
if (exp)
statement3;
else
statement4;
statement5;
transition selectExpression;
}
```
*
* would be converted into the following four states:
*
```
state s {
statement1;
statement2;
transition select(exp) {
true: s_true;
false: s_false;
}
}

state s_true {
statement3;
transition s_join;
}

state s_false {
statement4;
transition s_join;
}

state s_join {
statement5;
transition selectExpression;
}
```
*
* @pre Must be run after MoveDeclarations. Requires an up-to-date
* ReferenceMap.
*
* @post No if statements remain in parsers.
*/

class DoRemoveParserControlFlow : public Transform {
ReferenceMap* refMap;
public:
Expand All @@ -35,6 +83,9 @@ class DoRemoveParserControlFlow : public Transform {
Visitor::profile_t init_apply(const IR::Node* node) override;
};


/// Iterates DoRemoveParserControlFlow and SimplifyControlFlow until
/// convergence.
class RemoveParserControlFlow : public PassRepeated {
public:
RemoveParserControlFlow(ReferenceMap* refMap, TypeMap* typeMap) : PassRepeated({}) {
Expand Down