P4C
The P4 Compiler
Loading...
Searching...
No Matches
trace_event_types.h
1#ifndef BACKENDS_P4TOOLS_COMMON_LIB_TRACE_EVENT_TYPES_H_
2#define BACKENDS_P4TOOLS_COMMON_LIB_TRACE_EVENT_TYPES_H_
3
4#include <iosfwd>
5#include <utility>
6#include <vector>
7
8#include "backends/p4tools/common/lib/model.h"
9#include "backends/p4tools/common/lib/symbolic_env.h"
10#include "backends/p4tools/common/lib/trace_event.h"
11#include "ir/ir.h"
12#include "ir/visitor.h"
13#include "lib/cstring.h"
14
17
18/* =============================================================================================
19 * Generic
20 * ============================================================================================= */
21
23class Generic : public TraceEvent {
24 protected:
25 // A label that specifies the type of this generic trace event.
26 cstring label;
27
28 void print(std::ostream &os) const override;
29
30 public:
31 explicit Generic(cstring label);
32 ~Generic() override = default;
33 Generic(const Generic &) = default;
34 Generic(Generic &&) = default;
35 Generic &operator=(const Generic &) = default;
36 Generic &operator=(Generic &&) = default;
37
38 DECLARE_TYPEINFO(Generic, TraceEvent);
39};
40
41/* =============================================================================================
42 * GenericDescription
43 * ============================================================================================= */
44
47class GenericDescription : public Generic {
48 protected:
49 cstring description;
50
51 void print(std::ostream &os) const override;
52
53 public:
54 explicit GenericDescription(cstring label, cstring description);
55
56 DECLARE_TYPEINFO(GenericDescription, Generic);
57};
58
59/* =============================================================================================
60 * Expression
61 * ============================================================================================= */
62
64class Expression : public Generic {
65 private:
66 const IR::Expression *value;
67
68 public:
69 [[nodiscard]] const Expression *subst(const SymbolicEnv &env) const override;
70 const Expression *apply(Transform &visitor) const override;
71 [[nodiscard]] const Expression *evaluate(const Model &model, bool doComplete) const override;
72
73 explicit Expression(const IR::Expression *value, cstring label);
74 ~Expression() override = default;
75 Expression(const Expression &) = default;
76 Expression(Expression &&) = default;
77 Expression &operator=(const Expression &) = default;
78 Expression &operator=(Expression &&) = default;
79
80 protected:
81 void print(std::ostream &os) const override;
82
83 DECLARE_TYPEINFO(Expression, Generic);
84};
85
86/* =============================================================================================
87 * MethodCallExpression
88 * ============================================================================================= */
89
91class MethodCall : public TraceEvent {
92 private:
93 const IR::MethodCallExpression *call;
94
95 public:
96 explicit MethodCall(const IR::MethodCallExpression *call);
97 ~MethodCall() override = default;
98 MethodCall(const MethodCall &) = default;
99 MethodCall(MethodCall &&) = default;
100 MethodCall &operator=(const MethodCall &) = default;
101 MethodCall &operator=(MethodCall &&) = default;
102
103 protected:
104 void print(std::ostream &os) const override;
105
106 DECLARE_TYPEINFO(MethodCall, TraceEvent);
107};
108
109/* =============================================================================================
110 * IfStatementCondition
111 * ============================================================================================= */
112
114class IfStatementCondition : public TraceEvent {
115 private:
116 const IR::Expression *preEvalCond = nullptr;
117 const IR::Expression *postEvalCond;
118
119 void setPreEvalCond(const IR::Expression *cond);
120
121 public:
122 [[nodiscard]] const IfStatementCondition *subst(const SymbolicEnv &env) const override;
123 const IfStatementCondition *apply(Transform &visitor) const override;
124 [[nodiscard]] const IfStatementCondition *evaluate(const Model &model,
125 bool doComplete) const override;
126
127 explicit IfStatementCondition(const IR::Expression *cond);
128
129 protected:
130 void print(std::ostream &os) const override;
131
132 DECLARE_TYPEINFO(IfStatementCondition, TraceEvent);
133};
134
135/* =============================================================================================
136 * AssignmentStatement
137 * ============================================================================================= */
138
140class AssignmentStatement : public TraceEvent {
141 private:
142 const IR::AssignmentStatement &stmt;
143
144 public:
145 [[nodiscard]] const AssignmentStatement *subst(const SymbolicEnv &env) const override;
146 const AssignmentStatement *apply(Transform &visitor) const override;
147 [[nodiscard]] const AssignmentStatement *evaluate(const Model &model,
148 bool doComplete) const override;
149
150 explicit AssignmentStatement(const IR::AssignmentStatement &stmt);
151
152 protected:
153 void print(std::ostream &os) const override;
154
155 DECLARE_TYPEINFO(AssignmentStatement, TraceEvent);
156};
157
158/* =============================================================================================
159 * ExtractSuccess
160 * ============================================================================================= */
161
164class ExtractSuccess : public TraceEvent {
165 private:
168 const IR::Expression *extractedHeader;
169
171 int offset;
172
174 const IR::Expression *condition;
175
177 std::vector<std::pair<IR::StateVariable, const IR::Expression *>> fields;
178
179 public:
180 [[nodiscard]] const ExtractSuccess *subst(const SymbolicEnv &env) const override;
181 const ExtractSuccess *apply(Transform &visitor) const override;
182 [[nodiscard]] const ExtractSuccess *evaluate(const Model &model,
183 bool doComplete) const override;
184
186 [[nodiscard]] const IR::Expression *getExtractedHeader() const;
187
189 [[nodiscard]] int getOffset() const;
190
192 [[nodiscard]] const std::vector<std::pair<IR::StateVariable, const IR::Expression *>> &
193 getFields() const;
194
195 ExtractSuccess(const IR::Expression *extractedHeader, int offset,
196 const IR::Expression *condition,
197 std::vector<std::pair<IR::StateVariable, const IR::Expression *>> fields);
198 ExtractSuccess(const ExtractSuccess &) = default;
199 ExtractSuccess(ExtractSuccess &&) = default;
200 ExtractSuccess &operator=(const ExtractSuccess &) = default;
201 ExtractSuccess &operator=(ExtractSuccess &&) = default;
202 ~ExtractSuccess() override = default;
203
204 protected:
205 void print(std::ostream &os) const override;
206
207 DECLARE_TYPEINFO(ExtractSuccess, TraceEvent);
208};
209
210/* =============================================================================================
211 * ExtractFailure
212 * ============================================================================================= */
213
216class ExtractFailure : public TraceEvent {
217 private:
220 const IR::Expression *extractedHeader;
221
223 int offset;
224
226 const IR::Expression *condition;
227
228 public:
229 ExtractFailure(const IR::Expression *extractedHeader, int offset,
230 const IR::Expression *condition);
231
232 ExtractFailure(const ExtractFailure &) = default;
233 ExtractFailure(ExtractFailure &&) = default;
234 ExtractFailure &operator=(const ExtractFailure &) = default;
235 ExtractFailure &operator=(ExtractFailure &&) = default;
236 ~ExtractFailure() override = default;
237
238 protected:
239 void print(std::ostream &os) const override;
240
241 DECLARE_TYPEINFO(ExtractFailure, TraceEvent);
242};
243
244/* =============================================================================================
245 * Emit
246 * ============================================================================================= */
247
249class Emit : public TraceEvent {
250 private:
252 const IR::HeaderExpression *emitHeader;
253
254 public:
255 [[nodiscard]] const Emit *subst(const SymbolicEnv &env) const override;
256 const Emit *apply(Transform &visitor) const override;
257 [[nodiscard]] const Emit *evaluate(const Model &model, bool doComplete) const override;
258
259 explicit Emit(const IR::HeaderExpression *emitHeader);
260 ~Emit() override = default;
261 Emit(const Emit &) = default;
262 Emit(Emit &&) = default;
263 Emit &operator=(const Emit &) = default;
264 Emit &operator=(Emit &&) = default;
265
266 protected:
267 void print(std::ostream &os) const override;
268
269 DECLARE_TYPEINFO(Emit, TraceEvent);
270};
271
272/* =============================================================================================
273 * Packet
274 * ============================================================================================= */
275
277class Packet : public TraceEvent {
278 public:
279 enum class Direction {
282
285 };
286
287 const Packet *apply(Transform &visitor) const override;
288
289 [[nodiscard]] const Packet *evaluate(const Model &model, bool doComplete) const override;
290
291 [[nodiscard]] const Packet *subst(const SymbolicEnv &env) const override;
292
293 Packet(const Direction &direction, const IR::Expression *packetValue);
294 ~Packet() override = default;
295 Packet(const Packet &) = default;
296 Packet(Packet &&) = default;
297 Packet &operator=(const Packet &) = default;
298 Packet &operator=(Packet &&) = default;
299
300 private:
301 Direction direction;
302 const IR::Expression *packetValue;
303
304 protected:
305 void print(std::ostream &os) const override;
306
307 DECLARE_TYPEINFO(Packet, TraceEvent);
308};
309
310std::ostream &operator<<(std::ostream &os, const Packet::Direction &direction);
311
312/* =============================================================================================
313 * ParserStart
314 * ============================================================================================= */
315
317class ParserStart : public TraceEvent {
318 private:
319 const IR::P4Parser *parser;
320
321 public:
322 explicit ParserStart(const IR::P4Parser *parser);
323 ~ParserStart() override = default;
324 ParserStart(const ParserStart &) = default;
325 ParserStart(ParserStart &&) = default;
326 ParserStart &operator=(const ParserStart &) = default;
327 ParserStart &operator=(ParserStart &&) = default;
328
329 protected:
330 void print(std::ostream &os) const override;
331
332 DECLARE_TYPEINFO(ParserStart, TraceEvent);
333};
334
335/* =============================================================================================
336 * ParserState
337 * ============================================================================================= */
338
340class ParserState : public TraceEvent {
341 private:
342 const IR::ParserState *state;
343
344 public:
345 explicit ParserState(const IR::ParserState *state);
346 ~ParserState() override = default;
347 ParserState(const ParserState &) = default;
348 ParserState(ParserState &&) = default;
349 ParserState &operator=(const ParserState &) = default;
350 ParserState &operator=(ParserState &&) = default;
351
353 const IR::ParserState *getParserState() const;
354
355 protected:
356 void print(std::ostream &os) const override;
357
358 DECLARE_TYPEINFO(ParserState, TraceEvent);
359};
360
361} // namespace P4::P4Tools::TraceEvents
362
363#endif /* BACKENDS_P4TOOLS_COMMON_LIB_TRACE_EVENT_TYPES_H_ */
Definition backends/p4tools/common/lib/model.h:18
Definition symbolic_env.h:12
An event in a trace of the execution of a P4 program.
Definition trace_event.h:14
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:174
const AssignmentStatement * evaluate(const Model &model, bool doComplete) const override
Definition trace_event_types.cpp:156
const AssignmentStatement * apply(Transform &visitor) const override
Applies the given IR transform to the expressions in this trace event.
Definition trace_event_types.cpp:149
const AssignmentStatement * subst(const SymbolicEnv &env) const override
Definition trace_event_types.cpp:142
const Emit * evaluate(const Model &model, bool doComplete) const override
Definition trace_event_types.cpp:280
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:285
const Emit * subst(const SymbolicEnv &env) const override
Definition trace_event_types.cpp:271
const Emit * apply(Transform &visitor) const override
Applies the given IR transform to the expressions in this trace event.
Definition trace_event_types.cpp:276
const Expression * apply(Transform &visitor) const override
Applies the given IR transform to the expressions in this trace event.
Definition trace_event_types.cpp:48
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:66
const Expression * subst(const SymbolicEnv &env) const override
Definition trace_event_types.cpp:44
const Expression * evaluate(const Model &model, bool doComplete) const override
Definition trace_event_types.cpp:52
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:258
const std::vector< std::pair< IR::StateVariable, const IR::Expression * > > & getFields() const
Definition trace_event_types.cpp:243
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:228
const ExtractSuccess * subst(const SymbolicEnv &env) const override
Definition trace_event_types.cpp:197
const ExtractSuccess * apply(Transform &visitor) const override
Applies the given IR transform to the expressions in this trace event.
Definition trace_event_types.cpp:206
int getOffset() const
Definition trace_event_types.cpp:241
const IR::Expression * getExtractedHeader() const
Definition trace_event_types.cpp:248
const ExtractSuccess * evaluate(const Model &model, bool doComplete) const override
Definition trace_event_types.cpp:215
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:34
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:25
const IfStatementCondition * subst(const SymbolicEnv &env) const override
Definition trace_event_types.cpp:94
const IfStatementCondition * evaluate(const Model &model, bool doComplete) const override
Definition trace_event_types.cpp:106
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:119
const IfStatementCondition * apply(Transform &visitor) const override
Applies the given IR transform to the expressions in this trace event.
Definition trace_event_types.cpp:100
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:77
A packet that is either presented to a parser or emitted from a deparser.
Definition trace_event_types.h:277
Direction
Definition trace_event_types.h:279
@ Out
Marks a packet that is emitted from a deparser.
Definition trace_event_types.h:284
@ In
Marks a packet that is presented to a parser.
Definition trace_event_types.h:281
const Packet * evaluate(const Model &model, bool doComplete) const override
Definition trace_event_types.cpp:302
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:309
const Packet * apply(Transform &visitor) const override
Applies the given IR transform to the expressions in this trace event.
Definition trace_event_types.cpp:298
const Packet * subst(const SymbolicEnv &env) const override
Definition trace_event_types.cpp:294
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:335
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:343
const IR::ParserState * getParserState() const
Definition trace_event_types.cpp:345
Definition visitor.h:437
Definition cstring.h:85
This file defines explicit types of trace events extended from the generic trace class.
Definition trace_event_types.cpp:17