P4C
The P4 Compiler
P4Tools::Utils Class Reference

General utility functions that are not present in the compiler framework. More...

Static Public Member Functions

template<typename ContainerType >
static std::string containerToString (const ContainerType &container)
 
static const IR::MethodCallExpression * generateInternalMethodCall (cstring methodName, const std::vector< const IR::Expression * > &argVector, const IR::Type *returnType=IR::Type_Void::get(), const IR::ParameterList *paramList=new IR::ParameterList())
 
static std::optional< uint32_t > getCurrentSeed ()
 
static big_int getRandBigInt (big_int max)
 
static const IR::Constant * getRandConstantForType (const IR::Type_Bits *type)
 
static const IR::Constant * getRandConstantForWidth (int bitWidth)
 
static uint64_t getRandInt (uint64_t max)
 
static std::string getTimeStamp ()
 
template<typename Iter >
static Iter pickRandom (Iter start, Iter end)
 
static void setRandomSeed (int seed)
 
template<typename T >
static void shuffle (T *inp)
 Shuffles the given iterable. More...
 

Detailed Description

General utility functions that are not present in the compiler framework.

Member Function Documentation

◆ containerToString()

template<typename ContainerType >
static std::string P4Tools::Utils::containerToString ( const ContainerType &  container)
inlinestatic

Convert a container type (array, set, vector, etc.) into a well-formed [val1, val2, ...] representation. This function is used for debugging output.

◆ generateInternalMethodCall()

const IR::MethodCallExpression * P4Tools::Utils::generateInternalMethodCall ( cstring  methodName,
const std::vector< const IR::Expression * > &  argVector,
const IR::Type *  returnType = IR::Type_Void::get(),
const IR::ParameterList *  paramList = new IR::ParameterList() 
)
static
Returns
a method call to an internal extern consumed by the interpreter. The return type is typically Type_Void.

◆ getCurrentSeed()

std::optional< uint32_t > P4Tools::Utils::getCurrentSeed ( )
static
Returns
currentSeed.

◆ getRandBigInt()

big_int P4Tools::Utils::getRandBigInt ( big_int  max)
static
Returns
a random big integer in the range [0,
Parameters
max].Always return 0 if no seed is set.

◆ getRandConstantForType()

const IR::Constant * P4Tools::Utils::getRandConstantForType ( const IR::Type_Bits *  type)
static
Returns
a IR::Constant with a random big integer that fits the specified
Parameters
type.

◆ getRandConstantForWidth()

const IR::Constant * P4Tools::Utils::getRandConstantForWidth ( int  bitWidth)
static
Returns
a IR::Constant with a random big integer that fits the specified bit width. The type will be an unsigned Type_Bits with
Parameters
bitWidth.

◆ getRandInt()

uint64_t P4Tools::Utils::getRandInt ( uint64_t  max)
static
Returns
a random integer in the range [0,
Parameters
max].Always return 0 if no seed is set.

◆ getTimeStamp()

std::string P4Tools::Utils::getTimeStamp ( )
static

Return the current timestamp with millisecond accuracy. Format: year-month-day-hour:minute:second.millisecond Borrowed from https://stackoverflow.com/a/35157784

◆ pickRandom()

template<typename Iter >
static Iter P4Tools::Utils::pickRandom ( Iter  start,
Iter  end 
)
inlinestatic
Returns
a random element from the given range between
Parameters
startand
end.

◆ shuffle()

template<typename T >
static void P4Tools::Utils::shuffle ( T *  inp)
inlinestatic

Shuffles the given iterable.

Parameters
inp