P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::BMV2::JsonObjects Class Reference

Public Member Functions

 JsonObjects ()
 Constructs a new JsonObjects instance. Initializes the top-level JsonObject and other member arrays.
 
unsigned add_action (const cstring &name, Util::JsonArray *&params, Util::JsonArray *&body)
 Adds an action to the JSON representation.
 
void add_enum (const cstring &enum_name, const cstring &entry_name, const unsigned entry_value)
 Adds a single enum entry to the JSON representation.
 
void add_error (const cstring &name, const unsigned type)
 Adds an error to the JSON representation.
 
void add_extern (const cstring &name, const cstring &type, Util::JsonArray *attributes)
 Adds an extern instance to the JSON representation.
 
void add_extern_attribute (const cstring &name, const cstring &type, const cstring &value, Util::JsonArray *attributes)
 Adds an extern attribute to the JSON representation.
 
unsigned add_header (const cstring &type, const cstring &name)
 Creates a header instance in JSON.
 
void add_header_field (const cstring &name, Util::JsonArray *&field)
 Adds a set of fields to an existing header type.
 
void add_header_stack (const cstring &type, const cstring &name, const unsigned size, const std::vector< unsigned > &header_ids)
 Adds a header stack to the JSON representation.
 
unsigned add_header_type (const cstring &name)
 Create a header type with empty field list.
 
unsigned add_header_type (const cstring &name, Util::JsonArray *&fields, unsigned max_length)
 Create a header type in json.
 
void add_header_union_stack (const cstring &type, const cstring &name, const unsigned size, const std::vector< unsigned > &header_ids)
 Adds a header union stack to the JSON representation.
 
void add_meta_info ()
 Adds meta information to the JsonObject.
 
unsigned add_metadata (const cstring &type, const cstring &name)
 Creates a metadata header instance in JSON.
 
void add_parse_vset (const cstring &name, const unsigned bitwidth, const big_int &size)
 Adds a parse vset to the JSON representation.
 
unsigned add_parser (const cstring &name)
 Adds a parser to the JSON representation.
 
void add_parser_op (const unsigned id, Util::IJson *op)
 Adds a parser operation to an existing parser state in the JSON representation.
 
unsigned add_parser_state (const unsigned id, const cstring &state_name)
 Adds a parser state to an existing parser in the JSON representation.
 
void add_parser_transition (const unsigned id, Util::IJson *transition)
 Adds a parser transition to an existing parser state in the JSON representation.
 
void add_parser_transition_key (const unsigned id, Util::IJson *key)
 Adds a parser transition key to an existing parser state in the JSON representation.
 
void add_program_info (const cstring &name)
 Adds program information to the top-level JsonObject.
 
unsigned add_union (const cstring &type, Util::JsonArray *&fields, const cstring &name)
 Creates a header union instance in JSON.
 
unsigned add_union_type (const cstring &name, Util::JsonArray *&fields)
 Creates a union type in JSON.
 
Util::JsonArrayappend_array (Util::JsonArray *parent)
 Appends a JSON array to a parent JSON array.
 
Util::JsonArraycreate_parameters (Util::JsonObject *object)
 Creates a JSON array named 'parameters' in a parent JsonObject.
 
Util::JsonObjectcreate_primitive (Util::JsonArray *parent, cstring name)
 Creates a primitive JsonObject in a parent JsonArray with the given name.
 
Util::JsonArrayget_field_list_contents (unsigned id) const
 Retrieves the contents of a field list identified by its ID.
 
Util::JsonArrayinsert_array_field (Util::JsonObject *parent, cstring name)
 Inserts a JSON array into a parent object under a specified key.
 

Static Public Member Functions

static Util::JsonObjectfind_object_by_name (Util::JsonArray *array, const cstring &name)
 Finds an object in a JSON array by its name.
 

Public Attributes

Util::JsonArrayactions
 
Util::JsonArraycalculations
 
Util::JsonArraychecksums
 
Util::JsonArraycounters
 
Util::JsonArraydeparsers
 
Util::JsonArrayenums
 
Util::JsonArrayerrors
 
Util::JsonArrayexterns
 
Util::JsonArrayfield_aliases
 
Util::JsonArrayfield_lists
 
Util::JsonArrayforce_arith
 
Util::JsonArrayheader_stacks
 
ordered_map< std::string, unsigned > header_type_id
 
Util::JsonArrayheader_types
 
Util::JsonArrayheader_union_stacks
 
Util::JsonArrayheader_union_types
 
Util::JsonArrayheader_unions
 
Util::JsonArrayheaders
 
Util::JsonArraylearn_lists
 
