P4C
The P4 Compiler
Loading...
Searching...
No Matches
simplifySelectList.h
1/*
2Copyright 2017 VMware, 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_SIMPLIFYSELECTLIST_H_
18#define MIDEND_SIMPLIFYSELECTLIST_H_
19
20#include "frontends/p4/typeChecking/typeChecker.h"
21#include "frontends/p4/typeMap.h"
22#include "ir/ir.h"
23
24namespace P4 {
25
32 TypeMap *typeMap;
33
34 void explode(const IR::Expression *expression, const IR::Type *type,
35 IR::Vector<IR::Expression> *components);
36
37 public:
38 explicit SubstituteStructures(TypeMap *typeMap) : typeMap(typeMap) {
39 CHECK_NULL(typeMap);
40 setName("SubstituteStructures");
41 }
42
43 const IR::Node *postorder(IR::PathExpression *expression) override;
44};
45
64 // Represent the nesting of lists inside of a selectExpression.
65 // E.g.: [__[__]_] for two nested lists.
66 // FIXME: Lots of terrible concatenations here, must be std::string
67 cstring nesting;
68
69 void flatten(const IR::Expression *expression, IR::Vector<IR::Expression> *output);
70 void flatten(const IR::Expression *expression, unsigned *nestingIndex,
72
73 public:
74 UnnestSelectList() { setName("UnnestSelectList"); }
75
76 const IR::Node *preorder(IR::SelectExpression *expression) override;
77 const IR::Node *preorder(IR::P4Control *control) override {
78 prune();
79 return control;
80 }
81};
82
84 public:
85 explicit SimplifySelectList(TypeMap *typeMap, TypeChecking *typeChecking = nullptr) {
86 if (!typeChecking) typeChecking = new TypeChecking(nullptr, typeMap);
87 passes.push_back(typeChecking);
88 passes.push_back(new SubstituteStructures(typeMap));
89 passes.push_back(typeChecking);
90 passes.push_back(new UnnestSelectList);
91 setName("SimplifySelectList");
92 }
93};
94
95} // namespace P4
96
97#endif /* MIDEND_SIMPLIFYSELECTLIST_H_ */
Definition node.h:95
Definition vector.h:59
Definition ir/pass_manager.h:40
Definition simplifySelectList.h:83
Definition simplifySelectList.h:31
Definition visitor.h:424
Definition typeChecker.h:55
Definition typeMap.h:41
Definition simplifySelectList.h:63
Definition cstring.h:85
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24