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