P4C
The P4 Compiler
Loading...
Searching...
No Matches
core/small_step/table_stepper.h
1/*
2 * SPDX-FileCopyrightText: 2022 The P4 Language Consortium
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_TABLE_STEPPER_H_
8#define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_TABLE_STEPPER_H_
9
10#include <cstddef>
11#include <optional>
12#include <vector>
13
14#include "backends/p4tools/common/lib/table_utils.h"
15#include "ir/ir.h"
16#include "lib/cstring.h"
17
18#include "backends/p4tools/modules/testgen/core/program_info.h"
19#include "backends/p4tools/modules/testgen/core/small_step/expr_stepper.h"
20#include "backends/p4tools/modules/testgen/lib/execution_state.h"
21#include "backends/p4tools/modules/testgen/lib/test_spec.h"
22
23namespace P4::P4Tools::P4Testgen {
24
26class TableStepper {
27 protected:
30
32 const IR::P4Table *table;
33
36
37 public:
38 /* =========================================================================================
39 * Table Variable Getter functions
40 * ========================================================================================= */
45 static const IR::StateVariable &getTableStateVariable(
46 const IR::Type *type, const IR::P4Table *table, cstring name,
47 std::optional<int> idx1_opt = std::nullopt, std::optional<int> idx2_opt = std::nullopt);
48
50 static const IR::StateVariable &getActiveTableVar();
51
54 static const IR::StateVariable &getTableHitVar(const IR::P4Table *table);
55
60 static const IR::StateVariable &getTableActionVar(const IR::P4Table *table);
61
62 static const IR::StateVariable &getTableResultVar(const IR::P4Table *table);
63
64 protected:
65 /* =========================================================================================
66 * Table Utility functions
67 * ========================================================================================= */
70
73
75 ExprStepper::Result getResult();
76
78 void addDefaultAction(std::optional<const IR::Expression *> tableMissCondition);
79
81 std::vector<const IR::ActionListElement *> buildTableActionList();
82
85 static const IR::StringLiteral *getTableActionString(
86 const IR::MethodCallExpression *actionCall);
87
91 bool resolveTableKeys();
92
98 virtual const IR::Expression *computeTargetMatchType(
99 const TableUtils::KeyProperties &keyProperties, TableMatchMap *matches,
100 const IR::Expression *hitCondition);
101
106 const IR::Expression *computeHit(TableMatchMap *matches);
107
110 virtual void checkTargetProperties(
111 const std::vector<const IR::ActionListElement *> &tableActionList);
112
113 /* =========================================================================================
114 * Table Evaluation functions
115 * ========================================================================================= */
121
129 const IR::Expression *evalTableConstEntries();
130
135 void evalTableControlEntries(const std::vector<const IR::ActionListElement *> &tableActionList);
136
142 void evalTaintedTable();
143
146 virtual void evalTargetTable(const std::vector<const IR::ActionListElement *> &tableActionList);
147
148 void setTableDefaultEntries(const std::vector<const IR::ActionListElement *> &tableActionList);
149
150 public:
156 bool eval();
157
158 explicit TableStepper(ExprStepper *stepper, const IR::P4Table *table);
159
160 virtual ~TableStepper() = default;
161};
162
163} // namespace P4::P4Tools::P4Testgen
164
165#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:40
Implements small-step operational semantics for expressions.
Definition core/small_step/expr_stepper.h:26
Stores target-specific information about a P4 program.
Definition core/program_info.h:27
static const IR::StateVariable & getActiveTableVar()
Definition core/small_step/table_stepper.cpp:82
void evalTableControlEntries(const std::vector< const IR::ActionListElement * > &tableActionList)
Definition core/small_step/table_stepper.cpp:310
bool eval()
Definition core/small_step/table_stepper.cpp:582
virtual void checkTargetProperties(const std::vector< const IR::ActionListElement * > &tableActionList)
Definition core/small_step/table_stepper.cpp:561
static const IR::StringLiteral * getTableActionString(const IR::MethodCallExpression *actionCall)
Definition core/small_step/table_stepper.cpp:157
const IR::Expression * evalTableConstEntries()
Definition core/small_step/table_stepper.cpp:162
static const IR::StateVariable & getTableHitVar(const IR::P4Table *table)
Definition core/small_step/table_stepper.cpp:86
virtual void evalTargetTable(const std::vector< const IR::ActionListElement * > &tableActionList)
Definition core/small_step/table_stepper.cpp:564
const IR::Expression * computeHit(TableMatchMap *matches)
Definition core/small_step/table_stepper.cpp:149
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:51
virtual const IR::Expression * computeTargetMatchType(const TableUtils::KeyProperties &keyProperties, TableMatchMap *matches, const IR::Expression *hitCondition)
Definition core/small_step/table_stepper.cpp:90
TableUtils::TableProperties properties
Basic table properties that are set when initializing the TableStepper.
Definition core/small_step/table_stepper.h:35
void addDefaultAction(std::optional< const IR::Expression * > tableMissCondition)
tableMissCondition is true.
Definition core/small_step/table_stepper.cpp:532
const ExecutionState * getExecutionState()
Definition core/small_step/table_stepper.cpp:45
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:47
static const IR::StateVariable & getTableActionVar(const IR::P4Table *table)
Definition core/small_step/table_stepper.cpp:70
bool resolveTableKeys()
Definition core/small_step/table_stepper.cpp:463
const IR::P4Table * table
The table for this particular stepper.
Definition core/small_step/table_stepper.h:32
ExprStepper::Result getResult()
Definition core/small_step/table_stepper.cpp:49
ExprStepper * stepper
Reference to the calling expression stepper.
Definition core/small_step/table_stepper.h:29
void evalTaintedTable()
Definition core/small_step/table_stepper.cpp:418
Definition cstring.h:85
KeyProperties define properties of table keys that are useful for execution.
Definition table_utils.h:16
Basic table properties that are set when initializing the TableStepper.
Definition table_utils.h:39