P4C
The P4 Compiler
 
Loading...
Searching...
No Matches
expr_stepper.h
1#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_EXPR_STEPPER_H_
2#define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_EXPR_STEPPER_H_
3
4#include <utility>
5#include <vector>
6
7#include "ir/id.h"
8#include "ir/ir.h"
9#include "ir/solver.h"
10#include "ir/vector.h"
11#include "lib/cstring.h"
12
13#include "backends/p4tools/modules/testgen/core/program_info.h"
14#include "backends/p4tools/modules/testgen/core/small_step/abstract_stepper.h"
15#include "backends/p4tools/modules/testgen/lib/execution_state.h"
16
17namespace P4Tools::P4Testgen {
18
21 private:
23 friend class TableStepper;
24
26 friend class ExtractUtils;
27
28 protected:
34
36 const IR::Expression *advanceCond;
37
40
42 const IR::Expression *advanceFailCond;
43 };
44
49 int advanceSize) const;
55 const ExecutionState &state, const IR::Expression *advanceExpr,
56 const IR::Expression *restrictions) const;
57
61 static std::vector<std::pair<IR::StateVariable, const IR::Expression *>> setFields(
62 ExecutionState &nextState, const std::vector<IR::StateVariable> &flatFields,
63 int varBitFieldSize);
68 void handleHitMissActionRun(const IR::Member *member);
69
73 bool resolveMethodCallArguments(const IR::MethodCallExpression *call);
74
86 virtual void evalExternMethodCall(const IR::MethodCallExpression *call,
87 const IR::Expression *receiver, IR::ID name,
101 virtual void evalInternalExternMethodCall(const IR::MethodCallExpression *call,
102 const IR::Expression *receiver, IR::ID name,
103 const IR::Vector<IR::Argument> *args,
104 const ExecutionState &state);
105
113 void evalActionCall(const IR::P4Action *action, const IR::MethodCallExpression *call);
114
119 // Otherwise, the target default value is chosen.
121 void generateCopyIn(ExecutionState &nextState, const IR::StateVariable &targetPath,
122 const IR::StateVariable &srcPath, cstring dir, bool forceTaint) const;
123
127 virtual void stepNoMatch(std::string traceLog, const IR::Expression *condition = nullptr);
128
129 public:
130 ExprStepper(const ExprStepper &) = default;
131
132 ExprStepper(ExprStepper &&) = default;
133
134 ExprStepper &operator=(const ExprStepper &) = delete;
135
136 ExprStepper &operator=(ExprStepper &&) = delete;
137
139
140 bool preorder(const IR::BoolLiteral *boolLiteral) override;
141 bool preorder(const IR::Constant *constant) override;
142 bool preorder(const IR::Member *member) override;
143 bool preorder(const IR::ArrayIndex *arr) override;
144 bool preorder(const IR::MethodCallExpression *call) override;
145 bool preorder(const IR::Mux *mux) override;
146 bool preorder(const IR::PathExpression *pathExpression) override;
147
151 bool preorder(const IR::P4ValueSet *valueSet) override;
152 bool preorder(const IR::Operation_Binary *binary) override;
153 bool preorder(const IR::Operation_Unary *unary) override;
154 bool preorder(const IR::SelectExpression *selectExpression) override;
155 bool preorder(const IR::BaseListExpression *listExpression) override;
156 bool preorder(const IR::StructExpression *structExpression) override;
157 bool preorder(const IR::Slice *slice) override;
158 bool preorder(const IR::P4Table *table) override;
159};
160
161} // namespace P4Tools::P4Testgen
162
163#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_EXPR_STEPPER_H_ */
Definition externInstance.h:33
Definition abstract_stepper.h:28
ExecutionState & state
The state being evaluated.
Definition abstract_stepper.h:49
const ProgramInfo & programInfo
Target-specific information about the P4 program being evaluated.
Definition abstract_stepper.h:46
AbstractSolver & solver
The solver backing the state being executed.
Definition abstract_stepper.h:52
Represents state of execution after having reached a program point.
Definition execution_state.h:34
Implements small-step operational semantics for expressions.
Definition expr_stepper.h:20
void handleHitMissActionRun(const IR::Member *member)
Definition expr_stepper.cpp:51
virtual void evalExternMethodCall(const IR::MethodCallExpression *call, const IR::Expression *receiver, IR::ID name, const IR::Vector< IR::Argument > *args, ExecutionState &state)
Definition extern_stepper.cpp:339
virtual void evalInternalExternMethodCall(const IR::MethodCallExpression *call, const IR::Expression *receiver, IR::ID name, const IR::Vector< IR::Argument > *args, const ExecutionState &state)
Definition extern_stepper.cpp:146
virtual PacketCursorAdvanceInfo calculateSuccessfulParserAdvance(const ExecutionState &state, int advanceSize) const
Definition extern_stepper.cpp:87
int advanceSize
How much the parser cursor will be advanced in a successful parsing case.
Definition expr_stepper.h:33
const IR::Expression * advanceFailCond
The condition that needs to be satisfied for the advance/extract to be rejected.
Definition expr_stepper.h:42
friend class ExtractUtils
Extract utils may access some protected members of the expression stepper.
Definition expr_stepper.h:26
virtual void stepNoMatch(std::string traceLog, const IR::Expression *condition=nullptr)
Definition expr_stepper.cpp:511
bool resolveMethodCallArguments(const IR::MethodCallExpression *call)
Definition expr_stepper.cpp:125
void generateCopyIn(ExecutionState &nextState, const IR::StateVariable &targetPath, const IR::StateVariable &srcPath, cstring dir, bool forceTaint) const
TODO: Consolidate this into the copy_in_out extern.
const IR::Expression * advanceCond
The condition that needs to be satisfied to successfully advance the parser cursor.
Definition expr_stepper.h:36
int advanceFailSize
Specifies at what point the parser cursor advancement will fail.
Definition expr_stepper.h:39
static std::vector< std::pair< IR::StateVariable, const IR::Expression * > > setFields(ExecutionState &nextState, const std::vector< IR::StateVariable > &flatFields, int varBitFieldSize)
Definition extern_stepper.cpp:36
void evalActionCall(const IR::P4Action *action, const IR::MethodCallExpression *call)
Definition expr_stepper.cpp:98
virtual PacketCursorAdvanceInfo calculateAdvanceExpression(const ExecutionState &state, const IR::Expression *advanceExpr, const IR::Expression *restrictions) const
Definition extern_stepper.cpp:99
Stores target-specific information about a P4 program.
Definition program_info.h:22
Implements small-step operational semantics for tables.
Definition table_stepper.h:20
Definition cstring.h:72