7#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_EXECUTION_STATE_H_
8#define BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_EXECUTION_STATE_H_
12#include <initializer_list>
21#include "backends/p4tools/common/compiler/reachability.h"
22#include "backends/p4tools/common/core/abstract_execution_state.h"
23#include "backends/p4tools/common/lib/namespace_context.h"
24#include "backends/p4tools/common/lib/symbolic_env.h"
25#include "backends/p4tools/common/lib/trace_event.h"
26#include "ir/declaration.h"
30#include "lib/cstring.h"
31#include "lib/exceptions.h"
32#include "midend/coverage.h"
34#include "backends/p4tools/modules/testgen/lib/continuation.h"
35#include "backends/p4tools/modules/testgen/lib/test_object.h"
37namespace P4::P4Tools::P4Testgen {
46 using ExceptionHandlers = std::map<Continuation::Exception, Continuation>;
50 ExceptionHandlers exceptionHandlers;
56 StackFrame(
Continuation normalContinuation, ExceptionHandlers exceptionHandlers,
59 StackFrame(
const StackFrame &) =
default;
60 StackFrame(StackFrame &&)
noexcept =
default;
61 StackFrame &operator=(
const StackFrame &) =
default;
62 StackFrame &operator=(StackFrame &&) =
default;
63 ~StackFrame() =
default;
82 std::vector<std::reference_wrapper<const TraceEvent>> trace;
99 std::stack<std::reference_wrapper<const StackFrame>> stack;
107 std::map<cstring, Continuation::PropertyValue> stateProperties;
115 std::map<cstring, TestObjectMap> testObjects;
119 std::optional<IR::StateVariable> parserErrorLabel = std::nullopt;
125 int inputPacketCursor = 0;
129 std::vector<const IR::Expression *> pathConstraint;
132 std::vector<uint64_t> selectedBranches;
139 uint16_t numAllocatedPacketVariables = 0;
145 [[nodiscard]]
const IR::SymbolicVariable *createPacketVariable(
const IR::Type *type);
155 [[nodiscard]]
const std::vector<const IR::Expression *> &
getPathConstraint()
const;
170 [[nodiscard]] std::optional<const Continuation::Command>
getNextCmd()
const;
173 [[nodiscard]]
const IR::Expression *
get(
const IR::StateVariable &var)
const override;
183 void set(
const IR::StateVariable &var,
const IR::Expression *value)
override;
186 [[nodiscard]]
const std::vector<std::reference_wrapper<const TraceEvent>> &
getTrace()
const;
192 [[nodiscard]]
const std::stack<std::reference_wrapper<const StackFrame>> &
getStack()
const;
204 auto iterator = stateProperties.find(propertyName);
205 if (
iterator != stateProperties.end()) {
208 T resolvedVal = std::get<T>(val);
210 }
catch (std::bad_variant_access
const &ex) {
211 BUG(
"Expected property value type does not correspond to value type stored in the "
215 BUG(
"Property %s not found in configuration map.", propertyName);
239 const auto *testObject =
getTestObject(category, objectLabel,
true);
240 return testObject->checkedTo<T>();
267 void replaceTopBody(
const std::vector<Continuation::Command> *cmds);
271 void replaceTopBody(std::initializer_list<Continuation::Command> cmds);
280 BUG_CHECK(!nodes->empty(),
"Replaced top of execution stack with empty list");
282 for (
auto it = nodes->rbegin(); it != nodes->rend(); ++it) {
283 BUG_CHECK(*it,
"Evaluation produced a null node.");
310 StackFrame::ExceptionHandlers = {});
318 void popContinuation(std::optional<const IR::Node *> argument_opt = std::nullopt);
415using ExecutionStateReference = std::reference_wrapper<ExecutionState>;
Represents a stack of namespaces.
Definition namespace_context.h:20
A continuation body is a list of commands.
Definition continuation.h:135
std::set< const IR::Node *, SourceIdCmp > CoverageSet
Definition coverage.h:47