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