19#ifndef BF_P4C_PARDE_FIELD_PACKING_H_
20#define BF_P4C_PARDE_FIELD_PACKING_H_
24#include "bf-p4c/ir/bitrange.h"
25#include "bf-p4c/ir/gress.h"
26#include "lib/cstring.h"
58 bool isPadding()
const {
return field ==
nullptr; }
64 static PackedItem makePadding(
unsigned width) {
return PackedItem(
width); }
67 typedef std::vector<PackedItem>::iterator iterator;
68 typedef std::vector<PackedItem>::const_iterator const_iterator;
70 iterator begin() {
return fields.begin(); }
71 iterator end() {
return fields.end(); }
72 const_iterator begin()
const {
return fields.begin(); }
73 const_iterator end()
const {
return fields.end(); }
79 template <Endian Order,
typename Func>
82 for (
auto &field :
fields) {
83 if (field.isPadding()) {
84 posBits += field.width;
87 const auto fieldRange =
89 posBits += field.width;
90 func(fieldRange, field.field, field.source);
109 gress_t gress = INGRESS);
110 void appendField(
const IR::Expression *field,
unsigned width, gress_t gress = INGRESS);
141 bool isAlignedTo(
unsigned alignment,
unsigned phase = 0)
const;
155 const IR::BFN::ParserState *finalState)
const;
The namespace encapsulating Barefoot/Intel-specific stuff.
Definition add_t2na_meta.cpp:21
The namespace encapsulating IR node classes.
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
ClosedRange< RangeUnit::Bit, Endian::Network > nw_bitrange
Convenience typedefs for closed ranges in bits.
Definition lib/bitrange.h:755
Definition field_packing.h:46
unsigned width
This item's width in bits.
Definition field_packing.h:56
cstring source
Definition field_packing.h:53
const IR::Expression * field
The packed field, or null if this is a padding item.
Definition field_packing.h:48
Definition field_packing.h:45
bool isAlignedTo(unsigned alignment, unsigned phase=0) const
Definition parde/field_packing.cpp:79
void append(const FieldPacking &packing)
Appends another sequence of packed items to this one.
Definition parde/field_packing.cpp:50
bool containsFields() const
Definition parde/field_packing.cpp:73
void appendField(const IR::Expression *field, cstring source, unsigned width, gress_t gress=INGRESS)
Definition parde/field_packing.cpp:33
void padToAlignment(unsigned alignment, unsigned phase=0)
Definition parde/field_packing.cpp:59
IR::BFN::ParserState * createExtractionState(gress_t gress, cstring stateName, const IR::BFN::ParserState *finalState) const
Definition parde/field_packing.cpp:84
std::vector< PackedItem > fields
The sequence of packed items (fields and padding).
Definition field_packing.h:158
void appendPadding(unsigned width)
Definition parde/field_packing.cpp:40
void clear()
Removes all packed items from this sequence.
Definition parde/field_packing.cpp:68
void forEachField(Func func) const
Definition field_packing.h:80
unsigned totalWidth
The total width of all packed items in the sequence.
Definition field_packing.h:161
Definition lib/bitrange.h:158
ClosedRange< Unit, DestOrder > toOrder(int spaceSize) const
Definition lib/bitrange.h:636