14#ifndef BACKENDS_TC_TCEXTERNS_H_
15#define BACKENDS_TC_TCEXTERNS_H_
18#include "ebpfCodeGen.h"
24class ControlBodyTranslatorPNA;
25class ConvertToBackendIR;
28 const IR::Declaration_Instance *di;
35 this->tblname = tblname;
56 const IR::Type *keyArg;
57 const IR::Type *valueArg;
66 this->instanceName = di->toString();
67 if (!di->type->is<IR::Type_Specialized>()) {
68 ::P4::error(ErrorType::ERR_MODEL,
"Missing specialization: %1%", di);
71 auto ts = di->type->to<IR::Type_Specialized>();
73 if (ts->arguments->size() != PARAM_INDEX_2) {
74 ::P4::error(ErrorType::ERR_MODEL,
"Expected a type specialized with two arguments: %1%",
79 this->valueArg = ts->arguments->at(0);
80 this->keyArg = ts->arguments->at(1);
82 this->keyType = EBPF::EBPFTypeFactory::instance->create(keyArg);
83 this->valueType = EBPF::EBPFTypeFactory::instance->create(valueArg);
87 const IR::Expression *leftExpression);
99 bool preorder(
const IR::PathExpression *pe)
override {
100 auto decl = table->program->refMap->
getDeclaration(pe->path,
true);
101 auto di = decl->
to<IR::Declaration_Instance>();
103 if (EBPF::EBPFObject::getSpecializedTypeName(di) !=
"DirectCounter") {
105 "%1%: not a DirectCounter, see declaration of %2%", pe, decl);
108 auto counterName = EBPF::EBPFObject::externalName(di);
109 auto tblname = table->table->container->name.originalName;
110 auto ctr =
new EBPFCounterPNA(table->program, di, counterName, table->codeGen, tblname);
111 table->
counters.emplace_back(std::make_pair(counterName, ctr));
115 void visitTableProperty() {
116 EBPF::EBPFTablePsaPropertyVisitor::visitTableProperty(
"pna_direct_counter"_cs);
125 void updateChecksum(
EBPF::CodeBuilder *builder,
const ArgumentsList &arguments,
bool addData);
134 void emitAddData(
EBPF::CodeBuilder *builder,
const ArgumentsList &arguments)
override;
137 void emitSubtractData(
EBPF::CodeBuilder *builder,
const ArgumentsList &arguments)
override;
141 const IR::MethodCallExpression *expr)
override;
142 cstring getConvertByteOrderFunction(
unsigned widthToEmit,
cstring byte_order);
153 auto di = block->
to<IR::Declaration_Instance>();
154 if (di->arguments->size() != 1) {
155 ::P4::error(ErrorType::ERR_UNEXPECTED,
"Expected exactly 1 argument %1%", block);
158 int type = di->arguments->at(0)->expression->checkedTo<IR::Constant>()->asInt();
159 init(program, name, type);
165 init(program, name, type);
174 EBPF::EBPFHashAlgorithmPSA::HashAlgorithm::ONES_COMPLEMENT16) {}
177 const IR::MethodCallExpression *expr,
Visitor *visitor)
override;
186 const IR::MethodCallExpression *expr,
Visitor *visitor)
override;
187 void calculateHash(
EBPF::CodeBuilder *builder,
const IR::MethodCallExpression *expr,
195 BUG_CHECK(width == 16 || width == 32,
"Must be 16 bits width or 32 bits width.");
196 initialValue =
"0"_cs;
200 const IR::MethodCallExpression *expr);
202 const IR::MethodCallExpression *expr)
override;
215 this->externName = externName;
216 this->instanceName = di->toString();
232 this->instanceName = di->toString();
237 this->tblname = tblname;
238 this->instanceName = di->toString();
242 const IR::Expression *leftExpression)
const;
245 const IR::Expression *leftExpression)
const;
255 bool preorder(
const IR::PathExpression *pe)
override {
256 auto decl = table->program->refMap->
getDeclaration(pe->path,
true);
257 auto di = decl->
to<IR::Declaration_Instance>();
259 if (EBPF::EBPFObject::getTypeName(di) !=
"DirectMeter") {
260 ::P4::error(ErrorType::ERR_UNEXPECTED,
"%1%: not a DirectMeter, see declaration of %2%",
265 auto meterName = EBPF::EBPFObject::externalName(di);
266 auto tblname = table->table->container->name.originalName;
267 auto met =
new EBPFMeterPNA(table->program, meterName, tblname, di, table->codeGen);
268 table->meters.emplace_back(std::make_pair(meterName, met));
272 void visitTableProperty() {
273 EBPF::EBPFTablePsaPropertyVisitor::visitTableProperty(
"pna_direct_meter"_cs);
Definition ebpfPsaHashAlgorithm.h:74
Definition ebpf/codeGen.h:33
Definition ebpf/codeGen.h:41
Definition ebpfPsaChecksum.h:25
Definition ebpfPsaCounter.h:26
Definition ebpfPsaDigest.h:27
Definition ebpfPsaHashAlgorithm.h:26
Definition ebpfPsaMeter.h:23
Definition ebpfProgram.h:39
Also used to represent counters.
Definition ebpfTable.h:49
Definition ebpfPsaTable.h:29
std::vector< std::pair< cstring, EBPFCounterPSA * > > counters
Definition ebpfPsaTable.h:73
Definition ebpfPsaTable.h:123
Base class for EBPF types.
Definition ebpfType.h:29
Definition methodInstance.h:168
const IR::IDeclaration * getDeclaration(const IR::Path *path, bool notNull=false) const override
Definition referenceMap.cpp:78
Definition tcExterns.h:191
Definition ebpfCodeGen.h:370
Definition tc/backend.h:49
Definition tcExterns.h:145
Definition tcExterns.h:27
Definition tcExterns.h:205
Definition tcExterns.h:180
Definition tcExterns.h:169
Definition tcExterns.h:224
Definition tcExterns.h:53
Definition tcExterns.h:94
Definition tcExterns.h:250
Definition tcExterns.h:120
void emitVariables(EBPF::CodeBuilder *builder, const IR::Declaration_Instance *decl) override
decl might be a null pointer
Definition tcExterns.cpp:215
This file defines functions for the pass to generate the introspection file.
Definition tc/backend.cpp:24
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:51
T * to() noexcept
Definition rtti.h:226