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/common/programStructure.h" 
   29#include "backends/common/psaProgramStructure.h" 
   30#include "frontends/common/constantFolding.h" 
   31#include "frontends/common/resolveReferences/referenceMap.h" 
   32#include "frontends/p4/coreLibrary.h" 
   33#include "frontends/p4/enumInstance.h" 
   34#include "frontends/p4/evaluator/evaluator.h" 
   35#include "frontends/p4/methodInstance.h" 
   36#include "frontends/p4/simplify.h" 
   37#include "frontends/p4/strengthReduction.h" 
   38#include "frontends/p4/typeMap.h" 
   39#include "frontends/p4/unusedDeclarations.h" 
   41#include "lib/big_int_util.h" 
   52    void modelError(
const char *format, 
const cstring field) {
 
   53        ::error(ErrorType::ERR_MODEL,
 
   54                (
cstring(format) + 
"\nInvalid metadata parameter value for PSA").c_str(), field);
 
   57    Util::IJson *convertParam(UNUSED 
const IR::Parameter *param, 
cstring fieldName)
 override {
 
   58        cstring ptName = param->type->toString();
 
   61            jsn->emplace(
"name", param->toString());
 
   62            jsn->emplace(
"type", 
"hexstr");
 
   63            auto bitwidth = param->type->width_bits();
 
   66            if (fieldName == 
"BYTES") {
 
   67                cstring repr = BMV2::stringRepr(0, ROUNDUP(bitwidth, 32));
 
   68                jsn->emplace(
"value", repr);
 
   69            } 
else if (fieldName == 
"PACKETS") {
 
   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);
 
   85            jsn->emplace(
"type", 
"field");
 
   86            auto a = mkArrayField(jsn, 
"value"_cs);
 
   87            a->append(ptName.exceptLast(2));
 
 
  109    void createExterns();
 
  113    void createGlobals();
 
 
  121    const IR::ToplevelBlock *toplevel;
 
  126                     const IR::ToplevelBlock *toplevel, 
JsonObjects *json,
 
  128        : refMap(refMap), typeMap(typeMap), toplevel(toplevel), json(json), structure(structure) {
 
  131        CHECK_NULL(toplevel);
 
  133        CHECK_NULL(structure);
 
  136    void postorder(UNUSED 
const IR::P4Program *program)
 override {
 
  137        cstring scalarsName = 
"scalars"_cs;
 
  140        auto ctxt = 
new ConversionContext(refMap, typeMap, toplevel, structure, conv, json);
 
  141        structure->create(ctxt);
 
 
  149    void convert(
const IR::ToplevelBlock *tlb) 
override;
 
  151                     P4::ConvertEnums::EnumMapping *enumMap)
 
  152        : 
Backend(options, refMap, typeMap, enumMap), options(options) {}
 
 
  155EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Hash)
 
  156EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Checksum)
 
  157EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(InternetChecksum)
 
  158EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Counter)
 
  159EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(DirectCounter)
 
  160EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Meter)
 
  161EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(DirectMeter)
 
  162EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Register)
 
  163EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Random)
 
  164EXTERN_CONVERTER_W_INSTANCE(ActionProfile)
 
  165EXTERN_CONVERTER_W_INSTANCE(ActionSelector)
 
  166EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Digest)
 
Definition backends/bmv2/common/options.h:26
 
Backend is a the base class for SimpleSwitchBackend and PortableSwitchBackend.
Definition bmv2/common/backend.h:59
 
Definition psaSwitch.h:117
 
Definition expression.h:51
 
Definition JsonObjects.h:27
 
Definition psaSwitch.h:98
 
Definition psaSwitch.h:145
 
Definition psaSwitch.h:46
 
Definition backends/common/programStructure.h:32
 
Definition common/psaProgramStructure.h:36
 
static bool isCounterMetadata(cstring ptName)
Definition common/psaProgramStructure.h:92
 
static bool isStandardMetadata(cstring ptName)
Definition common/psaProgramStructure.h:96
 
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