P4C
The P4 Compiler
Loading...
Searching...
No Matches
core/small_step/table_stepper.h
1#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_TABLE_STEPPER_H_
2#define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_TABLE_STEPPER_H_
3
4#include <cstddef>
5#include <optional>
6#include <vector>
7
8#include "backends/p4tools/common/lib/table_utils.h"
9#include "ir/ir.h"
10#include "lib/cstring.h"
11
12#include "backends/p4tools/modules/testgen/core/program_info.h"
13#include "backends/p4tools/modules/testgen/core/small_step/expr_stepper.h"
14#include "backends/p4tools/modules/testgen/lib/execution_state.h"
15#include "backends/p4tools/modules/testgen/lib/test_spec.h"
16
17namespace P4::P4Tools::P4Testgen {
18
21 protected:
24
26 const IR::P4Table *table;
27
30
31 public:
32 /* =========================================================================================
33 * Table Variable Getter functions
34 * ========================================================================================= */
39 static const IR::StateVariable &getTableStateVariable(
40 const IR::Type *type, const IR::P4Table *table, cstring name,
41 std::optional<int> idx1_opt = std::nullopt, std::optional<int> idx2_opt = std::nullopt);
42
45 static const IR::StateVariable &getTableHitVar(const IR::P4Table *table);
46
51 static const IR::StateVariable &getTableActionVar(const IR::P4Table *table);
52
53 static const IR::StateVariable &getTableResultVar(const IR::P4Table *table);
54
55 protected:
56 /* =========================================================================================
57 * Table Utility functions
58 * ========================================================================================= */
61
64
66 ExprStepper::Result getResult();
67
69 void addDefaultAction(std::optional<const IR::Expression *> tableMissCondition);
70
72 std::vector<const IR::ActionListElement *> buildTableActionList();
73
76 static const IR::StringLiteral *getTableActionString(
77 const IR::MethodCallExpression *actionCall);
78
82 bool resolveTableKeys();
83
89 virtual const IR::Expression *computeTargetMatchType(
90 const TableUtils::KeyProperties &keyProperties, TableMatchMap *matches,
91 const IR::Expression *hitCondition);
92
97 const IR::Expression *computeHit(TableMatchMap *matches);
98
101 virtual void checkTargetProperties(
102 const std::vector<const IR::ActionListElement *> &tableActionList);
103
104 /* =========================================================================================
105 * Table Evaluation functions
106 * ========================================================================================= */
112
120 const IR::Expression *evalTableConstEntries();
121
126 void evalTableControlEntries(const std::vector<const IR::ActionListElement *> &tableActionList);
127
133 void evalTaintedTable();
134
137 virtual void evalTargetTable(const std::vector<const IR::ActionListElement *> &tableActionList);
138
139 void setTableDefaultEntries(const std::vector<const IR::ActionListElement *> &tableActionList);
140
141 public:
147 bool eval();
148
149 explicit TableStepper(ExprStepper *stepper, const IR::P4Table *table);
150
151 virtual ~TableStepper() = default;
152};
153
154} // namespace P4::P4Tools::P4Testgen
155
156#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_TABLE_STEPPER_H_ */
Represents state of execution after having reached a program point.
Definition execution_state.h:34
Implements small-step operational semantics for expressions.
Definition core/small_step/expr_stepper.h:20
Stores target-specific information about a P4 program.
Definition core/program_info.h:21
Implements small-step operational semantics for tables.
Definition core/small_step/table_stepper.h:20
void evalTableControlEntries(const std::vector< const IR::ActionListElement * > &tableActionList)
Definition core/small_step/table_stepper.cpp:300
bool eval()
Definition core/small_step/table_stepper.cpp:540
virtual void checkTargetProperties(const std::vector< const IR::ActionListElement * > &tableActionList)
Definition core/small_step/table_stepper.cpp:519
static const IR::StringLiteral * getTableActionString(const IR::MethodCallExpression *actionCall)
Definition core/small_step/table_stepper.cpp:149
const IR::Expression * evalTableConstEntries()
Definition core/small_step/table_stepper.cpp:154
static const IR::StateVariable & getTableHitVar(const IR::P4Table *table)
Definition core/small_step/table_stepper.cpp:78
virtual void evalTargetTable(const std::vector< const IR::ActionListElement * > &tableActionList)
Definition core/small_step/table_stepper.cpp:522
const IR::Expression * computeHit(TableMatchMap *matches)
Definition core/small_step/table_stepper.cpp:141
static const IR::StateVariable & getTableStateVariable(const IR::Type *type, const IR::P4Table *table, cstring name, std::optional< int > idx1_opt=std::nullopt, std::optional< int > idx2_opt=std::nullopt)
Definition core/small_step/table_stepper.cpp:47
virtual const IR::Expression * computeTargetMatchType(const TableUtils::KeyProperties &keyProperties, TableMatchMap *matches, const IR::Expression *hitCondition)
Definition core/small_step/table_stepper.cpp:82
TableUtils::TableProperties properties
Basic table properties that are set when initializing the TableStepper.
Definition core/small_step/table_stepper.h:29
void addDefaultAction(std::optional< const IR::Expression * > tableMissCondition)
tableMissCondition is true.
Definition core/small_step/table_stepper.cpp:491
const ExecutionState * getExecutionState()
Definition core/small_step/table_stepper.cpp:41
std::vector< const IR::ActionListElement * > buildTableActionList()
Helper function that collects the list of actions contained in the table.
const ProgramInfo * getProgramInfo()
Definition core/small_step/table_stepper.cpp:43
static const IR::StateVariable & getTableActionVar(const IR::P4Table *table)
Definition core/small_step/table_stepper.cpp:66
bool resolveTableKeys()
Definition core/small_step/table_stepper.cpp:422
const IR::P4Table * table
The table for this particular stepper.
Definition core/small_step/table_stepper.h:26
ExprStepper::Result getResult()
Definition core/small_step/table_stepper.cpp:45
ExprStepper * stepper
Reference to the calling expression stepper.
Definition core/small_step/table_stepper.h:23
void evalTaintedTable()
Definition core/small_step/table_stepper.cpp:381
Definition cstring.h:85
KeyProperties define properties of table keys that are useful for execution.
Definition table_utils.h:10
Basic table properties that are set when initializing the TableStepper.
Definition table_utils.h:33