19class EBPFTablePSA :
public EBPFTable {
21 struct ConstTernaryEntryDesc {
22 const IR::Entry *entry;
25 typedef std::vector<ConstTernaryEntryDesc> EntriesGroup_t;
26 typedef std::vector<EntriesGroup_t> EntriesGroupedByMask_t;
27 EntriesGroupedByMask_t getConstEntriesGroupedByMask();
28 bool hasConstEntries();
29 const cstring addPrefixFunctionName =
"add_prefix_and_entries"_cs;
30 const cstring tuplesMapName = instanceName +
"_tuples_map"_cs;
31 const cstring prefixesMapName = instanceName +
"_prefixes"_cs;
37 void initDirectCounters();
38 void initDirectMeters();
39 void initImplementation();
41 bool tableCacheEnabled =
false;
45 void tryEnableTableCache();
46 void createCacheTypeNames(
bool isCacheKeyType,
bool isCacheValueType);
48 void emitTableValue(
CodeBuilder *builder,
const IR::Expression *expr,
cstring valueName);
49 void emitDefaultActionInitializer(
CodeBuilder *builder);
50 void emitConstEntriesInitializer(
CodeBuilder *builder);
51 void emitTernaryConstEntriesInitializer(
CodeBuilder *builder);
55 void emitKeyMasks(
CodeBuilder *builder, EntriesGroupedByMask_t &entriesGroupedByMask,
56 std::vector<cstring> &keyMasksNames);
57 void emitKeysAndValues(
CodeBuilder *builder, EntriesGroup_t &sameMaskEntries,
58 std::vector<cstring> &keyNames, std::vector<cstring> &valueNames);
63 std::vector<std::pair<cstring, EBPFCounterPSA *>>
counters;
64 std::vector<std::pair<cstring, EBPFMeterPSA *>> meters;
67 EBPFTablePSA(
const EBPFProgram *program,
const IR::TableBlock *table,
73 void emitValueStructStructure(
CodeBuilder *builder)
override;
75 void emitInitializer(
CodeBuilder *builder)
override;
78 cstring actionRunVariable)
override;
80 static cstring addPrefixFunc(
bool trace);
86 const IR::PathExpression *getActionNameExpression(
const IR::Expression *expr)
const;
87 bool cacheEnabled()
override {
return tableCacheEnabled; }
91 [name](std::pair<cstring, EBPFCounterPSA *> elem) ->
bool {
92 return name == elem.first;
94 if (result !=
counters.end())
return result->second;
98 EBPFMeterPSA *getMeter(
cstring name)
const {
99 auto result = std::find_if(
100 meters.begin(), meters.end(),
101 [name](std::pair<cstring, EBPFMeterPSA *> elem) ->
bool { return name == elem.first; });
102 if (result != meters.end())
return result->second;
106 bool isMatchTypeSupported(
const IR::Declaration_ID *matchType)
override {
107 return EBPFTable::isMatchTypeSupported(matchType) || matchType->name.name ==
"selector";
110 DECLARE_TYPEINFO(EBPFTablePSA, EBPFTable);
113class EBPFTablePsaPropertyVisitor :
public Inspector {
118 explicit EBPFTablePsaPropertyVisitor(
EBPFTablePSA *table) : table(table) {}
123 bool preorder(
const IR::ListExpression *)
override {
return true; }
124 bool preorder(
const IR::Expression *expr)
override {
126 "%1%: unsupported expression, expected a named instance", expr);
130 void visitTableProperty(
cstring propertyName) {
131 auto property = table->table->container->properties->getProperty(propertyName);
132 if (property !=
nullptr)
property->apply(*
this);
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:58