1#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_EXPR_STEPPER_H_
2#define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_EXPR_STEPPER_H_
10#include "lib/cstring.h"
12#include "backends/p4tools/modules/testgen/core/extern_info.h"
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"
17namespace P4::P4Tools::P4Testgen {
26 template <
typename StepperType>
48 std::optional<MethodImpl>
find(
const IR::PathExpression &externObjectRef,
53 const IR::Type_Extern *externType =
nullptr;
54 if (
const auto *type = externObjectRef.type->to<IR::Type_Extern>()) {
56 }
else if (
const auto *specType =
57 externObjectRef.type->to<IR::Type_SpecializedCanonical>()) {
58 CHECK_NULL(specType->substituted);
59 externType = specType->substituted->checkedTo<IR::Type_Extern>();
60 }
else if (externObjectRef.path->name ==
IR::ID(
"*method")) {
62 BUG(
"Not a valid extern: %1% with member %2%. Type is %3%.", externObjectRef,
63 methodName, externObjectRef.type->node_type_name());
66 cstring qualifiedMethodName = externType->name +
"." + methodName;
67 auto submapIt = impls.find(qualifiedMethodName);
68 if (submapIt == impls.end()) {
71 if (submapIt->second.count(args.size()) == 0) {
77 std::optional<MethodImpl> matchingImpl;
78 for (
const auto &pair : submapIt->second.at(args.size())) {
79 const auto ¶mNames = pair.first;
80 const auto &methodImpl = pair.second;
82 if (matches(paramNames, args)) {
83 BUG_CHECK(!matchingImpl,
"Ambiguous extern method call: %1%",
85 matchingImpl = methodImpl;
98 std::map<size_t, std::vector<std::pair<std::vector<cstring>,
MethodImpl>>>>
104 static bool matches(
const std::vector<cstring> ¶mNames,
107 if (paramNames.size() != args.size()) {
111 for (
size_t idx = 0; idx < paramNames.size(); idx++) {
112 const auto ¶mName = paramNames.at(idx);
113 const auto &arg = args.at(idx);
115 if (arg->name.name ==
nullptr) {
118 if (paramName != arg->name.name) {
135 for (
const auto &implSpec : implList) {
136 auto &[name, paramNames, impl] = implSpec;
138 auto &tmpImplList = impls[name][paramNames.size()];
143 for (
auto &pair : tmpImplList) {
144 BUG_CHECK(pair.first != paramNames,
"Multiple implementations of %1%(%2%)",
148 tmpImplList.emplace_back(paramNames, impl);
191 int advanceSize)
const;
198 const IR::Expression *restrictions)
const;
203 static std::vector<std::pair<IR::StateVariable, const IR::Expression *>>
setFields(
204 ExecutionState &nextState,
const std::vector<IR::StateVariable> &flatFields,
205 int varBitFieldSize);
251 void evalActionCall(
const IR::P4Action *action,
const IR::MethodCallExpression *call);
260 const IR::StateVariable &srcPath,
cstring dir,
bool forceTaint)
const;
265 virtual void stepNoMatch(std::string traceLog,
const IR::Expression *condition =
nullptr);
278 bool preorder(
const IR::BoolLiteral *boolLiteral)
override;
279 bool preorder(
const IR::Constant *constant)
override;
280 bool preorder(
const IR::Member *member)
override;
281 bool preorder(
const IR::ArrayIndex *arr)
override;
282 bool preorder(
const IR::MethodCallExpression *call)
override;
283 bool preorder(
const IR::Mux *mux)
override;
284 bool preorder(
const IR::PathExpression *pathExpression)
override;
289 bool preorder(
const IR::P4ValueSet *valueSet)
override;
290 bool preorder(
const IR::Operation_Binary *binary)
override;
291 bool preorder(
const IR::Operation_Unary *unary)
override;
292 bool preorder(
const IR::SelectExpression *selectExpression)
override;
293 bool preorder(
const IR::BaseListExpression *listExpression)
override;
294 bool preorder(
const IR::StructExpression *structExpression)
override;
295 bool preorder(
const IR::AbstractSlice *slice)
override;
296 bool preorder(
const IR::P4Table *table)
override;
Provides a higher-level interface for an SMT solver.
Definition solver.h:24
Definition phv/solver/action_constraint_solver.cpp:33