P4C
The P4 Compiler
 
Loading...
Searching...
No Matches
P4::DoRemoveParserControlFlow Class Reference

Converts if statements in parsers into transitions. More...

Inheritance diagram for P4::DoRemoveParserControlFlow:

Public Member Functions

 DoRemoveParserControlFlow (ReferenceMap *refMap)
 
Visitor::profile_t init_apply (const IR::Node *node) override
 
const IR::Node * postorder (IR::ParserState *state) override
 

Detailed Description

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;
}
Precondition
Must be run after MoveDeclarations. Requires an up-to-date ReferenceMap.
Postcondition
No if statements remain in parsers.