P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::P4V1::ProgramStructure Class Reference

Information about the structure of a P4-14 program, used to convert it to a P4-16 program. More...

#include <programStructure.h>

Inheritance diagram for P4::P4V1::ProgramStructure:
[legend]

Public Member Functions

const IR::AssignmentStatement * assign (Util::SourceInfo srcInfo, const IR::Expression *left, const IR::Expression *right, const IR::Type *type)
 
virtual const IR::Declaration_Instance * convert (const IR::Register *reg, cstring newName, const IR::Type *regElementType=nullptr)
 
virtual const IR::Expression * convertFieldList (const IR::Expression *expression)
 
virtual const IR::Expression * convertHashAlgorithm (Util::SourceInfo srcInfo, IR::ID algorithm)
 
virtual const IR::Expression * convertHashAlgorithms (const IR::NameList *algorithm)
 
virtual const IR::P4Program * create (Util::SourceInfo info)
 
virtual IR::Vector< IR::Argument > * createApplyArguments (cstring n)
 
void createExterns ()
 
virtual const IR::Type_Struct * createFieldListType (const IR::Expression *expression)
 
void createTypes ()
 
const IR::Expression * explodeLabel (const IR::Constant *value, const IR::Constant *mask, const std::vector< const IR::Type::Bits * > &fieldTypes)
 
const IR::Type * explodeType (const std::vector< const IR::Type::Bits * > &fieldTypes)
 
virtual const IR::FieldListCalculation * getFieldListCalculation (const IR::Expression *)
 
virtual const IR::FieldList * getFieldLists (const IR::FieldListCalculation *flc)
 
void include (cstring filename, cstring ppoptions=cstring())
 
bool isFieldInList (cstring type, cstring field, const IR::FieldList *fl) const
 
bool isHeader (const IR::ConcreteHeaderRef *nhr) const
 
const IR::Expression * listIndex (const IR::Expression *fl) const
 
virtual const IR::Vector< IR::Expression > * listIndexes (cstring type, cstring field) const
 
virtual void loadModel ()
 
cstring makeUniqueName (cstring base)
 
virtual const IR::Expression * paramReference (const IR::Parameter *param)
 
void populateOutputNames ()
 
const IR::Statement * sliceAssign (const IR::Primitive *prim, const IR::Expression *left, const IR::Expression *right, const IR::Expression *mask)
 
void tablesReferred (const IR::V1Control *control, std::vector< const IR::V1Table * > &out)
 

Public Attributes

NamedObjectInfo< const IR::ActionProfile * > action_profiles
 
NamedObjectInfo< const IR::ActionSelector * > action_selectors
 
NamedObjectInfo< const IR::ActionFunction * > actions
 
ordered_set< const IR::FieldList * > allFieldLists
 Field lists that appear in the program.
 
std::unordered_map< cstring, int > allNames
 
std::vector< const IR::CalculatedField * > calculated_fields
 
P4::CallGraph< cstringcalledActions
 
P4::CallGraph< cstringcalledControls
 
P4::CallGraph< cstringcalledCounters
 
P4::CallGraph< cstringcalledExterns
 
P4::CallGraph< cstringcalledMeters
 
P4::CallGraph< cstringcalledRegisters
 
NamedObjectInfo< const IR::V1Control * > controls
 
ConversionContextconversionContext = nullptr
 
std::map< cstring, const IR::Declaration_Instance * > counterMap
 
NamedObjectInfo< const IR::Counter * > counters
 
IR::Vector< IR::Node > * declarations
 
const int defaultRegisterWidth = 32
 
const IR::P4Control * deparser
 
std::map< cstring, cstringdirectCounters
 
std::map< cstring, const IR::Meter * > directMeters
 Maps table name to direct meter.
 
IR::Vector< IR::Type > * emptyTypeArguments = nullptr
 
std::map< const IR::Type_Extern *, const IR::Type_Extern * > extern_remap
 
