45 class EmptyStatementRemover final :
public Transform {
47 EmptyStatementRemover() {}
48 const IR::Node *postorder(IR::EmptyStatement *statement)
override;
49 const IR::Node *postorder(IR::BlockStatement *statement)
override;
57 class ExpressionReplacer final :
public Transform {
60 const IR::AssignmentStatement *statement;
63 const std::vector<bool> &traversalPath;
65 std::vector<const IR::Expression *> &conditions;
67 unsigned currentNestingLevel = 0;
69 bool visitingIndex =
false;
72 explicit ExpressionReplacer(
const IR::AssignmentStatement *a, std::vector<bool> &t,
73 std::vector<const IR::Expression *> &c)
74 : statement(a), traversalPath(t), conditions(c) {
77 const IR::Mux *preorder(IR::Mux *mux)
override;
78 void emplaceExpression(IR::Mux *mux);
79 void visitBranch(IR::Mux *mux,
bool then);
80 void setVisitingIndex(
bool val);
86 EmptyStatementRemover remover;
89 bool modifyIndex =
false;
91 unsigned ifNestingLevel;
93 unsigned depNestingLevel;
97 std::vector<cstring> dependentNames;
100 std::vector<bool> traversalPath;
101 std::vector<cstring> dependencies;
104 std::map<cstring, const IR::AssignmentStatement *> liveAssignments;
108 std::vector<const IR::AssignmentStatement *> liveAssigns;
111 std::vector<const IR::Declaration *> indexDeclarations;
115 std::map<cstring, bool> isStatementDependent;
116 const IR::Statement *error(
const IR::Statement *statement)
const {
117 if (inside_action && ifNestingLevel > 0)
119 "%1%: Conditional execution in actions unsupported on this target",
125 explicit Predication() : inside_action(
false), ifNestingLevel(0), depNestingLevel(0) {
126 setName(
"Predication");
129 auto rv = Transform::init_apply(node);
130 node->apply(generator);
135 const IR::Expression *clone(
const IR::Expression *expression);
136 const IR::Node *clone(
const IR::AssignmentStatement *statement);
137 const IR::Node *preorder(IR::IfStatement *statement)
override;
138 const IR::Node *preorder(IR::P4Action *action)
override;
139 const IR::Node *postorder(IR::P4Action *action)
override;
140 const IR::Node *preorder(IR::AssignmentStatement *statement)
override;
142 const IR::Node *preorder(IR::PathExpression *pathExpr)
override;
143 const IR::Node *preorder(IR::Member *member)
override;
144 const IR::Node *preorder(IR::ArrayIndex *arrInd)
override;
146 const IR::Node *postorder(IR::MethodCallStatement *statement)
override {
147 return error(statement);
149 const IR::Node *postorder(IR::ReturnStatement *statement)
override {
return error(statement); }
150 const IR::Node *postorder(IR::ExitStatement *statement)
override {
return error(statement); }
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:51