P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::P4Tools::AbstractExecutionState Class Referenceabstract

Represents state of execution after having reached a program point. More...

#include <abstract_execution_state.h>

Inheritance diagram for P4::P4Tools::AbstractExecutionState:
[legend]

Public Member Functions

 AbstractExecutionState (AbstractExecutionState &&)=default
 
 AbstractExecutionState (const IR::P4Program *program)
 Creates an initial execution state for the given program.
 
void assignStructLike (const IR::StateVariable &left, const IR::Expression *right)
 
virtual AbstractExecutionStateclone () const =0
 
void copyIn (const Target &target, const IR::Parameter *internalParam, cstring externalParamName)
 
void copyOut (const IR::Parameter *internalParam, cstring externalParamName)
 
void declareVariable (const Target &target, const IR::Declaration_Variable &declVar)
 
bool exists (const IR::StateVariable &var) const
 Checks whether the given variable exists in the symbolic environment of this state.
 
const IR::IDeclarationfindDecl (const IR::Path *path) const
 Looks up a declaration from a path. A BUG occurs if no declaration is found.
 
const IR::IDeclarationfindDecl (const IR::PathExpression *pathExpr) const
 Looks up a declaration from a path expression. A BUG occurs if no declaration is found.
 
const IR::P4Table * findTable (const IR::Member *member) const
 
virtual const IR::Expression * get (const IR::StateVariable &var) const =0
 
std::vector< IR::StateVariable > getFlatFields (const IR::StateVariable &parent, std::vector< IR::StateVariable > *validVector=nullptr) const
 
const NamespaceContextgetNamespaceContext () const
 
const IR::P4Action * getP4Action (const IR::MethodCallExpression *actionExpr) const
 
const SymbolicEnvgetSymbolicEnv () const
 
void initializeBlockParams (const Target &target, const IR::Type_Declaration *typeDecl, const std::vector< cstring > *blockParams)
 
void initializeStructLike (const Target &target, const IR::StateVariable &targetVar, bool forceTaint)
 
AbstractExecutionStateoperator= (AbstractExecutionState &&)=delete
 
void popNamespace ()
 Exists a namespace of declarations.
 
void printSymbolicEnv (std::ostream &out=std::cout) const
 Produce a formatted output of the current symbolic environment.
 
void pushNamespace (const IR::INamespace *ns)
 Enters a namespace of declarations.
 
const IR::Type * resolveType (const IR::Type *type) const
 Resolves a Type in the current environment.
 
virtual void set (const IR::StateVariable &var, const IR::Expression *value)=0
 
void setNamespaceContext (const NamespaceContext *namespaces)
 Replaces the namespace context in the current state with the given context.
 
void setStructLike (const IR::StateVariable &targetVar, const IR::StateVariable &sourceVar)
 Set the members of struct-like @target with the values of struct-like @source.
 

Protected Member Functions

 AbstractExecutionState ()
 Used for debugging and testing.
 
 AbstractExecutionState (const AbstractExecutionState &)=default
 Execution state needs to be explicitly copied using the clone call..
 
const IR::Expression * convertToComplexExpression (const IR::StateVariable &parent) const
 
AbstractExecutionStateoperator= (const AbstractExecutionState &)=default
 Do not accidentally copy-assign the execution state.
 

Static Protected Member Functions

static std::vector< const IR::Expression * > flattenComplexExpression (const IR::Expression *inputExpression, std::vector< const IR::Expression * > &flatValids)
 

Protected Attributes

SymbolicEnv env
 The symbolic environment. Maps program variables to their symbolic values.
 
const NamespaceContextnamespaces
 

Detailed Description

Represents state of execution after having reached a program point.

Member Function Documentation

◆ assignStructLike()

void P4::P4Tools::AbstractExecutionState::assignStructLike ( const IR::StateVariable & left,
const IR::Expression * right )

Assign a struct-like expression to

Parameters
left.Unrolls
rightinto a series of individual assignments.

◆ clone()

virtual AbstractExecutionState & P4::P4Tools::AbstractExecutionState::clone ( ) const
nodiscardpure virtual

Allocate a new execution state object with the same state as this object. Returns a reference, not a pointer.

Implemented in P4::P4Tools::P4Testgen::ExecutionState.

◆ convertToComplexExpression()

const IR::Expression * P4::P4Tools::AbstractExecutionState::convertToComplexExpression ( const IR::StateVariable & parent) const
protected

