P4C
The P4 Compiler
Loading...
Searching...
No Matches
abstract_execution_state.h
1#ifndef BACKENDS_P4TOOLS_COMMON_CORE_ABSTRACT_EXECUTION_STATE_H_
2#define BACKENDS_P4TOOLS_COMMON_CORE_ABSTRACT_EXECUTION_STATE_H_
3
4#include "backends/p4tools/common/core/target.h"
5#include "backends/p4tools/common/lib/namespace_context.h"
6#include "backends/p4tools/common/lib/symbolic_env.h"
7#include "ir/ir.h"
8
9namespace P4::P4Tools {
10
13 protected:
17
20
21 /* =========================================================================================
22 * Constructors
23 * ========================================================================================= */
26
29
32
33 public:
35 explicit AbstractExecutionState(const IR::P4Program *program);
36 virtual ~AbstractExecutionState() = default;
38
41 [[nodiscard]] virtual AbstractExecutionState &clone() const = 0;
42
44
45 /* =========================================================================================
46 * Accessors
47 * ========================================================================================= */
48 public:
50 [[nodiscard]] virtual const IR::Expression *get(const IR::StateVariable &var) const = 0;
51
54 virtual void set(const IR::StateVariable &var, const IR::Expression *value) = 0;
55
57 [[nodiscard]] bool exists(const IR::StateVariable &var) const;
58
60 [[nodiscard]] const SymbolicEnv &getSymbolicEnv() const;
61
63 void printSymbolicEnv(std::ostream &out = std::cout) const;
64
65 public:
67 [[nodiscard]] const IR::IDeclaration *findDecl(const IR::Path *path) const;
68
70 [[nodiscard]] const IR::IDeclaration *findDecl(const IR::PathExpression *pathExpr) const;
71
73 [[nodiscard]] const IR::Type *resolveType(const IR::Type *type) const;
74
76 [[nodiscard]] const NamespaceContext *getNamespaceContext() const;
77
80
82 void pushNamespace(const IR::INamespace *ns);
83
85 void popNamespace();
86
87 /* =========================================================================================
88 * General utilities involving ExecutionState.
89 * ========================================================================================= */
90 protected:
94 const IR::Expression *convertToComplexExpression(const IR::StateVariable &parent) const;
95
100 static std::vector<const IR::Expression *> flattenComplexExpression(
101 const IR::Expression *inputExpression, std::vector<const IR::Expression *> &flatValids);
102
103 public:
109 [[nodiscard]] std::vector<IR::StateVariable> getFlatFields(
110 const IR::StateVariable &parent,
111 std::vector<IR::StateVariable> *validVector = nullptr) const;
112
115 void initializeStructLike(const Target &target, const IR::StateVariable &targetVar,
116 bool forceTaint);
117
120 void assignStructLike(const IR::StateVariable &left, const IR::Expression *right);
121
123 void setStructLike(const IR::StateVariable &targetVar, const IR::StateVariable &sourceVar);
124
127 void declareVariable(const Target &target, const IR::Declaration_Variable &declVar);
128
131 void copyIn(const Target &target, const IR::Parameter *internalParam,
132 cstring externalParamName);
133
136 void copyOut(const IR::Parameter *internalParam, cstring externalParamName);
137
140 void initializeBlockParams(const Target &target, const IR::Type_Declaration *typeDecl,
141 const std::vector<cstring> *blockParams);
142
145 const IR::P4Table *findTable(const IR::Member *member) const;
146
147 // Try to extract and @return the IR::P4Action from the action call.
150 [[nodiscard]] const IR::P4Action *getP4Action(const IR::MethodCallExpression *actionExpr) const;
151};
152
153} // namespace P4::P4Tools
154
155#endif /* BACKENDS_P4TOOLS_COMMON_CORE_ABSTRACT_EXECUTION_STATE_H_ */
The Declaration interface, representing objects with names.
Definition declaration.h:26
Represents state of execution after having reached a program point.
Definition abstract_execution_state.h:12
void pushNamespace(const IR::INamespace *ns)
Enters a namespace of declarations.
Definition abstract_execution_state.cpp:67
void copyIn(const Target &target, const IR::Parameter *internalParam, cstring externalParamName)
Definition abstract_execution_state.cpp:289
void initializeStructLike(const Target &target, const IR::StateVariable &targetVar, bool forceTaint)
Definition abstract_execution_state.cpp:173
void declareVariable(const Target &target, const IR::Declaration_Variable &declVar)
Definition abstract_execution_state.cpp:254
virtual void set(const IR::StateVariable &var, const IR::Expression *value)=0
const IR::P4Action * getP4Action(const IR::MethodCallExpression *actionExpr) const
Definition abstract_execution_state.cpp:375
const IR::Expression * convertToComplexExpression(const IR::StateVariable &parent) const
Definition abstract_execution_state.cpp:77
const IR::P4Table * findTable(const IR::Member *member) const
Definition abstract_execution_state.cpp:383
const NamespaceContext * getNamespaceContext() const
Definition abstract_execution_state.cpp:61
SymbolicEnv env
The symbolic environment. Maps program variables to their symbolic values.
Definition abstract_execution_state.h:19
virtual const IR::Expression * get(const IR::StateVariable &var) const =0
const IR::IDeclaration * findDecl(const IR::Path *path) const
Looks up a declaration from a path. A BUG occurs if no declaration is found.
Definition abstract_execution_state.cpp:41
void assignStructLike(const IR::StateVariable &left, const IR::Expression *right)
Definition abstract_execution_state.cpp:186
void initializeBlockParams(const Target &target, const IR::Type_Declaration *typeDecl, const std::vector< cstring > *blockParams)
Definition abstract_execution_state.cpp:343
const SymbolicEnv & getSymbolicEnv() const
Definition abstract_execution_state.cpp:25
bool exists(const IR::StateVariable &var) const
Checks whether the given variable exists in the symbolic environment of this state.
Definition abstract_execution_state.cpp:23
void printSymbolicEnv(std::ostream &out=std::cout) const
Produce a formatted output of the current symbolic environment.
Definition abstract_execution_state.cpp:27
virtual AbstractExecutionState & clone() const =0
static std::vector< const IR::Expression * > flattenComplexExpression(const IR::Expression *inputExpression, std::vector< const IR::Expression * > &flatValids)
Definition abstract_execution_state.cpp:118
const NamespaceContext * namespaces
Definition abstract_execution_state.h:16
AbstractExecutionState(const AbstractExecutionState &)=default
Execution state needs to be explicitly copied using the clone call..
AbstractExecutionState & operator=(const AbstractExecutionState &)=default
Do not accidentally copy-assign the execution state.
void setStructLike(const IR::StateVariable &targetVar, const IR::StateVariable &sourceVar)
Set the members of struct-like @target with the values of struct-like @source.
Definition abstract_execution_state.cpp:232
const IR::Type * resolveType(const IR::Type *type) const
Resolves a Type in the current environment.
Definition abstract_execution_state.cpp:49
std::vector< IR::StateVariable > getFlatFields(const IR::StateVariable &parent, std::vector< IR::StateVariable > *validVector=nullptr) const
Definition abstract_execution_state.cpp:140
AbstractExecutionState()
Used for debugging and testing.
Definition abstract_execution_state.cpp:17
void popNamespace()
Exists a namespace of declarations.
Definition abstract_execution_state.cpp:71
void copyOut(const IR::Parameter *internalParam, cstring externalParamName)
Definition abstract_execution_state.cpp:319
void setNamespaceContext(const NamespaceContext *namespaces)
Replaces the namespace context in the current state with the given context.
Definition abstract_execution_state.cpp:63
Represents a stack of namespaces.
Definition namespace_context.h:14
Definition symbolic_env.h:12
Definition p4tools/common/core/target.h:19
Definition cstring.h:85
Definition common/compiler/compiler_result.cpp:3