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
32class SubstituteStructures : public Transform {
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
64class UnnestSelectList : public Transform {
65 // Represent the nesting of lists inside of a selectExpression.
66 // E.g.: [__[__]_] for two nested lists.
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
83class SimplifySelectList : public PassManager {
84 public:
85 SimplifySelectList(ReferenceMap *refMap, TypeMap *typeMap,
86 TypeChecking *typeChecking = nullptr) {
87 if (!typeChecking) typeChecking = new TypeChecking(refMap, typeMap);
88 passes.push_back(typeChecking);
89 passes.push_back(new SubstituteStructures(typeMap));
90 passes.push_back(typeChecking);
91 passes.push_back(new UnnestSelectList);
92 setName("SimplifySelectList");
93 }
94};
95
96} // namespace P4
97
98#endif /* MIDEND_SIMPLIFYSELECTLIST_H_ */
Definition externInstance.h:33
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition simplifySelectList.h:83
Definition simplifySelectList.h:32
Definition typeChecker.h:60
Definition typeMap.h:42
Definition simplifySelectList.h:64
Definition cstring.h:72
Definition applyOptionsPragmas.cpp:24