P4C
The P4 Compiler
Loading...
Searching...
No Matches
backends/bmv2/common/programStructure.h
1/*
2Copyright 2013-present Barefoot Networks, 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 BACKENDS_BMV2_COMMON_PROGRAMSTRUCTURE_H_
18#define BACKENDS_BMV2_COMMON_PROGRAMSTRUCTURE_H_
19
20#include "ir/visitor.h"
21#include "lib/ordered_set.h"
22#include "metermap.h"
23
24namespace BMV2 {
25
27
28enum class BlockConverted {
29 None,
30 Parser,
31 Ingress,
32 Egress,
33 Deparser,
34 ChecksumCompute,
35 ChecksumVerify
36};
37
70
72 public:
73 ProgramStructure *structure;
74
75 explicit DiscoverStructure(ProgramStructure *structure) : structure(structure) {
76 setName("DiscoverStructure");
77 }
78 void postorder(const IR::ParameterList *paramList) override;
79 void postorder(const IR::P4Action *action) override;
80 void postorder(const IR::Declaration_Variable *decl) override;
81 void postorder(const IR::Type_Error *errors) override;
82 void postorder(const IR::Declaration_MatchKind *kind) override;
83};
84
90 ResourceMap *resourceMap;
91
92 public:
93 explicit BuildResourceMap(ResourceMap *resourceMap) : resourceMap(resourceMap) {
94 CHECK_NULL(resourceMap);
95 }
96
97 bool preorder(const IR::ControlBlock *control) override {
98 resourceMap->emplace(control->container, control);
99 for (auto cv : control->constantValue) {
100 resourceMap->emplace(cv.first, cv.second);
101 }
102
103 for (auto c : control->container->controlLocals) {
104 if (c->is<IR::InstantiatedBlock>()) {
105 resourceMap->emplace(c, control->getValue(c));
106 }
107 }
108 return false;
109 }
110
111 bool preorder(const IR::ParserBlock *parser) override {
112 resourceMap->emplace(parser->container, parser);
113 for (auto cv : parser->constantValue) {
114 resourceMap->emplace(cv.first, cv.second);
115 if (cv.second->is<IR::Block>()) {
116 visit(cv.second->getNode());
117 }
118 }
119
120 for (auto c : parser->container->parserLocals) {
121 if (c->is<IR::InstantiatedBlock>()) {
122 resourceMap->emplace(c, parser->getValue(c));
123 }
124 }
125 return false;
126 }
127
128 bool preorder(const IR::TableBlock *table) override {
129 resourceMap->emplace(table->container, table);
130 for (auto cv : table->constantValue) {
131 resourceMap->emplace(cv.first, cv.second);
132 if (cv.second->is<IR::Block>()) {
133 visit(cv.second->getNode());
134 }
135 }
136 return false;
137 }
138
139 bool preorder(const IR::PackageBlock *package) override {
140 for (auto cv : package->constantValue) {
141 if (cv.second->is<IR::Block>()) {
142 visit(cv.second->getNode());
143 }
144 }
145 return false;
146 }
147
148 bool preorder(const IR::ToplevelBlock *tlb) override {
149 auto package = tlb->getMain();
150 visit(package);
151 return false;
152 }
153};
154
155} // namespace BMV2
156
157#endif /* BACKENDS_BMV2_COMMON_PROGRAMSTRUCTURE_H_ */
Definition backends/bmv2/common/programStructure.h:89
Definition bmv2/common/metermap.h:24
Definition backends/bmv2/common/programStructure.h:71
Definition backends/bmv2/common/programStructure.h:40
ResourceMap resourceMap
map IR node to compile-time allocated resource blocks.
Definition backends/bmv2/common/programStructure.h:66
ordered_map< const IR::P4Action *, unsigned > ids
For each action its json id.
Definition backends/bmv2/common/programStructure.h:50
std::map< const IR::StructField *, cstring > scalarMetadataFields
Definition backends/bmv2/common/programStructure.h:58
std::set< cstring > match_kinds
All match kinds.
Definition backends/bmv2/common/programStructure.h:64
ordered_map< const IR::Parameter *, unsigned > index
Definition backends/bmv2/common/programStructure.h:46
ordered_map< const IR::IDeclaration *, unsigned int > errorCodesMap
All error codes.
Definition backends/bmv2/common/programStructure.h:54
std::vector< const IR::Declaration_Variable * > variables
All local variables.
Definition backends/bmv2/common/programStructure.h:52
ordered_map< const IR::P4Action *, const IR::P4Control * > actions
Map action to parent control.
Definition backends/bmv2/common/programStructure.h:43
ordered_set< const IR::Parameter * > nonActionParameters
Parameters of controls/parsers.
Definition backends/bmv2/common/programStructure.h:48
DirectMeterMap directMeterMap
All the direct meters.
Definition backends/bmv2/common/programStructure.h:60
ordered_map< cstring, const IR::P4Table * > directCounterMap
All the direct counters.
Definition backends/bmv2/common/programStructure.h:62
Definition visitor.h:396
Definition ordered_map.h:30
Definition ordered_set.h:30
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition action.cpp:21