P4C
The P4 Compiler
Loading...
Searching...
No Matches
simplifySelectList.h
1
/*
2
* Copyright 2017 VMware, Inc.
3
* SPDX-FileCopyrightText: 2017 VMware, Inc.
4
*
5
* SPDX-License-Identifier: Apache-2.0
6
*/
7
8
#ifndef MIDEND_SIMPLIFYSELECTLIST_H_
9
#define MIDEND_SIMPLIFYSELECTLIST_H_
10
11
#include "frontends/p4/typeChecking/typeChecker.h"
12
#include "frontends/p4/typeMap.h"
13
#include "ir/ir.h"
14
15
namespace
P4
{
16
22
class
SubstituteStructures :
public
Transform
{
23
TypeMap
*typeMap;
24
25
void
explode(
const
IR::Expression *expression,
const
IR::Type *type,
26
IR::Vector<IR::Expression>
*components);
27
28
public
:
29
explicit
SubstituteStructures(
TypeMap
*typeMap) : typeMap(typeMap) {
30
CHECK_NULL(typeMap);
31
setName(
"SubstituteStructures"
);
32
}
33
34
const
IR::Node
*postorder(IR::PathExpression *expression)
override
;
35
};
36
54
class
UnnestSelectList :
public
Transform
{
55
// Represent the nesting of lists inside of a selectExpression.
56
// E.g.: [__[__]_] for two nested lists.
57
// FIXME: Lots of terrible concatenations here, must be std::string
58
cstring
nesting;
59
60
void
flatten(
const
IR::Expression *expression,
IR::Vector<IR::Expression>
*output);
61
void
flatten(
const
IR::Expression *expression,
unsigned
*nestingIndex,
62
IR::Vector<IR::Expression>
*output);
63
64
public
:
65
UnnestSelectList() { setName(
"UnnestSelectList"
); }
66
67
const
IR::Node
*preorder(IR::SelectExpression *expression)
override
;
68
const
IR::Node
*preorder(IR::P4Control *control)
override
{
69
prune();
70
return
control;
71
}
72
};
73
74
class
SimplifySelectList :
public
PassManager {
75
public
:
76
explicit
SimplifySelectList(
TypeMap
*typeMap,
TypeChecking
*typeChecking =
nullptr
) {
77
if
(!typeChecking) typeChecking =
new
TypeChecking
(
nullptr
, typeMap);
78
passes.push_back(typeChecking);
79
passes.push_back(
new
SubstituteStructures
(typeMap));
80
passes.push_back(typeChecking);
81
passes.push_back(
new
UnnestSelectList
);
82
setName(
"SimplifySelectList"
);
83
}
84
};
85
86
}
// namespace P4
87
88
#endif
/* MIDEND_SIMPLIFYSELECTLIST_H_ */
P4::IR::Node
Definition
node.h:53
P4::IR::Vector
Definition
ir/vector.h:59
P4::SubstituteStructures
Definition
simplifySelectList.h:22
P4::Transform
Definition
visitor.h:442
P4::TypeChecking
Definition
typeChecker.h:55
P4::TypeMap
Definition
typeMap.h:32
P4::UnnestSelectList
Definition
simplifySelectList.h:54
P4::cstring
Definition
cstring.h:85
P4
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition
applyOptionsPragmas.cpp:13
midend
simplifySelectList.h
Generated by
1.13.2