Convert the input reference into a complex expression such as a HeaderExpression, StructExpression, or HeaderStackExpression.

Returns
nullptr if the expression is not complex.

◆ copyIn()

void P4::P4Tools::AbstractExecutionState::copyIn ( const Target & target,
const IR::Parameter * internalParam,
cstring externalParamName )

Copy the values referenced by

Parameters

externalParamName into the values references by

Parameters

internalParam. Any parameter with the direction "out" is de-initialized.

◆ copyOut()

void P4::P4Tools::AbstractExecutionState::copyOut ( const IR::Parameter * internalParam,
cstring externalParamName )

Copy the values referenced by

Parameters

internalParam into the values references by

Parameters

externalParamName. Only parameters with the direction out or inout are copied.

◆ declareVariable()

void P4::P4Tools::AbstractExecutionState::declareVariable ( const Target & target,
const IR::Declaration_Variable & declVar )

Initialize a Declaration_Variable to its default value. Does not expect an initializer.

◆ findTable()

const IR::P4Table * P4::P4Tools::AbstractExecutionState::findTable ( const IR::Member * member) const

Looks up the

Parameters
memberin the environment of
state.Returns nullptr if the member is not a table type.

◆ flattenComplexExpression()

std::vector< const IR::Expression * > P4::P4Tools::AbstractExecutionState::flattenComplexExpression ( const IR::Expression * inputExpression,
std::vector< const IR::Expression * > & flatValids )
staticprotected

Takes in a complex expression as a StructExpression, ListExpression, or HeaderStackExpression, flattens it into a vector and

Returns
this vector. In parallel this function fills a vector of the validity variables of any Type_Header encountered in this expression.

◆ get()

virtual const IR::Expression * P4::P4Tools::AbstractExecutionState::get ( const IR::StateVariable & var) const
nodiscardpure virtual
Returns
the value associated with the given state variable.

Implemented in P4::P4Tools::P4Testgen::ExecutionState.

◆ getFlatFields()

std::vector< IR::StateVariable > P4::P4Tools::AbstractExecutionState::getFlatFields ( const IR::StateVariable & parent,
std::vector< IR::StateVariable > * validVector = nullptr ) const
nodiscard

Takes an input struct type @ts and a prefix @parent and returns a vector of references to members of the struct. The vector contains all the Type_Base (bit and bool) members in canonical representation (e.g., {"prefix.h.ethernet.dst_address", "prefix.h.ethernet.src_address", ...}). If

  • validVector is provided, this function also collects the validity bits of the headers.

◆ getNamespaceContext()

const NamespaceContext * P4::P4Tools::AbstractExecutionState::getNamespaceContext ( ) const
nodiscard
Returns
the current namespace context.

◆ getP4Action()

const IR::P4Action * P4::P4Tools::AbstractExecutionState::getP4Action ( const IR::MethodCallExpression * actionExpr) const
nodiscard

This is done by looking up the reference in the execution state. Throws a BUG, if the action does not exist.

◆ getSymbolicEnv()

const SymbolicEnv & P4::P4Tools::AbstractExecutionState::getSymbolicEnv ( ) const
nodiscard
Returns
the current symbolic environment.

◆ initializeBlockParams()

void P4::P4Tools::AbstractExecutionState::initializeBlockParams ( const Target & target,
const IR::Type_Declaration * typeDecl,
const std::vector< cstring > * blockParams )

Initialize a set of parameters contained in

Parameters

blockParams to their default values. The default values are specified by the target.

◆ initializeStructLike()

void P4::P4Tools::AbstractExecutionState::initializeStructLike ( const Target & target,
const IR::StateVariable & targetVar,
bool forceTaint )

Initialize all the members of a struct-like object by calling the initialization function of the active target. Headers validity is set to "false".

◆ set()

virtual void P4::P4Tools::AbstractExecutionState::set ( const IR::StateVariable & var,
const IR::Expression * value )
pure virtual

Sets the symbolic value of the given state variable to the given value. Constant folding is done on the given value before updating the symbolic state.

Implemented in P4::P4Tools::P4Testgen::ExecutionState.

Member Data Documentation

◆ namespaces

const NamespaceContext* P4::P4Tools::AbstractExecutionState::namespaces
protected

The namespace context in the IR for the current state. The innermost element is the P4 program, representing the top-level namespace.