17#ifndef BACKENDS_BMV2_PNA_NIC_PNANIC_H_
18#define BACKENDS_BMV2_PNA_NIC_PNANIC_H_
20#include "backends/bmv2/portable_common/portable.h"
21#include "pnaProgramStructure.h"
31 void modelError(
const char *format,
const cstring field) {
33 (
cstring(format) +
"\nInvalid metadata parameter value for PNA").c_str(),
37 Util::IJson *convertParam(UNUSED
const IR::Parameter *param,
cstring fieldName)
override {
38 cstring ptName = param->type->toString();
41 jsn->emplace(
"name"_cs, param->toString());
42 jsn->emplace(
"type"_cs,
"hexstr");
43 auto bitwidth = param->type->width_bits();
46 if (fieldName ==
"BYTES") {
47 cstring repr = BMV2::stringRepr(0, ROUNDUP(bitwidth, 32));
48 jsn->emplace(
"value"_cs, repr);
49 }
else if (fieldName ==
"PACKETS") {
50 cstring repr = BMV2::stringRepr(1, ROUNDUP(bitwidth, 32));
51 jsn->emplace(
"value"_cs, repr);
52 }
else if (fieldName ==
"PACKETS_AND_BYTES") {
53 cstring repr = BMV2::stringRepr(2, ROUNDUP(bitwidth, 32));
54 jsn->emplace(
"value"_cs, repr);
56 modelError(
"%1%: Exptected a PNA_CounterType_t", fieldName);
64 jsn->emplace(
"type"_cs,
"field");
65 auto a = mkArrayField(jsn,
"value"_cs);
66 a->append(ptName.exceptLast(2));
92 const IR::ToplevelBlock *toplevel;
98 const IR::ToplevelBlock *toplevel,
JsonObjects *json,
100 : refMap(refMap), typeMap(typeMap), toplevel(toplevel), json(json), structure(structure) {
103 CHECK_NULL(toplevel);
105 CHECK_NULL(structure);
107 CHECK_NULL(codeGenerator);
110 void postorder(UNUSED
const IR::P4Program *program)
override {
111 cstring scalarsName =
"scalars"_cs;
114 auto ctxt =
new ConversionContext(refMap, typeMap, toplevel, structure, conv, json);
115 codeGenerator->create(ctxt, structure);
123 void convert(
const IR::ToplevelBlock *tlb)
override;
125 P4::ConvertEnums::EnumMapping *enumMap)
126 :
Backend(options, refMap, typeMap, enumMap), options(options) {}
129EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Hash)
130EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(InternetChecksum)
131EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Register)
Definition backends/bmv2/common/options.h:26
Backend is a the base class for SimpleSwitchBackend and PortableSwitchBackend.
Definition bmv2/common/backend.h:59
Definition expression.h:51
Definition JsonObjects.h:27
Definition bmv2/pna_nic/pnaProgramStructure.h:31
static bool isStandardMetadata(cstring ptName)
Definition bmv2/pna_nic/pnaProgramStructure.h:46
static bool isCounterMetadata(cstring ptName)
Definition bmv2/pna_nic/pnaProgramStructure.h:42
Definition portableProgramStructure.h:29
Definition backends/common/programStructure.h:32
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition action.cpp:21
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:51
Definition bmv2/common/helpers.h:297