P4C
The P4 Compiler
 
Loading...
Searching...
No Matches
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 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 const IR::StringLiteral *getTableActionString(const IR::MethodCallExpression *actionCall);
77
81 bool resolveTableKeys();
82
88 virtual const IR::Expression *computeTargetMatchType(
89 const TableUtils::KeyProperties &keyProperties, TableMatchMap *matches,
90 const IR::Expression *hitCondition);
91
96 const IR::Expression *computeHit(TableMatchMap *matches);
97
100 virtual void checkTargetProperties(
101 const std::vector<const IR::ActionListElement *> &tableActionList);
102
103 /* =========================================================================================
104 * Table Evaluation functions
105 * ========================================================================================= */
111
119 const IR::Expression *evalTableConstEntries();
120
125 void evalTableControlEntries(const std::vector<const IR::ActionListElement *> &tableActionList);
126
132 void evalTaintedTable();
133
136 virtual void evalTargetTable(const std::vector<const IR::ActionListElement *> &tableActionList);
137
138 void setTableDefaultEntries(const std::vector<const IR::ActionListElement *> &tableActionList);
139
140 public:
146 bool eval();
147
148 explicit TableStepper(ExprStepper *stepper, const IR::P4Table *table);
149
150 virtual ~TableStepper() = default;
151};
152
153} // namespace P4Tools::P4Testgen
154
155#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 expr_stepper.h:20
Stores target-specific information about a P4 program.
Definition program_info.h:22
Implements small-step operational semantics for tables.
Definition table_stepper.h:20
const IR::Expression * evalTableConstEntries()
Definition table_stepper.cpp:155
virtual const IR::Expression * computeTargetMatchType(const TableUtils::KeyProperties &keyProperties, TableMatchMap *matches, const IR::Expression *hitCondition)
Definition table_stepper.cpp:82
ExprStepper * stepper
Reference to the calling expression stepper.
Definition table_stepper.h:23
std::vector< const IR::ActionListElement * > buildTableActionList()
Helper function that collects the list of actions contained in the table.
static const IR::StateVariable & getTableHitVar(const IR::P4Table *table)
Definition table_stepper.cpp:78
const IR::Expression * computeHit(TableMatchMap *matches)
Definition table_stepper.cpp:141
virtual void evalTargetTable(const std::vector< const IR::ActionListElement * > &tableActionList)
Definition table_stepper.cpp:523
const IR::StringLiteral * getTableActionString(const IR::MethodCallExpression *actionCall)
Definition table_stepper.cpp:149
virtual void checkTargetProperties(const std::vector< const IR::ActionListElement * > &tableActionList)
Definition table_stepper.cpp:520
const ExecutionState * getExecutionState()
Definition table_stepper.cpp:41
const IR::P4Table * table
The table for this particular stepper.
Definition table_stepper.h:26
void evalTaintedTable()
Definition table_stepper.cpp:382
void addDefaultAction(std::optional< const IR::Expression * > tableMissCondition)
tableMissCondition is true.
Definition table_stepper.cpp:492
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 table_stepper.cpp:47
TableUtils::TableProperties properties
Basic table properties that are set when initializing the TableStepper.
Definition table_stepper.h:29
static const IR::StateVariable & getTableActionVar(const IR::P4Table *table)
Definition table_stepper.cpp:66
void evalTableControlEntries(const std::vector< const IR::ActionListElement * > &tableActionList)
Definition table_stepper.cpp:301
bool eval()
Definition table_stepper.cpp:541
ExprStepper::Result getResult()
Definition table_stepper.cpp:45
bool resolveTableKeys()
Definition table_stepper.cpp:423
const ProgramInfo * getProgramInfo()
Definition table_stepper.cpp:43
Definition cstring.h:72
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