8#ifndef BACKENDS_BMV2_PNA_NIC_PNANIC_H_
9#define BACKENDS_BMV2_PNA_NIC_PNANIC_H_
11#include "backends/bmv2/portable_common/portable.h"
12#include "pnaProgramStructure.h"
16class PnaNicExpressionConverter :
public ExpressionConverter {
22 void modelError(
const char *format,
const cstring field) {
24 (
cstring(format) +
"\nInvalid metadata parameter value for PNA").c_str(),
28 Util::IJson *convertParam(UNUSED
const IR::Parameter *param,
cstring fieldName)
override {
29 cstring ptName = param->type->toString();
32 jsn->emplace(
"name"_cs, param->toString());
33 jsn->emplace(
"type"_cs,
"hexstr");
34 auto bitwidth = param->type->width_bits();
37 if (fieldName ==
"BYTES") {
38 cstring repr = BMV2::stringRepr(0, ROUNDUP(bitwidth, 32));
39 jsn->emplace(
"value"_cs, repr);
40 }
else if (fieldName ==
"PACKETS") {
41 cstring repr = BMV2::stringRepr(1, ROUNDUP(bitwidth, 32));
42 jsn->emplace(
"value"_cs, repr);
43 }
else if (fieldName ==
"PACKETS_AND_BYTES") {
44 cstring repr = BMV2::stringRepr(2, ROUNDUP(bitwidth, 32));
45 jsn->emplace(
"value"_cs, repr);
47 modelError(
"%1%: Exptected a PNA_CounterType_t", fieldName);
55 jsn->emplace(
"type"_cs,
"field");
56 auto a = mkArrayField(jsn,
"value"_cs);
57 a->append(ptName.exceptLast(2));
79class ConvertPnaToJson :
public Inspector {
83 const IR::ToplevelBlock *toplevel;
91 : refMap(refMap), typeMap(typeMap), toplevel(toplevel),
json(
json), structure(structure) {
96 CHECK_NULL(structure);
98 CHECK_NULL(codeGenerator);
101 void postorder(UNUSED
const IR::P4Program *program)
override {
102 cstring scalarsName =
"scalars"_cs;
106 codeGenerator->create(ctxt, structure);
110class PnaNicBackend :
public Backend {
114 void convert(
const IR::ToplevelBlock *tlb)
override;
116 P4::ConvertEnums::EnumMapping *enumMap)
117 : Backend(options, refMap, typeMap, enumMap), options(options) {}
120EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Hash)
121EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(InternetChecksum)
122EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Register)
Definition backends/bmv2/common/options.h:18
Definition expression.h:42
Definition JsonObjects.h:17
Definition bmv2/pna_nic/pnaProgramStructure.h:22
static bool isStandardMetadata(cstring ptName)
Definition bmv2/pna_nic/pnaProgramStructure.h:37
static bool isCounterMetadata(cstring ptName)
Definition bmv2/pna_nic/pnaProgramStructure.h:33
Definition portableProgramStructure.h:20
Definition backends/common/programStructure.h:23
Class used to encode maps from paths to declarations.
Definition referenceMap.h:67
Definition lib/json.h:177
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition action.cpp:9
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:58
Definition bmv2/common/helpers.h:288