![]() |
P4C
The P4 Compiler
|
#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< PackedItem > | fields |
| The sequence of packed items (fields and padding). | |
| unsigned | totalWidth = 0 |
| The total width of all packed items in the sequence. | |
A field packing format, consisting of a sequence of spans of bits which are either mapped to a field or are treated as padding.
| 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.
| field | An IR object corresponding to the field. Generally this is an IR::Member of a header or struct, but that's not required. |
| source | If 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. |
| width | The width in bits of the field. |
| gress | The gress of the field, if it matters. |
| void BFN::FieldPacking::appendPadding | ( | unsigned | width | ) |
Appends the specified number of bits of padding to the sequence of packed items.
| bool BFN::FieldPacking::containsFields | ( | ) | const |
| 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.
| gress | Which thread these states are intended for. |
| stateName | The name to use for the generated state. |
| finalState | The state the generated parser should branch to after its work is complete. |
|
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
| Order. |
| bool BFN::FieldPacking::isAlignedTo | ( | unsigned | alignment, |
| unsigned | phase = 0 ) const |
| 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).
| alignment | The desired alignment - e.g., 32 bits. |
| phase | If 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. |