P4C
The P4 Compiler
Loading...
Searching...
No Matches
BFN::FieldPacking Struct Reference

#include <field_packing.h>

Classes

struct  PackedItem
 

Public Types

typedef std::vector< PackedItem >::const_iterator const_iterator
 
typedef std::vector< PackedItem >::iterator iterator
 

Public Member Functions

void append (const FieldPacking &packing)
 Appends another sequence of packed items to this one.
 
void appendField (const IR::Expression *field, cstring source, unsigned width, gress_t gress=INGRESS)
 
void appendField (const IR::Expression *field, unsigned width, gress_t gress=INGRESS)
 
void appendPadding (unsigned width)
 
iterator begin ()
 
const_iterator begin () const
 
void clear ()
 Removes all packed items from this sequence.
 
bool containsFields () const
 
IR::BFN::ParserState * createExtractionState (gress_t gress, cstring stateName, const IR::BFN::ParserState *finalState) const
 
iterator end ()
 
const_iterator end () const
 
template<Endian Order, typename Func >
void forEachField (Func func) const
 
bool isAlignedTo (unsigned alignment, unsigned phase=0) const
 
void padToAlignment (unsigned alignment, unsigned phase=0)
 

Public Attributes

std::vector< PackedItemfields
 The sequence of packed items (fields and padding).
 
unsigned totalWidth = 0
 The total width of all packed items in the sequence.
 

Detailed Description

A field packing format, consisting of a sequence of spans of bits which are either mapped to a field or are treated as padding.

Member Function Documentation

◆ appendField()

void BFN::FieldPacking::appendField ( const IR::Expression * field,
cstring source,
unsigned width,
gress_t gress = INGRESS )

Append a field to the sequence of packed items.

Parameters
fieldAn IR object corresponding to the field. Generally this is an IR::Member of a header or struct, but that's not required.
sourceIf non-empty, a string identifying the source of the field, for use by the control plane. This is primarily intended for the phase 0 table, since the control plane API we generate uses the names of the action parameter and not the metadata fields we assign those parameters to.
widthThe width in bits of the field.
gressThe gress of the field, if it matters.

◆ appendPadding()

void BFN::FieldPacking::appendPadding ( unsigned width)

Appends the specified number of bits of padding to the sequence of packed items.

◆ containsFields()

bool BFN::FieldPacking::containsFields ( ) const
Returns
true if this sequence contains any fields; if it only contains padding or is totally empty, returns false.

◆ createExtractionState()

IR::BFN::ParserState * BFN::FieldPacking::createExtractionState ( gress_t gress,
cstring stateName,
const IR::BFN::ParserState * finalState ) const

Creates a parser state that extract the fields in this sequence from the input buffer and into the destination specified by each packed item's 'field' member.

Parameters
gressWhich thread these states are intended for.
stateNameThe name to use for the generated state.
finalStateThe state the generated parser should branch to after its work is complete.
Returns
the root of the resulting parser program.

◆ forEachField()

template<Endian Order, typename Func >
void BFN::FieldPacking::forEachField ( Func func) const
inline

Iterate over each range of bits in the packing format which is occupied by a field. The callback function should have a prototype like: f(range of bits, field, field source) The ordering of the range of bits is specified by

Template Parameters
Order.

◆ isAlignedTo()

bool BFN::FieldPacking::isAlignedTo ( unsigned alignment,
unsigned phase = 0 ) const
Returns
true if this sequence's total width is a multiple of the provided alignment (in bits), possibly with an additional bit offset.
See also
padToAlignment.

◆ padToAlignment()

void BFN::FieldPacking::padToAlignment ( unsigned alignment,
unsigned phase = 0 )

Appends enough padding to make the total width of this sequence a multiple of the provided alignment (in bits).

Parameters
alignmentThe desired alignment - e.g., 32 bits.
phaseIf provided, an additional offset to the alignment - e.g. a 32 bit alignment with a 2 bit phase would add padding until the total width was 2 bits after a multiple of 32 bits.