NamedObjectInfo< const IR::Type_Extern * > extern_types
 
NamedObjectInfo< const IR::Declaration_Instance * > externs
 
std::map< cstring, IR::Vector< IR::Expression > > extracts
 
std::map< const IR::MethodCallExpression *, const IR::Type_Header * > extractsSynthesized
 
NamedObjectInfo< const IR::FieldListCalculation * > field_list_calculations
 
NamedObjectInfo< const IR::FieldList * > field_lists
 
cstring fieldListsEnum
 Name of the serializable enum that holds one id for each field list.
 
std::map< cstring, const IR::Type * > finalHeaderType
 
std::map< const IR::Node *, const IR::Declaration_Instance * > globalInstances
 
std::set< cstringheaderInstances
 
NamedObjectInfo< const IR::Header * > headers
 
std::set< cstringheaderTypes
 
const IR::V1Control * ingress
 
IR::ID ingressReference
 
const IR::Expression * latest
 Represents 'latest' P4-14 construct.
 
std::vector< const IR::Declaration * > localInstances
 extra local instances to control created by primitive translation
 
NamedObjectInfo< const IR::HeaderOrMetadata * > metadata
 
std::set< cstringmetadataInstances
 
std::set< cstringmetadataTypes
 
std::map< const IR::Meter *, const IR::Declaration_Instance * > meterMap
 
NamedObjectInfo< const IR::Meter * > meters
 
P4::P4CoreLibraryp4lib
 
std::set< cstringparameterTypes
 
std::map< cstring, const IR::ParserState * > parserEntryPoints
 
const IR::Parameter * parserHeadersOut = nullptr
 
const IR::Parameter * parserPacketIn = nullptr
 
P4::CallGraph< cstringparsers
 
NamedObjectInfo< const IR::V1Parser * > parserStates
 
std::map< cstring, cstringregisterLayoutType
 
NamedObjectInfo< const IR::Register * > registers
 
NamedObjectInfo< const IR::HeaderStack * > stacks
 
std::map< const IR::V1Table *, const IR::Apply * > tableInvocation
 
std::map< const IR::V1Table *, const IR::V1Control * > tableMapping
 
NamedObjectInfo< const IR::V1Table * > tables
 
NamedObjectInfo< const IR::Type_StructLike * > types
 
const IR::P4Control * updateChecksums
 
P4V1::V1Modelv1model
 
NamedObjectInfo< const IR::ParserValueSet * > value_sets
 
std::set< cstringvalue_sets_implemented
 
const IR::P4Control * verifyChecksums
 

Protected Member Functions

virtual void checkHeaderType (const IR::Type_StructLike *hrd, bool toStruct)
 
virtual const IR::Type_Control * controlType (IR::ID name)
 
virtual const IR::Declaration_Instance * convert (const IR::CounterOrMeter *cm, cstring newName)
 
virtual const IR::P4Action * convertAction (const IR::ActionFunction *action, cstring newName, const IR::Meter *meterToAccess, cstring counterToAccess)
 
virtual const IR::Declaration_Instance * convertActionProfile (const IR::ActionProfile *, cstring newName)
 
virtual const IR::P4Control * convertControl (const IR::V1Control *control, cstring newName)
 
virtual const IR::Statement * convertCounterCall (cstring counterToAccess)
 
virtual const IR::Declaration_Instance * convertDirectCounter (const IR::Counter *c, cstring newName)
 
virtual const IR::Declaration_Instance * convertDirectMeter (const IR::Meter *m, cstring newName)
 
virtual const IR::Statement * convertMeterCall (const IR::Meter *meterToAccess)
 
virtual const IR::ParserState * convertParser (const IR::V1Parser *, IR::IndexedVector< IR::Declaration > *)
 
virtual const IR::Statement * convertParserStatement (const IR::Expression *expr)
 
virtual const IR::Statement * convertPrimitive (const IR::Primitive *primitive)
 
