P4C
The P4 Compiler
Loading...
Searching...
No Matches
targets/pna/test_spec.h
1#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_TEST_SPEC_H_
2#define BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_TEST_SPEC_H_
3
4#include <cstddef>
5#include <map>
6#include <utility>
7#include <vector>
8
9#include "backends/p4tools/common/lib/model.h"
10#include "ir/declaration.h"
11#include "ir/ir.h"
12#include "lib/cstring.h"
13
14#include "backends/p4tools/modules/testgen/lib/test_object.h"
15#include "backends/p4tools/modules/testgen/lib/test_spec.h"
16
18
19/* =========================================================================================
20 * PnaDpdkRegister
21 * ========================================================================================= */
22
24 public:
26 const IR::Expression *index;
27
29 const IR::Expression *value;
30
31 explicit PnaDpdkRegisterCondition(const IR::Expression *index, const IR::Expression *value);
32
35 [[nodiscard]] const IR::Constant *getEvaluatedIndex() const;
36
39 [[nodiscard]] const IR::Constant *getEvaluatedValue() const;
40
41 [[nodiscard]] const PnaDpdkRegisterCondition *evaluate(const Model &model,
42 bool doComplete) const override;
43
44 [[nodiscard]] cstring getObjectName() const override;
45
46 DECLARE_TYPEINFO(PnaDpdkRegisterCondition, TestObject);
47};
48
58 private:
61 const IR::Expression *initialValue;
62
64 std::vector<PnaDpdkRegisterCondition> registerConditions;
65
66 public:
67 explicit PnaDpdkRegisterValue(const IR::Expression *initialValue);
68
69 [[nodiscard]] cstring getObjectName() const override;
70
73
75 [[nodiscard]] const IR::Expression *getInitialValue() const;
76
79 const IR::Expression *getCurrentValue(const IR::Expression *index) const;
80
83 [[nodiscard]] const IR::Constant *getEvaluatedValue() const;
84
85 [[nodiscard]] const PnaDpdkRegisterValue *evaluate(const Model &model,
86 bool doComplete) const override;
87
88 DECLARE_TYPEINFO(PnaDpdkRegisterValue, TestObject);
89};
90
91/* =========================================================================================
92 * PnaDpdkActionProfile
93 * ========================================================================================= */
95 private:
97 std::vector<std::pair<cstring, std::vector<ActionArg>>> actions;
98
100 const IR::IDeclaration *profileDecl;
101
102 public:
103 explicit PnaDpdkActionProfile(const IR::IDeclaration *profileDecl);
104
105 [[nodiscard]] cstring getObjectName() const override;
106
108 [[nodiscard]] const std::vector<std::pair<cstring, std::vector<ActionArg>>> *getActions() const;
109
111 [[nodiscard]] const IR::IDeclaration *getProfileDecl() const;
112
114 size_t getActionMapSize() const;
115
117 void addToActionMap(cstring actionName, std::vector<ActionArg> actionArgs);
118
119 [[nodiscard]] const PnaDpdkActionProfile *evaluate(const Model &model,
120 bool doComplete) const override;
121
122 DECLARE_TYPEINFO(PnaDpdkActionProfile, TestObject);
123};
124
125/* =========================================================================================
126 * ActionSelector
127 * ========================================================================================= */
129 private:
131 const IR::IDeclaration *selectorDecl;
132
134 const PnaDpdkActionProfile *actionProfile;
135
136 public:
137 explicit PnaDpdkActionSelector(const IR::IDeclaration *selectorDecl,
138 const PnaDpdkActionProfile *actionProfile);
139
140 [[nodiscard]] cstring getObjectName() const override;
141
143 [[nodiscard]] const IR::IDeclaration *getSelectorDecl() const;
144
146 [[nodiscard]] const PnaDpdkActionProfile *getActionProfile() const;
147
148 [[nodiscard]] const PnaDpdkActionSelector *evaluate(const Model &model,
149 bool doComplete) const override;
150
151 DECLARE_TYPEINFO(PnaDpdkActionSelector, TestObject);
152};
153
154/* =========================================================================================
155 * MetadataCollection
156 * ========================================================================================= */
158 private:
159 std::map<cstring, const IR::Literal *> metadataFields;
160
161 public:
163
164 [[nodiscard]] cstring getObjectName() const override;
165
166 [[nodiscard]] const MetadataCollection *evaluate(const Model & /*model*/,
167 bool doComplete) const override;
168
170 [[nodiscard]] const std::map<cstring, const IR::Literal *> &getMetadataFields() const;
171
172 void addMetaDataField(cstring name, const IR::Literal *metadataField);
173
174 const IR::Literal *getMetadataField(cstring name);
175
176 DECLARE_TYPEINFO(MetadataCollection, TestObject);
177};
178
179/* =========================================================================================
180 * Table Key Match Types
181 * ========================================================================================= */
182
183class Optional : public TableMatch {
184 private:
186 const IR::Expression *value;
187
189 bool addMatch;
190
191 public:
192 explicit Optional(const IR::KeyElement *key, const IR::Expression *value, bool addMatch);
193
194 const Optional *evaluate(const Model &model, bool doComplete) const override;
195
196 cstring getObjectName() const override;
197
200 const IR::Constant *getEvaluatedValue() const;
201
203 bool addAsExactMatch() const;
204
205 DECLARE_TYPEINFO(Optional, TableMatch);
206};
207
208class Range : public TableMatch {
209 private:
211 const IR::Expression *low;
212
214 const IR::Expression *high;
215
216 public:
217 explicit Range(const IR::KeyElement *key, const IR::Expression *low,
218 const IR::Expression *high);
219
220 const Range *evaluate(const Model &model, bool doComplete) const override;
221
222 cstring getObjectName() const override;
223
226 const IR::Constant *getEvaluatedLow() const;
227
230 const IR::Constant *getEvaluatedHigh() const;
231
232 DECLARE_TYPEINFO(Range, TableMatch);
233};
234
235} // namespace P4::P4Tools::P4Testgen::Pna
236
237#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_TEST_SPEC_H_ */
The Declaration interface, representing objects with names.
Definition declaration.h:26
Definition backends/p4tools/common/lib/model.h:18
Definition targets/pna/test_spec.h:157
const std::map< cstring, const IR::Literal * > & getMetadataFields() const
Definition targets/pna/test_spec.cpp:206
const MetadataCollection * evaluate(const Model &, bool doComplete) const override
Definition targets/pna/test_spec.cpp:201
cstring getObjectName() const override
Definition targets/pna/test_spec.cpp:199
Definition targets/pna/test_spec.h:183
bool addAsExactMatch() const
Definition targets/pna/test_spec.cpp:164
const IR::Constant * getEvaluatedValue() const
Definition targets/pna/test_spec.cpp:148
const Optional * evaluate(const Model &model, bool doComplete) const override
Definition targets/pna/test_spec.cpp:157
cstring getObjectName() const override
Definition targets/pna/test_spec.cpp:162
Definition targets/pna/test_spec.h:94
const PnaDpdkActionProfile * evaluate(const Model &model, bool doComplete) const override
Definition targets/pna/test_spec.cpp:104
const std::vector< std::pair< cstring, std::vector< ActionArg > > > * getActions() const
Definition targets/pna/test_spec.cpp:87
size_t getActionMapSize() const
Definition targets/pna/test_spec.cpp:102
cstring getObjectName() const override
Definition targets/pna/test_spec.cpp:95
void addToActionMap(cstring actionName, std::vector< ActionArg > actionArgs)
Add an action (its name) and the arguments to the action map of this profile.
Definition targets/pna/test_spec.cpp:99
const IR::IDeclaration * getProfileDecl() const
Definition targets/pna/test_spec.cpp:97
Definition targets/pna/test_spec.h:128
const PnaDpdkActionProfile * getActionProfile() const
Definition targets/pna/test_spec.cpp:131
const IR::IDeclaration * getSelectorDecl() const
Definition targets/pna/test_spec.cpp:129
const PnaDpdkActionSelector * evaluate(const Model &model, bool doComplete) const override
Definition targets/pna/test_spec.cpp:135
cstring getObjectName() const override
Definition targets/pna/test_spec.cpp:127
Definition targets/pna/test_spec.h:23
const PnaDpdkRegisterCondition * evaluate(const Model &model, bool doComplete) const override
Definition targets/pna/test_spec.cpp:74
const IR::Expression * index
The register index.
Definition targets/pna/test_spec.h:26
const IR::Expression * value
The register value.
Definition targets/pna/test_spec.h:29
cstring getObjectName() const override
Definition targets/pna/test_spec.cpp:81
const IR::Constant * getEvaluatedValue() const
Definition targets/pna/test_spec.cpp:60
const IR::Constant * getEvaluatedIndex() const
Definition targets/pna/test_spec.cpp:67
Definition targets/pna/test_spec.h:57
cstring getObjectName() const override
Definition targets/pna/test_spec.cpp:25
const IR::Expression * getCurrentValue(const IR::Expression *index) const
Definition targets/pna/test_spec.cpp:27
void addRegisterCondition(PnaDpdkRegisterCondition cond)
Each element is an API name paired with a match rule.
Definition targets/pna/test_spec.cpp:19
const IR::Constant * getEvaluatedValue() const
Definition targets/pna/test_spec.cpp:38
const IR::Expression * getInitialValue() const
Definition targets/pna/test_spec.cpp:23
const PnaDpdkRegisterValue * evaluate(const Model &model, bool doComplete) const override
Definition targets/pna/test_spec.cpp:45
Definition targets/pna/test_spec.h:208
const IR::Constant * getEvaluatedLow() const
Definition targets/pna/test_spec.cpp:169
const IR::Constant * getEvaluatedHigh() const
Definition targets/pna/test_spec.cpp:178
const Range * evaluate(const Model &model, bool doComplete) const override
Definition targets/pna/test_spec.cpp:187
cstring getObjectName() const override
Definition targets/pna/test_spec.cpp:218
Definition lib/test_spec.h:126
Definition test_object.h:15
Definition cstring.h:85
Inja.
Definition pna/backend/metadata/metadata.cpp:24