P4C
The P4 Compiler
Loading...
Searching...
No Matches
small_step.h
1/*
2 * SPDX-FileCopyrightText: 2022 The P4 Language Consortium
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_SMALL_STEP_H_
8#define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_SMALL_STEP_H_
9
10#include <cstdint>
11#include <functional>
12#include <optional>
13#include <utility>
14#include <vector>
15
16#include "backends/p4tools/common/compiler/reachability.h"
17#include "ir/node.h"
18#include "ir/solver.h"
19#include "midend/coverage.h"
20
21#include "backends/p4tools/modules/testgen/core/program_info.h"
22#include "backends/p4tools/modules/testgen/lib/execution_state.h"
23
24namespace P4::P4Tools::P4Testgen {
25
28class SmallStepEvaluator {
29 friend class CommandVisitor;
30
31 public:
34 struct Branch {
35 const Constraint *constraint;
36
37 ExecutionStateReference nextState;
38
39 P4::Coverage::CoverageSet potentialNodes;
40
42 explicit Branch(ExecutionState &nextState);
43
46 Branch(std::optional<const Constraint *> c, const ExecutionState &prevState,
47 ExecutionState &nextState);
48
51 Branch(std::optional<const Constraint *> c, const ExecutionState &prevState,
52 ExecutionState &nextState, P4::Coverage::CoverageSet potentialNodes);
53 };
54
55 using Result = std::vector<Branch> *;
56
59 static constexpr uint64_t MAX_GUARD_VIOLATIONS = 100;
60
61 private:
63 const ProgramInfo &programInfo;
64
67
69 uint64_t violatedGuardConditions = 0;
70
72 ReachabilityEngine *reachabilityEngine = nullptr;
73
74 using REngineType = std::pair<ReachabilityResult, std::vector<SmallStepEvaluator::Branch> *>;
75
76 static void renginePostprocessing(ReachabilityResult &result,
77 std::vector<SmallStepEvaluator::Branch> *branches);
78
79 REngineType renginePreprocessing(SmallStepEvaluator &stepper, const ExecutionState &nextState,
80 const IR::Node *node);
81
82 public:
83 Result step(ExecutionState &state);
84
85 SmallStepEvaluator(AbstractSolver &solver, const ProgramInfo &programInfo);
86};
87
88} // namespace P4::P4Tools::P4Testgen
89
90#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_SMALL_STEP_H_ */
Provides a higher-level interface for an SMT solver.
Definition solver.h:30
Definition node.h:53
Represents state of execution after having reached a program point.
Definition execution_state.h:40
Stores target-specific information about a P4 program.
Definition core/program_info.h:27
static constexpr uint64_t MAX_GUARD_VIOLATIONS
Definition small_step.h:59
Definition reachability.h:159
std::set< const IR::Node *, SourceIdCmp > CoverageSet
Definition coverage.h:47
IR::Expression Constraint
Represents a constraint that can be shipped to and asserted within a solver.
Definition solver.h:23
Definition phv/solver/action_constraint_solver.cpp:33
Branch(ExecutionState &nextState)
Simple branch without any constraint.
Definition small_step.cpp:37