17#ifndef BACKENDS_BMV2_PSA_SWITCH_PSASWITCH_H_
18#define BACKENDS_BMV2_PSA_SWITCH_PSASWITCH_H_
20#include "backends/bmv2/portable_common/portable.h"
21#include "backends/common/psaProgramStructure.h"
31 void modelError(
const char *format,
const cstring field) {
33 (
cstring(format) +
"\nInvalid metadata parameter value for PSA").c_str(),
37 Util::IJson *convertParam(UNUSED
const IR::Parameter *param,
cstring fieldName)
override {
38 cstring ptName = param->type->toString();
41 jsn->emplace(
"name", param->toString());
42 jsn->emplace(
"type",
"hexstr");
48 if (fieldName ==
"BYTES") {
49 cstring repr = BMV2::stringRepr(0, ROUNDUP(bitwidth, 32));
50 jsn->emplace(
"value", repr);
51 }
else if (fieldName ==
"PACKETS") {
52 cstring repr = BMV2::stringRepr(1, ROUNDUP(bitwidth, 32));
53 jsn->emplace(
"value", repr);
54 }
else if (fieldName ==
"PACKETS_AND_BYTES") {
55 cstring repr = BMV2::stringRepr(2, ROUNDUP(bitwidth, 32));
56 jsn->emplace(
"value", repr);
58 modelError(
"%1%: Exptected a PSA_CounterType_t", fieldName);
67 jsn->emplace(
"type",
"field");
68 auto a = mkArrayField(jsn,
"value"_cs);
69 a->append(ptName.exceptLast(2));
95 const IR::ToplevelBlock *toplevel;
101 const IR::ToplevelBlock *toplevel,
JsonObjects *json,
103 : refMap(refMap), typeMap(typeMap), toplevel(toplevel), json(json), structure(structure) {
106 CHECK_NULL(toplevel);
108 CHECK_NULL(structure);
110 CHECK_NULL(codeGenerator);
113 void postorder(UNUSED
const IR::P4Program *program)
override {
114 cstring scalarsName =
"scalars"_cs;
117 auto ctxt =
new ConversionContext(refMap, typeMap, toplevel, structure, conv, json);
118 codeGenerator->create(ctxt, structure);
126 void convert(
const IR::ToplevelBlock *tlb)
override;
128 P4::ConvertEnums::EnumMapping *enumMap)
129 :
Backend(options, refMap, typeMap, enumMap), options(options) {}
132EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Hash)
133EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(InternetChecksum)
134EXTERN_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:60
Definition psaSwitch.h:91
Definition expression.h:51
Definition JsonObjects.h:27
Definition psaSwitch.h:80
Definition psaSwitch.h:122
Definition psaSwitch.h:25
Definition portableProgramStructure.h:29
Definition backends/common/programStructure.h:32
Definition psaProgramStructure.h:36
static bool isCounterMetadata(cstring ptName)
Definition psaProgramStructure.h:47
static bool isStandardMetadata(cstring ptName)
Definition psaProgramStructure.h:51
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