17#ifndef BACKENDS_BMV2_PSA_SWITCH_PSASWITCH_H_
18#define BACKENDS_BMV2_PSA_SWITCH_PSASWITCH_H_
20#include "backends/bmv2/common/action.h"
21#include "backends/bmv2/common/control.h"
22#include "backends/bmv2/common/deparser.h"
23#include "backends/bmv2/common/extern.h"
24#include "backends/bmv2/common/header.h"
25#include "backends/bmv2/common/helpers.h"
26#include "backends/bmv2/common/lower.h"
27#include "backends/bmv2/common/parser.h"
28#include "backends/bmv2/common/programStructure.h"
29#include "frontends/common/constantFolding.h"
30#include "frontends/common/resolveReferences/referenceMap.h"
31#include "frontends/p4/coreLibrary.h"
32#include "frontends/p4/enumInstance.h"
33#include "frontends/p4/evaluator/evaluator.h"
34#include "frontends/p4/methodInstance.h"
35#include "frontends/p4/simplify.h"
36#include "frontends/p4/strengthReduction.h"
37#include "frontends/p4/typeMap.h"
38#include "frontends/p4/unusedDeclarations.h"
40#include "lib/big_int_util.h"
42#include "psaProgramStructure.h"
53 ::error(ErrorType::ERR_MODEL,
54 (
cstring(
format) +
"\nInvalid metadata parameter value for PSA").c_str(), field);
61 jsn->emplace(
"name", param->toString());
62 jsn->emplace(
"type",
"hexstr");
63 auto bitwidth = param->type->width_bits();
67 cstring repr = BMV2::stringRepr(0, ROUNDUP(bitwidth, 32));
68 jsn->emplace(
"value", repr);
70 cstring repr = BMV2::stringRepr(1, ROUNDUP(bitwidth, 32));
71 jsn->emplace(
"value", repr);
72 }
else if (
fieldName ==
"PACKETS_AND_BYTES") {
73 cstring repr = BMV2::stringRepr(2, ROUNDUP(bitwidth, 32));
74 jsn->emplace(
"value", repr);
76 modelError(
"%1%: Exptected a PSA_CounterType_t",
fieldName);
84 jsn->emplace(
"type",
"field");
85 auto a = mkArrayField(
jsn,
"value");
86 a->append(
ptName.exceptLast(2));
108 void createExterns();
112 void createGlobals();
120 const IR::ToplevelBlock *toplevel;
125 const IR::ToplevelBlock *toplevel,
JsonObjects *json,
127 : refMap(refMap), typeMap(typeMap), toplevel(toplevel), json(json), structure(structure) {
130 CHECK_NULL(toplevel);
132 CHECK_NULL(structure);
135 void postorder(UNUSED
const IR::P4Program *program)
override {
136 cstring scalarsName =
"scalars";
139 auto ctxt =
new ConversionContext(refMap, typeMap, toplevel, structure, conv, json);
140 structure->create(ctxt);
148 void convert(
const IR::ToplevelBlock *tlb)
override;
150 P4::ConvertEnums::EnumMapping *enumMap)
151 :
Backend(options, refMap, typeMap, enumMap), options(options) {}
154EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Hash)
155EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(
Checksum)
157EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Counter)
159EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Meter)
161EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Register)
162EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(
Random)
163EXTERN_CONVERTER_W_INSTANCE(ActionProfile)
164EXTERN_CONVERTER_W_INSTANCE(ActionSelector)
165EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Digest)
Definition psaSwitch.h:116
Definition expression.h:53
Definition JsonObjects.h:27
Definition programStructure.h:40
Definition psaSwitch.h:97
Definition psaProgramStructure.h:29
static bool isStandardMetadata(cstring ptName)
Definition psaProgramStructure.h:93
static bool isCounterMetadata(cstring ptName)
Definition psaProgramStructure.h:87
Definition psaSwitch.h:144
Definition psaSwitch.h:46
Definition sharedActionSelectorCheck.h:40
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66