P4C
The P4 Compiler
Loading...
Searching...
No Matches
abstract_stepper.h
1#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_ABSTRACT_STEPPER_H_
2#define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_ABSTRACT_STEPPER_H_
3
4#include <functional>
5#include <optional>
6#include <string>
7
8#include "ir/ir.h"
9#include "ir/node.h"
10#include "ir/solver.h"
11#include "ir/vector.h"
12#include "ir/visitor.h"
13
14#include "backends/p4tools/modules/testgen/core/program_info.h"
15#include "backends/p4tools/modules/testgen/core/small_step/small_step.h"
16#include "backends/p4tools/modules/testgen/lib/continuation.h"
17#include "backends/p4tools/modules/testgen/lib/execution_state.h"
18
19namespace P4::P4Tools::P4Testgen {
20
28class AbstractStepper : public Inspector {
29 public:
31 using Result = SmallStepEvaluator::Result;
32
37 Result step(const IR::Node *);
38
40 bool preorder(const IR::Node *) override;
41
43
44 protected:
47
50
53
55 Result result;
56
58 virtual std::string getClassName() = 0;
59
60 virtual const ProgramInfo &getProgramInfo() const;
61
63 void logStep(const IR::Node *node);
64
69 static void checkMemberInvariant(const IR::Node *node);
70
71 /* *****************************************************************************************
72 * Transition helper functions
73 * ***************************************************************************************** */
74
80 bool stepSymbolicValue(const IR::Node *);
81
85
93 static bool stepToSubexpr(
94 const IR::Expression *subexpr, SmallStepEvaluator::Result &result,
95 const ExecutionState &state,
96 std::function<const Continuation::Command(const Continuation::Parameter *)> rebuildCmd);
97
108 static bool stepToListSubexpr(
109 const IR::BaseListExpression *subexpr, SmallStepEvaluator::Result &result,
110 const ExecutionState &state,
111 std::function<const Continuation::Command(const IR::BaseListExpression *)> rebuildCmd);
112
116 static bool stepToStructSubexpr(
117 const IR::StructExpression *subexpr, SmallStepEvaluator::Result &result,
118 const ExecutionState &state,
119 std::function<const Continuation::Command(const IR::StructExpression *)> rebuildCmd);
120
127 bool stepGetHeaderValidity(const IR::StateVariable &headerRef);
128
131 void setHeaderValidity(const IR::StateVariable &headerRef, bool validity,
133
141 bool stepSetHeaderValidity(const IR::StateVariable &headerRef, bool validity);
142
151 bool stepStackPushPopFront(const IR::Expression *stackRef, const IR::Vector<IR::Argument> *args,
152 bool isPush = true);
153
158 const IR::Literal *evaluateExpression(const IR::Expression *expr,
159 std::optional<const IR::Expression *> cond) const;
160
165 void setTargetUninitialized(ExecutionState &nextState, const IR::StateVariable &ref,
166 bool forceTaint) const;
167
171 void declareStructLike(ExecutionState &nextState, const IR::StateVariable &parentExpr,
172 bool forceTaint = false) const;
173
176 void declareBaseType(ExecutionState &nextState, const IR::StateVariable &paramPath,
177 const IR::Type_Base *baseType) const;
178};
179
180} // namespace P4::P4Tools::P4Testgen
181
182#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_ABSTRACT_STEPPER_H_ */
Provides a higher-level interface for an SMT solver.
Definition solver.h:24
Definition node.h:95
Definition vector.h:59
Definition visitor.h:400
Definition abstract_stepper.h:28
const IR::Literal * evaluateExpression(const IR::Expression *expr, std::optional< const IR::Expression * > cond) const
Definition abstract_stepper.cpp:324
void declareStructLike(ExecutionState &nextState, const IR::StateVariable &parentExpr, bool forceTaint=false) const
Definition abstract_stepper.cpp:370
static bool stepToListSubexpr(const IR::BaseListExpression *subexpr, SmallStepEvaluator::Result &result, const ExecutionState &state, std::function< const Continuation::Command(const IR::BaseListExpression *)> rebuildCmd)
Definition abstract_stepper.cpp:105
static bool stepToStructSubexpr(const IR::StructExpression *subexpr, SmallStepEvaluator::Result &result, const ExecutionState &state, std::function< const Continuation::Command(const IR::StructExpression *)> rebuildCmd)
Definition abstract_stepper.cpp:149
bool stepToException(Continuation::Exception)
Definition abstract_stepper.cpp:77
ExecutionState & state
The state being evaluated.
Definition abstract_stepper.h:49
void declareBaseType(ExecutionState &nextState, const IR::StateVariable &paramPath, const IR::Type_Base *baseType) const
Definition abstract_stepper.cpp:387
static void checkMemberInvariant(const IR::Node *node)
Definition abstract_stepper.cpp:54
Result step(const IR::Node *)
Definition abstract_stepper.cpp:34
bool preorder(const IR::Node *) override
Provides generic handling of unsupported nodes.
Definition abstract_stepper.cpp:39
Result result
The output of the evaluation.
Definition abstract_stepper.h:55
bool stepSetHeaderValidity(const IR::StateVariable &headerRef, bool validity)
Definition abstract_stepper.cpp:248
void setTargetUninitialized(ExecutionState &nextState, const IR::StateVariable &ref, bool forceTaint) const
Definition abstract_stepper.cpp:346
bool stepSymbolicValue(const IR::Node *)
Definition abstract_stepper.cpp:66
bool stepGetHeaderValidity(const IR::StateVariable &headerRef)
Definition abstract_stepper.cpp:183
const ProgramInfo & programInfo
Target-specific information about the P4 program being evaluated.
Definition abstract_stepper.h:46
virtual std::string getClassName()=0
AbstractSolver & solver
The solver backing the state being executed.
Definition abstract_stepper.h:52
void logStep(const IR::Node *node)
Helper function for debugging execution of small stepper.
Definition abstract_stepper.cpp:47
static bool stepToSubexpr(const IR::Expression *subexpr, SmallStepEvaluator::Result &result, const ExecutionState &state, std::function< const Continuation::Command(const Continuation::Parameter *)> rebuildCmd)
Definition abstract_stepper.cpp:83
void setHeaderValidity(const IR::StateVariable &headerRef, bool validity, ExecutionState &state)
Definition abstract_stepper.cpp:213
bool stepStackPushPopFront(const IR::Expression *stackRef, const IR::Vector< IR::Argument > *args, bool isPush=true)
Definition abstract_stepper.cpp:294
Exception
Enumerates the exceptions that can be thrown during symbolic execution.
Definition continuation.h:35
Represents state of execution after having reached a program point.
Definition execution_state.h:34
Stores target-specific information about a P4 program.
Definition core/program_info.h:21
Definition phv/solver/action_constraint_solver.cpp:33