P4C
The P4 Compiler
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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
11enum InternalTableType { REGULAR_EXACT, LEARNER, WILDCARD };
12
15 cstring p4arch; // 'pna' or 'psa'
17 unsigned scalars_width = 0;
18
19 std::map<const IR::StructField *, cstring> scalarMetadataFields;
28
31 ordered_set<cstring> learner_actions;
33 ordered_map<cstring, std::vector<cstring>> learner_action_params;
37
39
46
47 std::map<const cstring, IR::IndexedVector<IR::Parameter> *> args_struct_map;
48 std::map<const IR::Declaration_Instance *, cstring> csum_map;
49 std::map<cstring, int> error_map;
50 std::vector<const IR::Declaration_Instance *> externDecls;
51 std::map<cstring, std::vector<std::pair<cstring, cstring>>> key_map;
52 std::map<cstring, const IR::P4Table *> group_tables;
53 std::map<cstring, const IR::P4Table *> member_tables;
54
55 std::set<cstring> pipeline_controls;
56 std::set<cstring> non_pipeline_controls;
57
58 IR::Type_Struct *metadataStruct;
59 IR::Expression *ipsec_header;
60 cstring local_metadata_type = cstring::empty;
61 cstring header_type = cstring::empty;
62 IR::IndexedVector<IR::StructField> compiler_added_fields;
64 IR::Vector<IR::Type> used_metadata;
67
68 void push_variable(const IR::DpdkDeclaration *d) { variables.push_back(d); }
69 IR::IndexedVector<IR::DpdkDeclaration> &get_globals() { return variables; }
70
71 bool hasVisited(const IR::Type_StructLike *st) {
72 if (auto h = st->to<IR::Type_Header>())
73 return header_types.count(h->getName());
74 else if (auto s = st->to<IR::Type_Struct>())
75 return metadata_types.count(s->getName());
76 else if (auto u = st->to<IR::Type_HeaderUnion>())
77 return header_union_types.count(u->getName());
78 return false;
79 }
80
87 bool isPSA(void) { return (p4arch == "psa") ? true : false; }
88
95 bool isPNA(void) { return (p4arch == "pna") ? true : false; }
96};
97
99 cstring modifiedName;
100 cstring headerStr;
101 unsigned modifiedWidth;
102 unsigned offset;
103 unsigned lsb;
104 unsigned msb;
105 unsigned fieldWidth;
106 hdrFieldInfo() {
107 modifiedName = cstring::empty;
108 headerStr = cstring::empty;
109 modifiedWidth = 0;
110 offset = 0;
111 lsb = 0;
112 msb = 0;
113 fieldWidth = 0;
114 }
115};
116
118 DpdkProgramStructure *structure;
119
120 public:
121 explicit ParseDpdkArchitecture(DpdkProgramStructure *structure) : structure(structure) {
122 CHECK_NULL(structure);
123 }
124
125 bool preorder(const IR::ToplevelBlock *block) override;
126 bool preorder(const IR::PackageBlock *block) override;
127 void parse_psa_block(const IR::PackageBlock *);
128 void parse_pna_block(const IR::PackageBlock *);
129
130 profile_t init_apply(const IR::Node *root) override {
131 structure->variables.clear();
132 structure->header_types.clear();
133 structure->metadata_types.clear();
134 structure->parsers.clear();
135 structure->deparsers.clear();
136 structure->pipelines.clear();
137 structure->actions.clear();
138 return Inspector::init_apply(root);
139 }
140};
141
143 P4::ReferenceMap *refMap;
144 P4::TypeMap *typeMap;
145 DpdkProgramStructure *structure;
146
147 public:
149 DpdkProgramStructure *structure)
150 : refMap(refMap), typeMap(typeMap), structure(structure) {
151 CHECK_NULL(structure);
152 }
153
154 bool isHeaders(const IR::Type_StructLike *st);
155 void addTypesAndInstances(const IR::Type_StructLike *type, bool meta);
156 void addHeaderType(const IR::Type_StructLike *st);
157 void addHeaderInstance(const IR::Type_StructLike *st, cstring name);
158 bool preorder(const IR::Declaration_Variable *dv) override;
159 bool preorder(const IR::Parameter *parameter) override;
160 bool preorder(const IR::P4Action *) override;
161 bool isStandardMetadata(cstring);
162};
163
164#endif /* BACKENDS_DPDK_DPDKPROGRAMSTRUCTURE_H_ */
Definition node.h:50
Definition node.h:93
Definition vector.h:56
Definition dpdkProgramStructure.h:142
Definition visitor.h:396
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
Definition typeMap.h:41
Definition dpdkProgramStructure.h:117
Definition visitor.h:76
Definition cstring.h:80
Definition ordered_map.h:30
Definition ordered_set.h:30
Collect information related to P4 programs targeting dpdk.
Definition dpdkProgramStructure.h:14
ordered_set< cstring > learner_tables
Table and action info for learner tables.
Definition dpdkProgramStructure.h:30
bool isPSA(void)
Predicate that states whether architecture is PSA or not.
Definition dpdkProgramStructure.h:87
bool isPNA(void)
Predicate that states whether architecture is PNA or not.
Definition dpdkProgramStructure.h:95
Definition dpdkProgramStructure.h:98