P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::ControlPlaneAPI::P4RuntimeSymbolTable Class Reference

#include <p4RuntimeSymbolTable.h>

Inheritance diagram for P4::ControlPlaneAPI::P4RuntimeSymbolTable:
[legend]

Public Member Functions

void add (P4RuntimeSymbolType type, const IR::IDeclaration *declaration) override
 Add a @type symbol, extracting the name and id from @declaration.
 
and possibly an explicit P4 '@id'.

Add a @type symbol with

void add (P4RuntimeSymbolType type, cstring name, std::optional< p4rt_id_t > id=std::nullopt) override
 
p4rt_id_t getId (P4RuntimeSymbolType type, const IR::IDeclaration *declaration) const override
 
- Public Member Functions inherited from P4::ControlPlaneAPI::P4RuntimeSymbolTableIface

Static Public Member Functions

template<typename Func >
static P4RuntimeSymbolTablecreate (Func function)
 
static P4RuntimeSymbolTablegenerateSymbols (const IR::P4Program *program, const IR::ToplevelBlock *evaluatedProgram, ReferenceMap *refMap, TypeMap *typeMap, P4RuntimeArchHandlerIface *archHandler)
 

.

Returns
the P4Runtime id for the symbol of @type with name
p4rt_id_t getId (P4RuntimeSymbolType type, cstring name) const override
 
cstring getAlias (cstring name) const override
 

Detailed Description

A table which tracks the symbols which are visible to P4Runtime and their ids.

Member Function Documentation

◆ add() [1/2]

void P4::ControlPlaneAPI::P4RuntimeSymbolTable::add ( P4RuntimeSymbolType type,
const IR::IDeclaration * declaration )
overridevirtual

Add a @type symbol, extracting the name and id from @declaration.

Implements P4::ControlPlaneAPI::P4RuntimeSymbolTableIface.

◆ add() [2/2]

void P4::ControlPlaneAPI::P4RuntimeSymbolTable::add ( P4RuntimeSymbolType type,
cstring name,
std::optional< p4rt_id_t > id = std::nullopt )
overridevirtual

◆ create()

template<typename Func >
static P4RuntimeSymbolTable * P4::ControlPlaneAPI::P4RuntimeSymbolTable::create ( Func function)
inlinestatic
Returns
a fully constructed P4Runtime symbol table with a unique id computed for each symbol. The table is populated by @function, which can call the various add*() methods on this class.

This approach of constructing the symbol table is intended to encourage correct usage. The symbol table should be used in phases: first, we collect symbols and populate the table. Then, ids are assigned. Finally, the P4Runtime serialization code can read the ids from the table as needed. To ensure that no code accidentally adds new symbols after ids are assigned, create() enforces that only code that runs before id assignment has access to a non-const reference to the symbol table.

◆ getAlias()

cstring P4::ControlPlaneAPI::P4RuntimeSymbolTable::getAlias ( cstring name) const
overridevirtual
Returns
the alias for the given fully qualified external name. P4Runtime defines an alias for each object to make referring to objects easier. By default, the alias is the shortest unique suffix of path components in the name.

Implements P4::ControlPlaneAPI::P4RuntimeSymbolTableIface.

◆ getId() [1/2]

P4::ControlPlaneAPI::p4rt_id_t P4::ControlPlaneAPI::P4RuntimeSymbolTable::getId ( P4RuntimeSymbolType type,
const IR::IDeclaration * declaration ) const
overridevirtual
Returns
the P4Runtime id for the symbol of @type corresponding to @declaration.

Implements P4::ControlPlaneAPI::P4RuntimeSymbolTableIface.

◆ getId() [2/2]

P4::ControlPlaneAPI::p4rt_id_t P4::ControlPlaneAPI::P4RuntimeSymbolTable::getId ( P4RuntimeSymbolType type,
cstring name ) const
overridevirtual