P4C
The P4 Compiler
|
TODO(antonin): High level goals of the generator go here!! More...
Namespaces | |
namespace | Helpers |
namespace | Standard |
Declarations specific to standard architectures (v1model & PSA). | |
Classes | |
struct | ActionRef |
struct | ControllerType |
See section "User-defined types" in P4RT specification. More... | |
struct | DefaultAction |
The information about a default action which is needed to serialize it. More... | |
class | FieldIdAllocator |
class | FlattenHeader |
Flattens a header type "locally", without modifying the IR. More... | |
struct | MatchField |
The information about a match field which is needed to serialize it. More... | |
class | P4InfoMaps |
class | P4RuntimeAnalyzer |
struct | P4RuntimeArchHandlerBuilderIface |
class | P4RuntimeArchHandlerIface |
class | P4RuntimeEntriesConverter |
class | P4RuntimeSymbolTable |
class | P4RuntimeSymbolTableIface |
class | P4RuntimeSymbolType |
struct | P4SymbolSuffixSet |
class | ParseP4RuntimeAnnotations |
Parses P4Runtime-specific annotations. More... | |
struct | TranslationAnnotation |
Payload of @p4runtime_translation annotation. More... | |
class | TypeSpecConverter |
Generates the appropriate p4.P4DataTypeSpec for a given IR::Type node. More... | |
Typedefs | |
using | p4rt_id_t = uint32_t |
Functions | |
void | collectControlSymbols (P4RuntimeSymbolTable &symbols, P4RuntimeArchHandlerIface *archHandler, const IR::ControlBlock *controlBlock, ReferenceMap *refMap, TypeMap *typeMap) |
void | collectExternSymbols (P4RuntimeSymbolTable &symbols, P4RuntimeArchHandlerIface *archHandler, const IR::ExternBlock *externBlock) |
void | collectParserSymbols (P4RuntimeSymbolTable &symbols, const IR::ParserBlock *parserBlock) |
void | collectTableSymbols (P4RuntimeSymbolTable &symbols, P4RuntimeArchHandlerIface *archHandler, const IR::TableBlock *tableBlock) |
std::optional< p4rt_id_t > | getIdAnnotation (const IR::IAnnotated *node) |
cstring | getTypeName (const IR::Type *type, TypeMap *typeMap) |
int | getTypeWidth (const IR::Type &type, const TypeMap &typeMap) |
bool | hasTranslationAnnotation (const IR::Type *type, TranslationAnnotation *payload) |
bool | isControllerHeader (const IR::Type_Header *type) |
bool | isHidden (const IR::IAnnotated *node) |
std::optional< std::string > | stringRepr (const IR::BoolLiteral *constant, int width) |
std::optional< std::string > | stringRepr (const IR::Constant *constant, int width) |
std::optional< std::string > | stringRepr (const TypeMap &typeMap, const IR::Expression *expression) |
std::optional< std::string > | stringReprConstant (big_int value, int width) |
uint64_t | szudzikPairing (p4rt_id_t x, p4rt_id_t y) |
in the given range | |
Generic meta function which searches an object by and
| |
const p4::config::v1::Table * | findP4RuntimeTable (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName) |
const p4::config::v1::Table * | findP4RuntimeTable (const p4::config::v1::P4Info &p4Info, p4rt_id_t id) |
const p4::config::v1::MatchField * | findP4RuntimeMatchField (const p4::config::v1::Table &p4Table, cstring controlPlaneName) |
const p4::config::v1::MatchField * | findP4RuntimeMatchField (const p4::config::v1::Table &p4Table, p4rt_id_t id) |
const p4::config::v1::Action * | findP4RuntimeAction (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName) |
const p4::config::v1::Action * | findP4RuntimeAction (const p4::config::v1::P4Info &p4Info, p4rt_id_t id) |
const p4::config::v1::ActionProfile * | findP4RuntimeActionProfile (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName) |
const p4::config::v1::ActionProfile * | findP4RuntimeActionProfile (const p4::config::v1::P4Info &p4Info, p4rt_id_t id) |
const p4::config::v1::Counter * | findP4RuntimeCounter (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName) |
const p4::config::v1::Counter * | findP4RuntimeCounter (const p4::config::v1::P4Info &p4Info, p4rt_id_t id) |
const p4::config::v1::DirectCounter * | findP4RuntimeDirectCounter (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName) |
const p4::config::v1::DirectCounter * | findP4RuntimeDirectCounter (const p4::config::v1::P4Info &p4Info, p4rt_id_t id) |
const p4::config::v1::Meter * | findP4RuntimeMeter (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName) |
const p4::config::v1::Meter * | findP4RuntimeMeter (const p4::config::v1::P4Info &p4Info, p4rt_id_t id) |
const p4::config::v1::DirectMeter * | findP4RuntimeDirectMeter (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName) |
const p4::config::v1::DirectMeter * | findP4RuntimeDirectMeter (const p4::config::v1::P4Info &p4Info, p4rt_id_t id) |
const p4::config::v1::ControllerPacketMetadata * | findP4RuntimeControllerPacketMetadata (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName) |
const p4::config::v1::ControllerPacketMetadata * | findP4RuntimeControllerPacketMetadata (const p4::config::v1::P4Info &p4Info, p4rt_id_t id) |
const p4::config::v1::ValueSet * | findP4RuntimeValueSet (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName) |
const p4::config::v1::ValueSet * | findP4RuntimeValueSet (const p4::config::v1::P4Info &p4Info, p4rt_id_t id) |
const p4::config::v1::Register * | findP4RuntimeRegister (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName) |
const p4::config::v1::Register * | findP4RuntimeRegister (const p4::config::v1::P4Info &p4Info, p4rt_id_t id) |
const p4::config::v1::Digest * | findP4RuntimeDigest (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName) |
const p4::config::v1::Digest * | findP4RuntimeDigest (const p4::config::v1::P4Info &p4Info, p4rt_id_t id) |
const p4::config::v1::Extern * | findP4RuntimeExtern (const p4::config::v1::P4Info &p4Info, cstring controlPlaneName) |
const p4::config::v1::Extern * | findP4RuntimeExtern (const p4::config::v1::P4Info &p4Info, p4rt_id_t id) |
std::optional< p4rt_id_t > | getP4RuntimeId (const p4::config::v1::P4Info &p4Info, const P4RuntimeSymbolType &type, cstring controlPlaneName) |
template<typename It > | |
auto | findP4InfoObject (const It &first, const It &last, cstring controlPlaneName) -> const typename std::iterator_traits< It >::value_type * |
template<typename It > | |
auto | findP4InfoObject (const It &first, const It &last, p4rt_id_t id) -> const typename std::iterator_traits< It >::value_type * |
Variables | |
const p4rt_id_t | INVALID_ID = ::p4::config::v1::P4Ids::UNSPECIFIED |
TODO(antonin): High level goals of the generator go here!!
TODO: Consider migrating this API to the top-level control-plane folder. The reason we have not already done this is because that folder already provides similar utility functions. However, these functions are tied to the P4RuntimeTableIface, which is fairly inflexible. We just need an API that can perform lookup operations on a P4Info or P4RuntimeAPI object.
struct P4::ControlPlaneAPI::ActionRef |
Class Members | ||
---|---|---|
const IAnnotated * | annotations | |
const cstring | name |
struct P4::ControlPlaneAPI::DefaultAction |
struct P4::ControlPlaneAPI::MatchField |
The information about a match field which is needed to serialize it.
Class Members | ||
---|---|---|
typedef MatchType | MatchType p4configv1::MatchField::MatchType | |
typedef MatchField | MatchTypes p4configv1::MatchField |
Class Members | ||
---|---|---|
const IAnnotated * | annotations | |
const uint32_t | bitwidth | |
const p4rt_id_t | id | |
const cstring | name | |
const cstring | other_match_type | |
const MatchType | type | |
const cstring | type_name |
struct P4::ControlPlaneAPI::TranslationAnnotation |
Payload of @p4runtime_translation annotation.
Class Members | ||
---|---|---|
ControllerType | controller_type | |
string | original_type_uri |
auto P4::ControlPlaneAPI::findP4InfoObject | ( | const It & | first, |
const It & | last, | ||
p4rt_id_t | id ) -> const typename std::iterator_traits<It>::value_type * |
Generic meta function which searches an object by @id in the given range and
const p4::config::v1::Action * P4::ControlPlaneAPI::findP4RuntimeAction | ( | const p4::config::v1::P4Info & | p4Info, |
cstring | controlPlaneName ) |
Try to find the P4Info description for the given action.
const p4::config::v1::Action * P4::ControlPlaneAPI::findP4RuntimeAction | ( | const p4::config::v1::P4Info & | p4Info, |
p4rt_id_t | id ) |
Try to find the P4Info description for the given action.
const p4::config::v1::ActionProfile * P4::ControlPlaneAPI::findP4RuntimeActionProfile | ( | const p4::config::v1::P4Info & | p4Info, |
cstring | controlPlaneName ) |
Try to find the P4Info description for the given action profile.
const p4::config::v1::ActionProfile * P4::ControlPlaneAPI::findP4RuntimeActionProfile | ( | const p4::config::v1::P4Info & | p4Info, |
p4rt_id_t | id ) |
Try to find the P4Info description for the given action profile.
const p4::config::v1::ControllerPacketMetadata * P4::ControlPlaneAPI::findP4RuntimeControllerPacketMetadata | ( | const p4::config::v1::P4Info & | p4Info, |
cstring | controlPlaneName ) |
Try to find the P4Info description for the given controller packet metadata.
const p4::config::v1::ControllerPacketMetadata * P4::ControlPlaneAPI::findP4RuntimeControllerPacketMetadata | ( | const p4::config::v1::P4Info & | p4Info, |
p4rt_id_t | id ) |
Try to find the P4Info description for the given controller packet metadata.
const p4::config::v1::Counter * P4::ControlPlaneAPI::findP4RuntimeCounter | ( | const p4::config::v1::P4Info & | p4Info, |
cstring | controlPlaneName ) |
Try to find the P4Info description for the given counter.
const p4::config::v1::Counter * P4::ControlPlaneAPI::findP4RuntimeCounter | ( | const p4::config::v1::P4Info & | p4Info, |
p4rt_id_t | id ) |
Try to find the P4Info description for the given counter.
const p4::config::v1::Digest * P4::ControlPlaneAPI::findP4RuntimeDigest | ( | const p4::config::v1::P4Info & | p4Info, |
cstring | controlPlaneName ) |
Try to find the P4Info description for the given digest.
const p4::config::v1::Digest * P4::ControlPlaneAPI::findP4RuntimeDigest | ( | const p4::config::v1::P4Info & | p4Info, |
p4rt_id_t | id ) |
Try to find the P4Info description for the given digest.
const p4::config::v1::DirectCounter * P4::ControlPlaneAPI::findP4RuntimeDirectCounter | ( | const p4::config::v1::P4Info & | p4Info, |
cstring | controlPlaneName ) |
Try to find the P4Info description for the given direct counter.
const p4::config::v1::DirectCounter * P4::ControlPlaneAPI::findP4RuntimeDirectCounter | ( | const p4::config::v1::P4Info & | p4Info, |
p4rt_id_t | id ) |
Try to find the P4Info description for the given direct counter.
const p4::config::v1::DirectMeter * P4::ControlPlaneAPI::findP4RuntimeDirectMeter | ( | const p4::config::v1::P4Info & | p4Info, |
cstring | controlPlaneName ) |
Try to find the P4Info description for the given direct meter.
const p4::config::v1::DirectMeter * P4::ControlPlaneAPI::findP4RuntimeDirectMeter | ( | const p4::config::v1::P4Info & | p4Info, |
p4rt_id_t | id ) |
Try to find the P4Info description for the given direct meter.
const p4::config::v1::Extern * P4::ControlPlaneAPI::findP4RuntimeExtern | ( | const p4::config::v1::P4Info & | p4Info, |
cstring | controlPlaneName ) |
Try to find the P4Info description for the given extern.
const p4::config::v1::Extern * P4::ControlPlaneAPI::findP4RuntimeExtern | ( | const p4::config::v1::P4Info & | p4Info, |
p4rt_id_t | id ) |
Try to find the P4Info description for the given extern.
const p4::config::v1::MatchField * P4::ControlPlaneAPI::findP4RuntimeMatchField | ( | const p4::config::v1::Table & | p4Table, |
cstring | controlPlaneName ) |
Try to find the P4Info description for the given match field in a particular P4Info table.
const p4::config::v1::MatchField * P4::ControlPlaneAPI::findP4RuntimeMatchField | ( | const p4::config::v1::Table & | p4Table, |
p4rt_id_t | id ) |
Try to find the P4Info description for the given match field in a particular P4Info table.
const p4::config::v1::Meter * P4::ControlPlaneAPI::findP4RuntimeMeter | ( | const p4::config::v1::P4Info & | p4Info, |
cstring | controlPlaneName ) |
Try to find the P4Info description for the given meter.
const p4::config::v1::Meter * P4::ControlPlaneAPI::findP4RuntimeMeter | ( | const p4::config::v1::P4Info & | p4Info, |
p4rt_id_t | id ) |
Try to find the P4Info description for the given meter.
const p4::config::v1::Register * P4::ControlPlaneAPI::findP4RuntimeRegister | ( | const p4::config::v1::P4Info & | p4Info, |
cstring | controlPlaneName ) |
Try to find the P4Info description for the given register.
const p4::config::v1::Register * P4::ControlPlaneAPI::findP4RuntimeRegister | ( | const p4::config::v1::P4Info & | p4Info, |
p4rt_id_t | id ) |
Try to find the P4Info description for the given register.
const p4::config::v1::Table * P4::ControlPlaneAPI::findP4RuntimeTable | ( | const p4::config::v1::P4Info & | p4Info, |
cstring | controlPlaneName ) |
Try to find the P4Info description for the given table.
const p4::config::v1::Table * P4::ControlPlaneAPI::findP4RuntimeTable | ( | const p4::config::v1::P4Info & | p4Info, |
p4rt_id_t | id ) |
Try to find the P4Info description for the given table.
const p4::config::v1::ValueSet * P4::ControlPlaneAPI::findP4RuntimeValueSet | ( | const p4::config::v1::P4Info & | p4Info, |
cstring | controlPlaneName ) |
Try to find the P4Info description for the given value set.
const p4::config::v1::ValueSet * P4::ControlPlaneAPI::findP4RuntimeValueSet | ( | const p4::config::v1::P4Info & | p4Info, |
p4rt_id_t | id ) |
Try to find the P4Info description for the given value set.
std::optional< p4rt_id_t > P4::ControlPlaneAPI::getIdAnnotation | ( | const IR::IAnnotated * | node | ) |
std::optional< p4rt_id_t > P4::ControlPlaneAPI::getP4RuntimeId | ( | const p4::config::v1::P4Info & | p4Info, |
const P4RuntimeSymbolType & | type, | ||
cstring | controlPlaneName ) |
Looks up the P4Runtime id for a P4Runtime symbol. Returns nullptr if the object or the type does not exist.
getTypeName returns a cstring for use as type_name for a Type_Newtype. It returns nullptr if @type is not a Type_Newtype.
int P4::ControlPlaneAPI::getTypeWidth | ( | const IR::Type & | type, |
const TypeMap & | typeMap ) |
getTypeWidth returns the width in bits for the @type, except if it is a user-defined type with a @p4runtime_translation annotation, in which case it returns W if the type is bit<W>, and 0 otherwise (i.e. if the type is string).
bool P4::ControlPlaneAPI::hasTranslationAnnotation | ( | const IR::Type * | type, |
TranslationAnnotation * | payload ) |
hasTranslationAnnotation returns true iff the type is annotated by a valid p4runtime_translation annotation, in which case it populates the given TranslationAnnotation with the values parsed from the annotation.
bool P4::ControlPlaneAPI::isControllerHeader | ( | const IR::Type_Header * | type | ) |
bool P4::ControlPlaneAPI::isHidden | ( | const IR::IAnnotated * | node | ) |
std::optional< std::string > P4::ControlPlaneAPI::stringRepr | ( | const IR::BoolLiteral * | constant, |
int | width ) |
Convert a BoolLiteral to the P4Runtime bytes representation by calling stringReprConstant.
std::optional< std::string > P4::ControlPlaneAPI::stringRepr | ( | const IR::Constant * | constant, |
int | width ) |
Convert a Constant to the P4Runtime bytes representation by calling stringReprConstant.
std::optional< std::string > P4::ControlPlaneAPI::stringRepr | ( | const TypeMap & | typeMap, |
const IR::Expression * | expression ) |
Convert an Expression to the P4Runtime bytes representation. The type map is required to resolve complex expressions such as serializable enums.
std::optional< std::string > P4::ControlPlaneAPI::stringReprConstant | ( | big_int | value, |
int | width ) |
Convert a bignum to the P4Runtime bytes representation. The value must fit within the provided @width expressed in bits. Padding will be added as necessary (as the most significant bits).
uint64_t P4::ControlPlaneAPI::szudzikPairing | ( | p4rt_id_t | x, |
p4rt_id_t | y ) |
Computes a unique pairing of two input numbers. We use this to generate unique P4Runtime IDs for combinations of tables and key elements, or actions and parameters. https://en.wikipedia.org/wiki/Pairing_function#Other_pairing_functions The maximum szudzikPairing value is 2^64 - 1, which is why we use uint64_t for the p4rt_id_t, which is uint32_t bit.