P4C
The P4 Compiler
Loading...
Searching...
No Matches
portableProgramStructure.h
1/*
2Copyright 2024 Marvell Technology, 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_COMMON_PORTABLEPROGRAMSTRUCTURE_H_
18#define BACKENDS_COMMON_PORTABLEPROGRAMSTRUCTURE_H_
19
20#include "backends/common/programStructure.h"
21#include "frontends/common/resolveReferences/referenceMap.h"
22#include "frontends/p4/typeMap.h"
23#include "ir/ir.h"
24#include "lib/cstring.h"
25
27namespace P4 {
28
30 public:
31 P4::ReferenceMap *refMap;
32 P4::TypeMap *typeMap;
33
37 unsigned scalars_width = 0;
38 unsigned bool_width = 1;
39
55
56 std::vector<const IR::ExternBlock *> globals;
57
58 public:
60 : refMap(refMap), typeMap(typeMap) {
61 CHECK_NULL(refMap);
62 CHECK_NULL(typeMap);
63 }
64
65 std::set<cstring> non_pipeline_controls;
66 std::set<cstring> pipeline_controls;
67
68 bool hasVisited(const IR::Type_StructLike *st) {
69 if (auto h = st->to<IR::Type_Header>())
70 return header_types.count(h->getName());
71 else if (auto s = st->to<IR::Type_Struct>())
72 return metadata_types.count(s->getName());
73 else if (auto u = st->to<IR::Type_HeaderUnion>())
74 return header_union_types.count(u->getName());
75 return false;
76 }
77};
78
80 public:
81 bool preorder(const IR::ToplevelBlock *block) override;
82};
83
85 protected:
86 P4::ReferenceMap *refMap;
87 P4::TypeMap *typeMap;
88
89 public:
91 : refMap(refMap), typeMap(typeMap) {
92 CHECK_NULL(refMap);
93 CHECK_NULL(typeMap);
94 }
95
96 bool isHeaders(const IR::Type_StructLike *st);
97};
98
99} // namespace P4
100
101#endif /* BACKENDS_COMMON_PORTABLEPROGRAMSTRUCTURE_H_ */
Definition portableProgramStructure.h:84
Definition visitor.h:400
Definition portableProgramStructure.h:79
Definition portableProgramStructure.h:29
ordered_map< cstring, const IR::Declaration_Variable * > scalars
Definition portableProgramStructure.h:36
Definition backends/common/programStructure.h:32
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition typeMap.h:41
Definition ordered_map.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24