P4C
The P4 Compiler
Loading...
Searching...
No Matches
removeComplexExpressions.h
1/*
2Copyright 2013-present Barefoot Networks, Inc.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef MIDEND_REMOVECOMPLEXEXPRESSIONS_H_
18#define MIDEND_REMOVECOMPLEXEXPRESSIONS_H_
19
20#include "frontends/common/resolveReferences/resolveReferences.h"
21#include "frontends/p4/typeMap.h"
22#include "ir/ir.h"
23
24namespace P4 {
25
31 public:
37 virtual bool convert(const IR::P4Control *control) const = 0;
38};
39
46 public:
48 P4::TypeMap *typeMap;
52
53 explicit RemoveComplexExpressions(P4::TypeMap *typeMap,
54 RemoveComplexExpressionsPolicy *policy = nullptr)
55 : typeMap(typeMap), policy(policy) {
56 CHECK_NULL(typeMap);
57 setName("RemoveComplexExpressions");
58 }
59 Visitor::profile_t init_apply(const IR::Node *node) override {
60 auto rv = Transform::init_apply(node);
61 node->apply(nameGen);
62
63 return rv;
64 }
65
66 const IR::PathExpression *createTemporary(const IR::Expression *expression);
67 const IR::Expression *simplifyExpression(const IR::Expression *expression, bool force);
68 const IR::Vector<IR::Expression> *simplifyExpressions(const IR::Vector<IR::Expression> *vec,
69 bool force = false);
70 const IR::Vector<IR::Argument> *simplifyExpressions(const IR::Vector<IR::Argument> *vec);
71 const IR::IndexedVector<IR::NamedExpression> *simplifyExpressions(
73
74 const IR::Node *simpleStatement(IR::Statement *statement);
75
76 const IR::Node *postorder(IR::SelectExpression *expression) override;
77 const IR::Node *preorder(IR::ParserState *state) override {
78 assignments.clear();
79 return state;
80 }
81 const IR::Node *postorder(IR::ParserState *state) override {
82 state->components.append(assignments);
83 return state;
84 }
85 const IR::Node *postorder(IR::MethodCallExpression *expression) override;
86 const IR::Node *preorder(IR::P4Parser *parser) override {
87 newDecls.clear();
88 return parser;
89 }
90 const IR::Node *postorder(IR::P4Parser *parser) override {
91 if (newDecls.size() != 0) {
92 // prepend declarations
93 newDecls.append(parser->parserLocals);
94 parser->parserLocals = newDecls;
95 }
96 return parser;
97 }
98 const IR::Node *preorder(IR::P4Control *control) override;
99 const IR::Node *postorder(IR::P4Control *control) override {
100 if (newDecls.size() != 0) {
101 // prepend declarations
102 newDecls.append(control->controlLocals);
103 control->controlLocals = newDecls;
104 }
105 return control;
106 }
107 const IR::Node *postorder(IR::Statement *statement) override;
108 const IR::Node *postorder(IR::MethodCallStatement *statement) override;
109};
110
111} // namespace P4
112
113#endif /* MIDEND_REMOVECOMPLEXEXPRESSIONS_H_ */
Definition node.h:52
Definition node.h:94
Definition vector.h:59
Definition referenceMap.h:36
Definition removeComplexExpressions.h:45
Definition removeComplexExpressions.h:30
virtual bool convert(const IR::P4Control *control) const =0
Visitor mixin for looking up names in enclosing scopes from the Visitor::Context.
Definition resolveReferences.h:35
Definition visitor.h:424
Definition typeMap.h:41
Definition visitor.h:78
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24