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
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
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
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
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
191 ExtractSuccess(const IR::Expression *extractedHeader, int offset,
192 const IR::Expression *condition,
193 std::vector<std::pair<IR::StateVariable, const IR::Expression *>> fields);
194 ExtractSuccess(const ExtractSuccess &) = default;
195 ExtractSuccess(ExtractSuccess &&) = default;
196 ExtractSuccess &operator=(const ExtractSuccess &) = default;
197 ExtractSuccess &operator=(ExtractSuccess &&) = default;
198 ~ExtractSuccess() override = default;
199
200 protected:
201 void print(std::ostream &os) const override;
202
203 DECLARE_TYPEINFO(ExtractSuccess, TraceEvent);
204};
205
206/* =============================================================================================
207 * ExtractFailure
208 * ============================================================================================= */
209
213 private:
216 const IR::Expression *extractedHeader;
217
219 int offset;
220
222 const IR::Expression *condition;
223
224 public:
225 ExtractFailure(const IR::Expression *extractedHeader, int offset,
226 const IR::Expression *condition);
227
228 ExtractFailure(const ExtractFailure &) = default;
229 ExtractFailure(ExtractFailure &&) = default;
230 ExtractFailure &operator=(const ExtractFailure &) = default;
231 ExtractFailure &operator=(ExtractFailure &&) = default;
232 ~ExtractFailure() override = default;
233
234 protected:
235 void print(std::ostream &os) const override;
236
237 DECLARE_TYPEINFO(ExtractFailure, TraceEvent);
238};
239
240/* =============================================================================================
241 * Emit
242 * ============================================================================================= */
243
245class Emit : public TraceEvent {
246 private:
248 const IR::HeaderExpression *emitHeader;
249
250 public:
251 [[nodiscard]] const Emit *subst(const SymbolicEnv &env) const override;
252 const Emit *apply(Transform &visitor) const override;
253 [[nodiscard]] const Emit *evaluate(const Model &model, bool doComplete) const override;
254
255 explicit Emit(const IR::HeaderExpression *emitHeader);
256 ~Emit() override = default;
257 Emit(const Emit &) = default;
258 Emit(Emit &&) = default;
259 Emit &operator=(const Emit &) = default;
260 Emit &operator=(Emit &&) = default;
261
262 protected:
263 void print(std::ostream &os) const override;
264
265 DECLARE_TYPEINFO(Emit, TraceEvent);
266};
267
268/* =============================================================================================
269 * Packet
270 * ============================================================================================= */
271
273class Packet : public TraceEvent {
274 public:
275 enum class Direction {
277 In,
278
280 Out,
281 };
282
283 const Packet *apply(Transform &visitor) const override;
284
285 [[nodiscard]] const Packet *evaluate(const Model &model, bool doComplete) const override;
286
287 [[nodiscard]] const Packet *subst(const SymbolicEnv &env) const override;
288
289 Packet(const Direction &direction, const IR::Expression *packetValue);
290 ~Packet() override = default;
291 Packet(const Packet &) = default;
292 Packet(Packet &&) = default;
293 Packet &operator=(const Packet &) = default;
294 Packet &operator=(Packet &&) = default;
295
296 private:
297 Direction direction;
298 const IR::Expression *packetValue;
299
300 protected:
301 void print(std::ostream &os) const override;
302
303 DECLARE_TYPEINFO(Packet, TraceEvent);
304};
305
306std::ostream &operator<<(std::ostream &os, const Packet::Direction &direction);
307
308/* =============================================================================================
309 * ParserStart
310 * ============================================================================================= */
311
313class ParserStart : public TraceEvent {
314 private:
315 const IR::P4Parser *parser;
316
317 public:
318 explicit ParserStart(const IR::P4Parser *parser);
319 ~ParserStart() override = default;
320 ParserStart(const ParserStart &) = default;
321 ParserStart(ParserStart &&) = default;
322 ParserStart &operator=(const ParserStart &) = default;
323 ParserStart &operator=(ParserStart &&) = default;
324
325 protected:
326 void print(std::ostream &os) const override;
327
328 DECLARE_TYPEINFO(ParserStart, TraceEvent);
329};
330
331/* =============================================================================================
332 * ParserState
333 * ============================================================================================= */
334
336class ParserState : public TraceEvent {
337 private:
338 const IR::ParserState *state;
339
340 public:
341 explicit ParserState(const IR::ParserState *state);
342 ~ParserState() override = default;
343 ParserState(const ParserState &) = default;
344 ParserState(ParserState &&) = default;
345 ParserState &operator=(const ParserState &) = default;
346 ParserState &operator=(ParserState &&) = default;
347
349 const IR::ParserState *getParserState() const;
350
351 protected:
352 void print(std::ostream &os) const override;
353
354 DECLARE_TYPEINFO(ParserState, TraceEvent);
355};
356
357} // namespace P4::P4Tools::TraceEvents
358
359#endif /* BACKENDS_P4TOOLS_COMMON_LIB_TRACE_EVENT_TYPES_H_ */
Definition backends/p4tools/common/lib/model.h:19
Definition symbolic_env.h:12
An event in a trace of the execution of a P4 program.
Definition trace_event.h:14
Represents an assignment statement.
Definition trace_event_types.h:140
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:185
const AssignmentStatement * evaluate(const Model &model, bool doComplete) const override
Definition trace_event_types.cpp:167
const AssignmentStatement * apply(Transform &visitor) const override
Applies the given IR transform to the expressions in this trace event.
Definition trace_event_types.cpp:160
const AssignmentStatement * subst(const SymbolicEnv &env) const override
Definition trace_event_types.cpp:153
A field being emitted by a deparser.
Definition trace_event_types.h:245
const Emit * evaluate(const Model &model, bool doComplete) const override
Definition trace_event_types.cpp:293
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:298
const Emit * subst(const SymbolicEnv &env) const override
Definition trace_event_types.cpp:284
const Emit * apply(Transform &visitor) const override
Applies the given IR transform to the expressions in this trace event.
Definition trace_event_types.cpp:289
A simple event that stores the provided expression.
Definition trace_event_types.h:64
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
Definition trace_event_types.h:212
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:271
Definition trace_event_types.h:164
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:246
const ExtractSuccess * subst(const SymbolicEnv &env) const override
Definition trace_event_types.cpp:215
const ExtractSuccess * apply(Transform &visitor) const override
Applies the given IR transform to the expressions in this trace event.
Definition trace_event_types.cpp:224
int getOffset() const
Definition trace_event_types.cpp:259
const IR::Expression * getExtractedHeader() const
Definition trace_event_types.cpp:261
const ExtractSuccess * evaluate(const Model &model, bool doComplete) const override
Definition trace_event_types.cpp:233
Definition trace_event_types.h:47
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:34
A generic event that only takes in a string as label.
Definition trace_event_types.h:23
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:25
Represents an if statement condition.
Definition trace_event_types.h:114
const IfStatementCondition * subst(const SymbolicEnv &env) const override
Definition trace_event_types.cpp:105
const IfStatementCondition * evaluate(const Model &model, bool doComplete) const override
Definition trace_event_types.cpp:117
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:130
const IfStatementCondition * apply(Transform &visitor) const override
Applies the given IR transform to the expressions in this trace event.
Definition trace_event_types.cpp:111
Label dedicated to method call expression.
Definition trace_event_types.h:91
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:83
A packet that is either presented to a parser or emitted from a deparser.
Definition trace_event_types.h:273
Direction
Definition trace_event_types.h:275
@ Out
Marks a packet that is emitted from a deparser.
@ In
Marks a packet that is presented to a parser.
const Packet * evaluate(const Model &model, bool doComplete) const override
Definition trace_event_types.cpp:324
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:331
const Packet * apply(Transform &visitor) const override
Applies the given IR transform to the expressions in this trace event.
Definition trace_event_types.cpp:320
const Packet * subst(const SymbolicEnv &env) const override
Definition trace_event_types.cpp:316
Marks the start of a parser.
Definition trace_event_types.h:313
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:357
Marks the entry into a parser state.
Definition trace_event_types.h:336
void print(std::ostream &os) const override
Prints this trace event to the given ostream.
Definition trace_event_types.cpp:365
const IR::ParserState * getParserState() const
Definition trace_event_types.cpp:367
Definition visitor.h:424
Definition cstring.h:85
This file defines explicit types of trace events extended from the generic trace class.
Definition trace_event_types.cpp:17