std::map< unsigned, Util::JsonObject * > map_parser
 
std::map< unsigned, Util::JsonObject * > map_parser_state
 
Util::JsonObjectmeta
 
Util::JsonArraymeter_arrays
 
Util::JsonArrayparse_vsets
 
Util::JsonArrayparsers
 
Util::JsonArraypipelines
 
Util::JsonArrayregister_arrays
 
Util::JsonObjecttoplevel
 
ordered_map< std::string, unsigned > union_type_id
 

Member Function Documentation

◆ add_action()

unsigned P4::BMV2::JsonObjects::add_action ( const cstring & name,
Util::JsonArray *& params,
Util::JsonArray *& body )

Adds an action to the JSON representation.

Parameters
nameThe name of the action.
paramsThe runtime data parameters of the action.
bodyThe primitives body of the action.
Returns
The ID of the newly created action.

◆ add_enum()

void P4::BMV2::JsonObjects::add_enum ( const cstring & enum_name,
const cstring & entry_name,
const unsigned entry_value )

Adds a single enum entry to the JSON representation.

Parameters
enum_nameThe name of the enum.
entry_nameThe name of the enum entry.
entry_valueThe value of the enum entry.

◆ add_error()

void P4::BMV2::JsonObjects::add_error ( const cstring & name,
const unsigned type )

Adds an error to the JSON representation.

Parameters
nameThe name of the error.
typeThe type of the error.

◆ add_extern()

void P4::BMV2::JsonObjects::add_extern ( const cstring & name,
const cstring & type,
Util::JsonArray * attributes )

Adds an extern instance to the JSON representation.

Parameters
nameThe name of the extern instance.
typeThe type of the extern instance.
attributesThe attributes array of the extern instance.

◆ add_extern_attribute()

void P4::BMV2::JsonObjects::add_extern_attribute ( const cstring & name,
const cstring & type,
const cstring & value,
Util::JsonArray * attributes )

Adds an extern attribute to the JSON representation.

Parameters
nameThe name of the attribute.
typeThe type of the attribute.
valueThe value of the attribute.
attributesThe attributes array to add the new attribute to.

◆ add_header()

unsigned P4::BMV2::JsonObjects::add_header ( const cstring & type,
const cstring & name )

Creates a header instance in JSON.

Parameters
typeThe type of the header.
nameThe name of the header instance.
Returns
The ID of the newly created header instance.

◆ add_header_field()

void P4::BMV2::JsonObjects::add_header_field ( const cstring & name,
Util::JsonArray *& field )

Adds a set of fields to an existing header type.

Parameters
nameThe name of the header type.
fieldThe JsonArray containing the fields to add.

◆ add_header_stack()

void P4::BMV2::JsonObjects::add_header_stack ( const cstring & type,
const cstring & name,
const unsigned size,
const std::vector< unsigned > & header_ids )

Adds a header stack to the JSON representation.

Parameters
typeThe type of the headers in the stack.
nameThe name of the header stack.
sizeThe size of the header stack.
idsThe vector of header IDs in the stack.

◆ add_header_type() [1/2]

unsigned P4::BMV2::JsonObjects::add_header_type ( const cstring & name)

Create a header type with empty field list.

Parameters
nameheader name
typeheader type
fieldsa JsonArray for the fields in the header
max_lengthmaximum length for a header with varbit fields; if 0 header does not
Returns
The ID of the newly created header type.

◆ add_header_type() [2/2]

unsigned P4::BMV2::JsonObjects::add_header_type ( const cstring & name,
Util::JsonArray *& fields,
unsigned max_length )

Create a header type in json.

Parameters
nameheader name
typeheader type
fieldsa JsonArray for the fields in the header
max_lengthmaximum length for a header with varbit fields; if 0 header does not
Returns
The ID of the newly created header type.

Create a header type in json.

Parameters
nameheader name
typeheader type
max_lengthmaximum length for a header with varbit fields; if 0 header does not contain varbit fields
fieldsa JsonArray for the fields in the header

◆ add_header_union_stack()

void P4::BMV2::JsonObjects::add_header_union_stack ( const cstring & type,
const cstring & name,
const unsigned size,
const std::vector< unsigned > & header_ids )

Adds a header union stack to the JSON representation.

Parameters
typeThe type of the header unions in the stack.
nameThe name of the header union stack.
sizeThe size of the header union stack.
idsThe vector of header union IDs in the stack.

◆ add_metadata()

unsigned P4::BMV2::JsonObjects::add_metadata ( const cstring & type,
const cstring & name )

Creates a metadata header instance in JSON.

Parameters
typeThe type of the metadata.
nameThe name of the metadata header instance.
Returns
The ID of the newly created metadata header instance.

