P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::P4Tools::P4Testgen::Continuation Class Reference

#include <continuation.h>

Classes

class  Body
 A continuation body is a list of commands. More...
 
struct  Guard
 
class  Parameter
 
struct  PropertyUpdate
 
struct  Return
 

Public Types

using Command
 
enum class  Exception {
  Exit , NoMatch , Reject , Drop ,
  PacketTooShort , Abort
}
 Enumerates the exceptions that can be thrown during symbolic execution. More...
 
using PropertyValue = std::variant<cstring, uint64_t, int64_t, bool, const IR::Expression *>
 

Public Member Functions

 Continuation (Body body)
 Creates a parameterless continuation.
 
 Continuation (std::optional< const Parameter * > parameterOpt, Body body)
 
Body apply (std::optional< const IR::Node * > value_opt) const
 

Static Public Member Functions

static const ParametergenParameter (const IR::Type *type, cstring name, const NamespaceContext *ctx)
 

Public Attributes

Body body
 
std::optional< const IR::PathExpression * > parameterOpt
 Represents the continuation's parameter.
 

Friends

std::ostream & operator<< (std::ostream &out, const Exception value)
 

Detailed Description

A continuation is a function that optionally takes an argument and executes a sequence of commands.

Member Typedef Documentation

◆ Command

using P4::P4Tools::P4Testgen::Continuation::Command
Initial value:
std::variant<
const IR::Node *,
const TraceEvent *,
Return,
PropertyUpdate,
Guard>
Exception
Enumerates the exceptions that can be thrown during symbolic execution.
Definition continuation.h:35

◆ PropertyValue

using P4::P4Tools::P4Testgen::Continuation::PropertyValue = std::variant<cstring, uint64_t, int64_t, bool, const IR::Expression *>

Alias for various property types that can be set. We restrict these to keep the feature simple.

Member Enumeration Documentation

◆ Exception

Enumerates the exceptions that can be thrown during symbolic execution.

Enumerator
Exit 

Thrown when an exit statement is encountered.

NoMatch 

Thrown when a select expression fails to match. This models P4's error.NoMatch.

Reject 

Thrown when the parser reaches the reject state.

Drop 

This is an internal interpreter exception to express drop semantics.

PacketTooShort 

Thrown on premature packet end. Models P4's error.PacketTooShort.

Abort 

Thrown when the target terminates.

Constructor & Destructor Documentation

◆ Continuation()

P4::P4Tools::P4Testgen::Continuation::Continuation ( std::optional< const Parameter * > parameterOpt,
Body body )
inline

Creates a continuation. The continuation will have the given parameter, if one is provided; otherwise, the continuation will have no parameters.

Member Function Documentation

◆ apply()

Continuation::Body P4::P4Tools::P4Testgen::Continuation::apply ( std::optional< const IR::Node * > value_opt) const
Returns
a body that is equivalent to applying this continuation to the given value (or unit, if no value is provided). A BUG occurs if parameterOpt is std::nullopt but value_opt is not, or vice versa.

Expressions in the metalanguage include P4 non-expressions. Because of this, the value (if provided) does not necessarily need to be an instance of IR::Expression.

Creates a visitor for Commands that substitutes the given value for the given parameter.

◆ genParameter()

const Continuation::Parameter * P4::P4Tools::P4Testgen::Continuation::genParameter ( const IR::Type * type,
cstring name,
const NamespaceContext * ctx )
static
Returns
a parameter for use in building continuations. The parameter will be fresh in the given @ctx.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
const Exception value )
friend

A helper function to print the string values of the exception enum. Unfortunately, this is a little clunky to use an maintain because we have to add new enum fields manually. TODO: Find a better implementation to print enums. Also use constexpr instead.