P4C
The P4 Compiler
Loading...
Searching...
No Matches
simplifySelectList.h
1
/*
2
Copyright 2017 VMware, Inc.
3
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7
8
http://www.apache.org/licenses/LICENSE-2.0
9
10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations 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
24
namespace
P4
{
25
31
class
SubstituteStructures
:
public
Transform
{
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
63
class
UnnestSelectList
:
public
Transform
{
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,
71
IR::Vector<IR::Expression>
*output);
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
83
class
SimplifySelectList
:
public
PassManager
{
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_ */
P4::IR::Node
Definition
node.h:94
P4::IR::Vector
Definition
vector.h:59
P4::PassManager
Definition
ir/pass_manager.h:40
P4::SimplifySelectList
Definition
simplifySelectList.h:83
P4::SubstituteStructures
Definition
simplifySelectList.h:31
P4::Transform
Definition
visitor.h:424
P4::TypeChecking
Definition
typeChecker.h:55
P4::TypeMap
Definition
typeMap.h:41
P4::UnnestSelectList
Definition
simplifySelectList.h:63
P4::cstring
Definition
cstring.h:85
P4
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition
applyOptionsPragmas.cpp:24
midend
simplifySelectList.h
Generated by
1.12.0