◆ add_parse_vset()

void P4::BMV2::JsonObjects::add_parse_vset ( const cstring & name,
const unsigned bitwidth,
const big_int & size )

Adds a parse vset to the JSON representation.

Parameters
nameThe name of the parse vset.
bitwidthThe compressed bit width of the parse vset.
sizeThe maximum size of the parse vset.

◆ add_parser()

unsigned P4::BMV2::JsonObjects::add_parser ( const cstring & name)

Adds a parser to the JSON representation.

Parameters
nameThe name of the parser.
Returns
The ID of the newly created parser.

◆ add_parser_op()

void P4::BMV2::JsonObjects::add_parser_op ( const unsigned id,
Util::IJson * op )

Adds a parser operation to an existing parser state in the JSON representation.

Parameters
state_idThe ID of the parser state.
opThe operation to add.

◆ add_parser_state()

unsigned P4::BMV2::JsonObjects::add_parser_state ( const unsigned id,
const cstring & state_name )

Adds a parser state to an existing parser in the JSON representation.

Parameters
parser_idThe ID of the parser.
state_nameThe name of the parser state.
Returns
The ID of the newly created parser state.

◆ add_parser_transition()

void P4::BMV2::JsonObjects::add_parser_transition ( const unsigned id,
Util::IJson * transition )

Adds a parser transition to an existing parser state in the JSON representation.

Parameters
state_idThe ID of the parser state.
transitionThe transition to add.

◆ add_parser_transition_key()

void P4::BMV2::JsonObjects::add_parser_transition_key ( const unsigned id,
Util::IJson * key )

Adds a parser transition key to an existing parser state in the JSON representation.

Parameters
state_idThe ID of the parser state.
newKeyThe new transition key to add.

◆ add_program_info()

void P4::BMV2::JsonObjects::add_program_info ( const cstring & name)

Adds program information to the top-level JsonObject.

Parameters
nameThe name of the program.

◆ add_union()

unsigned P4::BMV2::JsonObjects::add_union ( const cstring & type,
Util::JsonArray *& fields,
const cstring & name )

Creates a header union instance in JSON.

Parameters
typeThe type of the header union.
fieldsA JsonArray containing the header IDs in the union.
nameThe name of the header union instance.
Returns
The ID of the newly created header union instance.

◆ add_union_type()

unsigned P4::BMV2::JsonObjects::add_union_type ( const cstring & name,
Util::JsonArray *& fields )

Creates a union type in JSON.

Parameters
nameThe name of the union type.
fieldsA JsonArray containing the headers in the union type.
Returns
The ID of the newly created union type.

◆ append_array()

Util::JsonArray * P4::BMV2::JsonObjects::append_array ( Util::JsonArray * parent)

Appends a JSON array to a parent JSON array.

Parameters
parentThe parent JsonArray to which the array will be appended.
Returns
A pointer to the newly created JSON array.

◆ create_parameters()

Util::JsonArray * P4::BMV2::JsonObjects::create_parameters ( Util::JsonObject * object)

Creates a JSON array named 'parameters' in a parent JsonObject.

Parameters
objectThe parent JsonObject in which the 'parameters' array will be created.
Returns
A pointer to the newly created JSON array.

◆ create_primitive()

Util::JsonObject * P4::BMV2::JsonObjects::create_primitive ( Util::JsonArray * parent,
cstring name )

Creates a primitive JsonObject in a parent JsonArray with the given name.

Parameters
parentThe parent JsonArray in which the primitive will be created.
nameThe name of the primitive.
Returns
A pointer to the newly created primitive JsonObject.

◆ find_object_by_name()

Util::JsonObject * P4::BMV2::JsonObjects::find_object_by_name ( Util::JsonArray * array,
const cstring & name )
static

Finds an object in a JSON array by its name.

Parameters
arrayThe JSON array to search in.
nameThe name of the object to find.
Returns
A pointer to the JsonObject with the specified name, or nullptr if not found.

◆ get_field_list_contents()

Util::JsonArray * P4::BMV2::JsonObjects::get_field_list_contents ( unsigned id) const

Retrieves the contents of a field list identified by its ID.

Given a field list id returns the array of values called "elements".

Parameters
idThe ID of the field list.
Returns
A pointer to the JsonArray containing the field list's elements, or nullptr if not found.

◆ insert_array_field()

Util::JsonArray * P4::BMV2::JsonObjects::insert_array_field ( Util::JsonObject * parent,
cstring name )

Inserts a JSON array into a parent object under a specified key.

Parameters
parentThe parent JsonObject to insert the array into.