
Public Member Functions | |
| DoEliminateSwitch (ReferenceMap *refMap, const TypeMap *typeMap) | |
| const IR::Node * | postorder (IR::P4Control *control) override |
| const IR::Node * | postorder (IR::P4Program *program) override |
| const IR::Node * | postorder (IR::SwitchStatement *statement) override |
Public Attributes | |
| bool | exactNeeded = false |
Replaces switch statements that operate on arbitrary scalars with switch statements that operate on actions by introducing a new table.
switch (expression) { 1: { ... } 2: 3: { ... } 4: { ... } default: { ... } }
This generates the following program:
ExpressionType switch1_key;
@hidden action switch1_case_1 () { no statements here, by design } @hidden action switch1_case_23 () {} @hidden action switch1_case_4 () {} @hidden action switch1_case_default () {} @hidden table switch1_table { key = { switch1_key : exact; } actions = { switch1_case_1; switch1_case_23; switch1_case_4; switch1_case_default; } const entries = { 1 : switch1_case_1; 2 : switch1_case_23; 3 : switch1_case_23; 4 : switch1_case_4; } const default_action = switch1_case_default; }
later in the control's apply block, where the original switch statement appeared: switch1_key = expression; switch (switch1_table.apply().action_run) { switch1_case_1: { ... } switch1_case_23: { ... } switch1_case_4: { ... } switch1_case_default: { ... } }