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
20class TableStepper {
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
44 static const IR::StateVariable &getActiveTableVar();
45
48 static const IR::StateVariable &getTableHitVar(const IR::P4Table *table);
49
54 static const IR::StateVariable &getTableActionVar(const IR::P4Table *table);
55
56 static const IR::StateVariable &getTableResultVar(const IR::P4Table *table);
57
58 protected:
59 /* =========================================================================================
60 * Table Utility functions
61 * ========================================================================================= */
64
67
69 ExprStepper::Result getResult();
70
72 void addDefaultAction(std::optional<const IR::Expression *> tableMissCondition);
73
75 std::vector<const IR::ActionListElement *> buildTableActionList();
76
79 static const IR::StringLiteral *getTableActionString(
80 const IR::MethodCallExpression *actionCall);
81
85 bool resolveTableKeys();
86
92 virtual const IR::Expression *computeTargetMatchType(
93 const TableUtils::KeyProperties &keyProperties, TableMatchMap *matches,
94 const IR::Expression *hitCondition);
95
100 const IR::Expression *computeHit(TableMatchMap *matches);
101
104 virtual void checkTargetProperties(
105 const std::vector<const IR::ActionListElement *> &tableActionList);
106
107 /* =========================================================================================
108 * Table Evaluation functions
109 * ========================================================================================= */
115
123 const IR::Expression *evalTableConstEntries();
124
129 void evalTableControlEntries(const std::vector<const IR::ActionListElement *> &tableActionList);
130
136 void evalTaintedTable();
137
140 virtual void evalTargetTable(const std::vector<const IR::ActionListElement *> &tableActionList);
141
142 void setTableDefaultEntries(const std::vector<const IR::ActionListElement *> &tableActionList);
143
144 public:
150 bool eval();
151
152 explicit TableStepper(ExprStepper *stepper, const IR::P4Table *table);
153
154 virtual ~TableStepper() = default;
155};
156
157} // namespace P4::P4Tools::P4Testgen
158
159#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
static const IR::StateVariable & getActiveTableVar()
Definition core/small_step/table_stepper.cpp:78
void evalTableControlEntries(const std::vector< const IR::ActionListElement * > &tableActionList)
Definition core/small_step/table_stepper.cpp:306
bool eval()
Definition core/small_step/table_stepper.cpp:552
virtual void checkTargetProperties(const std::vector< const IR::ActionListElement * > &tableActionList)
Definition core/small_step/table_stepper.cpp:531
static const IR::StringLiteral * getTableActionString(const IR::MethodCallExpression *actionCall)
Definition core/small_step/table_stepper.cpp:153
const IR::Expression * evalTableConstEntries()
Definition core/small_step/table_stepper.cpp:158
static const IR::StateVariable & getTableHitVar(const IR::P4Table *table)
Definition core/small_step/table_stepper.cpp:82
virtual void evalTargetTable(const std::vector< const IR::ActionListElement * > &tableActionList)
Definition core/small_step/table_stepper.cpp:534
const IR::Expression * computeHit(TableMatchMap *matches)
Definition core/small_step/table_stepper.cpp:145
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:86
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:502
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:433
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:388
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