virtual const IR::P4Table * convertTable (const IR::V1Table *table, cstring newName, IR::IndexedVector< IR::Declaration > &stateful, std::map< cstring, cstring > &)
 
virtual const IR::Expression * counterType (const IR::CounterOrMeter *cm)
 
virtual void createChecksumUpdates ()
 
virtual void createChecksumVerifications ()
 
virtual void createControls ()
 
virtual void createDeparser ()
 
void createDeparserInternal (IR::ID deparserId, IR::Parameter *packetOut, IR::Parameter *headers, std::vector< IR::Parameter * >, IR::IndexedVector< IR::Declaration > controlLocals, std::function< IR::BlockStatement *(IR::BlockStatement *)>)
 
virtual void createMain ()
 
virtual void createParser ()
 
virtual void createStructures ()
 
virtual cstring createType (const IR::Type_StructLike *type, bool header, std::unordered_set< const IR::Type * > *converted)
 
const IR::PathExpression * getState (IR::ID dest)
 

Static Protected Member Functions

static IR::Vector< IR::Annotation > addGlobalNameAnnotation (cstring name, const IR::Vector< IR::Annotation > &annos)
 

Detailed Description

Information about the structure of a P4-14 program, used to convert it to a P4-16 program.

Member Function Documentation

◆ addGlobalNameAnnotation()

IR::Vector< IR::Annotation > P4::P4V1::ProgramStructure::addGlobalNameAnnotation ( cstring name,
const IR::Vector< IR::Annotation > & annos )
staticprotected

Like addNameAnnotation(), but prefixes a "." to make the name global. You should generally prefer this method;

See also
addNameAnnotation() for more discussion.

◆ convertParser()

const IR::ParserState * P4::P4V1::ProgramStructure::convertParser ( const IR::V1Parser * parser,
IR::IndexedVector< IR::Declaration > * stateful )
protectedvirtual

convert a P4-14 parser to P4-16 parser state.

Parameters
parserThe P4-14 parser IR node to be converted
statefulIf any declaration is created during the conversion, save to 'stateful'
Returns
The P4-16 parser state corresponding to the P4-14 parser

◆ createControls()

void P4::P4V1::ProgramStructure::createControls ( )
protectedvirtual

do not convert control block if it is not invoked by other control block and it is not ingress or egress.

◆ listIndex()

const IR::Expression * P4::P4V1::ProgramStructure::listIndex ( const IR::Expression * fl) const

Given an expression which is supposed to be a field list return a constant representing its value in the fieldListsEnum.

◆ listIndexes()

const IR::Vector< IR::Expression > * P4::P4V1::ProgramStructure::listIndexes ( cstring type,
cstring field ) const
virtual

A vector with indexes of the field lists that contain this field. Returns nullptr if the field does not appear in any list.

◆ populateOutputNames()

void P4::P4V1::ProgramStructure::populateOutputNames ( )

This inserts the names of the identifiers used in the output P4-16 programs into allNames, forcing P4-14 names that clash to be renamed.

Member Data Documentation

◆ directMeters

std::map<cstring, const IR::Meter *> P4::P4V1::ProgramStructure::directMeters

Maps table name to direct meter.

Maps table to direct counter.

◆ extractsSynthesized

std::map<const IR::MethodCallExpression *, const IR::Type_Header *> P4::P4V1::ProgramStructure::extractsSynthesized

Maps each inserted extract statement to the type of the header type that is being extracted. The extracts will need another pass to cope with varbit fields.

◆ finalHeaderType

std::map<cstring, const IR::Type *> P4::P4V1::ProgramStructure::finalHeaderType

Some types are transformed during conversion; this maps the original P4-14 header type name to the final P4-16 Type_Header. We can't use the P4-14 type object itself as a key, because it keeps changing.

◆ registerLayoutType

std::map<cstring, cstring> P4::P4V1::ProgramStructure::registerLayoutType

For registers whose layout is a header, this map contains the mapping from the original layout type name to the final layout type name.