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;
39
41
48
49 std::map<const cstring, IR::IndexedVector<IR::Parameter> *> args_struct_map;
50 std::map<const IR::Declaration_Instance *, cstring> csum_map;
51 std::map<cstring, int> error_map;
52 std::vector<const IR::Declaration_Instance *> externDecls;
53 std::map<cstring, std::vector<std::pair<cstring, cstring>>> key_map;
54 std::map<cstring, const IR::P4Table *> group_tables;
55 std::map<cstring, const IR::P4Table *> member_tables;
56
57 std::set<cstring> pipeline_controls;
58 std::set<cstring> non_pipeline_controls;
59
60 IR::Type_Struct *metadataStruct;
61 IR::Expression *ipsec_header;
62 cstring local_metadata_type = cstring::empty;
63 cstring header_type = cstring::empty;
64 IR::IndexedVector<IR::StructField> compiler_added_fields;
66 IR::Vector<IR::Type> used_metadata;
69
70 void push_variable(const IR::DpdkDeclaration *d) { variables.push_back(d); }
71 IR::IndexedVector<IR::DpdkDeclaration> &get_globals() { return variables; }
72
73 bool hasVisited(const IR::Type_StructLike *st) {
74 if (auto h = st->to<IR::Type_Header>())
75 return header_types.count(h->getName());
76 else if (auto s = st->to<IR::Type_Struct>())
77 return metadata_types.count(s->getName());
78 else if (auto u = st->to<IR::Type_HeaderUnion>())
79 return header_union_types.count(u->getName());
80 return false;
81 }
82
89 bool isPSA(void) { return (p4arch == "psa") ? true : false; }
90
97 bool isPNA(void) { return (p4arch == "pna") ? true : false; }
98};
99
101 cstring modifiedName;
102 cstring headerStr;
103 unsigned modifiedWidth;
104 unsigned offset;
105 unsigned lsb;
106 unsigned msb;
107 unsigned fieldWidth;
108 hdrFieldInfo() {
109 modifiedName = cstring::empty;
110 headerStr = cstring::empty;
111 modifiedWidth = 0;
112 offset = 0;
113 lsb = 0;
114 msb = 0;
115 fieldWidth = 0;
116 }
117};
118
120 DpdkProgramStructure *structure;
121
122 public:
123 explicit ParseDpdkArchitecture(DpdkProgramStructure *structure) : structure(structure) {
124 CHECK_NULL(structure);
125 }
126
127 bool preorder(const IR::ToplevelBlock *block) override;
128 bool preorder(const IR::PackageBlock *block) override;
129 void parse_psa_block(const IR::PackageBlock *);
130 void parse_pna_block(const IR::PackageBlock *);
131
132 profile_t init_apply(const IR::Node *root) override {
133 structure->variables.clear();
134 structure->header_types.clear();
135 structure->metadata_types.clear();
136 structure->parsers.clear();
137 structure->deparsers.clear();
138 structure->pipelines.clear();
139 structure->actions.clear();
140 return Inspector::init_apply(root);
141 }
142};
143
145 P4::ReferenceMap *refMap;
146 P4::TypeMap *typeMap;
147 DpdkProgramStructure *structure;
148
149 public:
151 DpdkProgramStructure *structure)
152 : refMap(refMap), typeMap(typeMap), structure(structure) {
153 CHECK_NULL(structure);
154 }
155
156 bool isHeaders(const IR::Type_StructLike *st);
157 void addTypesAndInstances(const IR::Type_StructLike *type, bool meta);
158 void addHeaderType(const IR::Type_StructLike *st);
159 void addHeaderInstance(const IR::Type_StructLike *st, cstring name);
160 bool preorder(const IR::Declaration_Variable *dv) override;
161 bool preorder(const IR::Parameter *parameter) override;
162 bool preorder(const IR::P4Action *) override;
163 bool isStandardMetadata(cstring);
164};
165
166} // namespace P4
167
168#endif /* BACKENDS_DPDK_DPDKPROGRAMSTRUCTURE_H_ */
Definition node.h:52
Definition node.h:95
Definition vector.h:58
Definition dpdkProgramStructure.h:144
Definition visitor.h:400
Definition dpdkProgramStructure.h:119
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:97
bool isPSA(void)
Predicate that states whether architecture is PSA or not.
Definition dpdkProgramStructure.h:89
Definition dpdkProgramStructure.h:100