P4C
The P4 Compiler
Loading...
Searching...
No Matches
dpdkProgramStructure.h
1#ifndef BACKENDS_DPDK_DPDKPROGRAMSTRUCTURE_H_
2#define BACKENDS_DPDK_DPDKPROGRAMSTRUCTURE_H_
3
4#include "frontends/common/resolveReferences/referenceMap.h"
5#include "frontends/p4/typeMap.h"
6#include "ir/ir.h"
7
8namespace P4 {
9
13enum InternalTableType { REGULAR_EXACT, LEARNER, WILDCARD };
14
17 cstring p4arch; // 'pna' or 'psa'
19 unsigned scalars_width = 0;
20
21 std::map<const IR::StructField *, cstring> scalarMetadataFields;
30
33 ordered_set<cstring> learner_actions;
35 ordered_map<cstring, std::vector<cstring>> learner_action_params;
40
42
49
50 std::map<const cstring, IR::IndexedVector<IR::Parameter> *> args_struct_map;
51 std::map<const IR::Declaration_Instance *, cstring> csum_map;
52 std::map<cstring, int> error_map;
53 std::vector<const IR::Declaration_Instance *> externDecls;
54 std::map<cstring, std::vector<std::pair<cstring, cstring>>> key_map;
55 std::map<cstring, const IR::P4Table *> group_tables;
56 std::map<cstring, const IR::P4Table *> member_tables;
57
58 std::set<cstring> pipeline_controls;
59 std::set<cstring> non_pipeline_controls;
60
61 IR::Type_Struct *metadataStruct;
62 IR::Expression *ipsec_header;
63 cstring local_metadata_type = cstring::empty;
64 cstring header_type = cstring::empty;
65 IR::IndexedVector<IR::StructField> compiler_added_fields;
67 IR::Vector<IR::Type> used_metadata;
70
71 void push_variable(const IR::DpdkDeclaration *d) { variables.push_back(d); }
72 IR::IndexedVector<IR::DpdkDeclaration> &get_globals() { return variables; }
73
74 void addHeaderInstances(const IR::DpdkHeaderInstance *d) {
75 if (header_instances.find(d->name->toString()) == header_instances.end()) {
76 header_instances.emplace(d->name->toString(), d);
77 }
78 }
79
80 bool hasVisited(const IR::Type_StructLike *st) {
81 if (auto h = st->to<IR::Type_Header>())
82 return header_types.count(h->getName());
83 else if (auto s = st->to<IR::Type_Struct>())
84 return metadata_types.count(s->getName());
85 else if (auto u = st->to<IR::Type_HeaderUnion>())
86 return header_union_types.count(u->getName());
87 return false;
88 }
89
96 bool isPSA(void) { return (p4arch == "psa") ? true : false; }
97
104 bool isPNA(void) { return (p4arch == "pna") ? true : false; }
105};
106
108 cstring modifiedName;
109 cstring headerStr;
110 unsigned modifiedWidth;
111 unsigned offset;
112 unsigned lsb;
113 unsigned msb;
114 unsigned fieldWidth;
115 hdrFieldInfo() {
116 modifiedName = cstring::empty;
117 headerStr = cstring::empty;
118 modifiedWidth = 0;
119 offset = 0;
120 lsb = 0;
121 msb = 0;
122 fieldWidth = 0;
123 }
124};
125
127 DpdkProgramStructure *structure;
128
129 public:
130 explicit ParseDpdkArchitecture(DpdkProgramStructure *structure) : structure(structure) {
131 CHECK_NULL(structure);
132 }
133
134 bool preorder(const IR::ToplevelBlock *block) override;
135 bool preorder(const IR::PackageBlock *block) override;
136 void parse_psa_block(const IR::PackageBlock *);
137 void parse_pna_block(const IR::PackageBlock *);
138
139 profile_t init_apply(const IR::Node *root) override {
140 structure->variables.clear();
141 structure->header_types.clear();
142 structure->metadata_types.clear();
143 structure->parsers.clear();
144 structure->deparsers.clear();
145 structure->pipelines.clear();
146 structure->actions.clear();
147 return Inspector::init_apply(root);
148 }
149};
150
152 P4::ReferenceMap *refMap;
153 P4::TypeMap *typeMap;
154 DpdkProgramStructure *structure;
155
156 public:
158 DpdkProgramStructure *structure)
159 : refMap(refMap), typeMap(typeMap), structure(structure) {
160 CHECK_NULL(structure);
161 }
162
163 bool isHeaders(const IR::Type_StructLike *st);
164 void addTypesAndInstances(const IR::Type_StructLike *type, bool meta);
165 void addHeaderType(const IR::Type_StructLike *st);
166 void addHeaderInstance(const IR::Type_StructLike *st, cstring name);
167 bool preorder(const IR::Declaration_Variable *dv) override;
168 bool preorder(const IR::Parameter *parameter) override;
169 bool preorder(const IR::P4Action *) override;
170 bool isStandardMetadata(cstring);
171};
172
173} // namespace P4
174
175#endif /* BACKENDS_DPDK_DPDKPROGRAMSTRUCTURE_H_ */
Definition node.h:52
Definition node.h:95
Definition vector.h:59
Definition dpdkProgramStructure.h:151
Definition visitor.h:400
Definition dpdkProgramStructure.h:126
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition typeMap.h:41
Definition visitor.h:78
Definition cstring.h:85
Definition ordered_map.h:32
Definition ordered_set.h:32
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
InternalTableType
Definition dpdkProgramStructure.h:13
Collect information related to P4 programs targeting dpdk.
Definition dpdkProgramStructure.h:16
ordered_set< cstring > learner_tables
Table and action info for learner tables.
Definition dpdkProgramStructure.h:32
bool isPNA(void)
Predicate that states whether architecture is PNA or not.
Definition dpdkProgramStructure.h:104
bool isPSA(void)
Predicate that states whether architecture is PSA or not.
Definition dpdkProgramStructure.h:96
Definition dpdkProgramStructure.h:107