From aaa797caebe1e9dcd0bb7063f9c9ebc1acbb6428 Mon Sep 17 00:00:00 2001 From: Rupesh Chiluka Date: Mon, 28 Oct 2024 23:09:24 +0530 Subject: [PATCH] Cleaned PNA_NIC PSA_SWITCH code Signed-off-by: Rupesh Chiluka --- backends/bmv2/pna_nic/options.cpp | 3 -- backends/bmv2/pna_nic/pnaNic.cpp | 51 ++++++++++++------------- backends/bmv2/pna_nic/pnaNic.h | 17 ++++----- backends/bmv2/psa_switch/options.h | 2 +- backends/bmv2/psa_switch/psaSwitch.h | 3 -- backends/common/psaProgramStructure.cpp | 2 +- 6 files changed, 34 insertions(+), 44 deletions(-) diff --git a/backends/bmv2/pna_nic/options.cpp b/backends/bmv2/pna_nic/options.cpp index 2d07e432ebc..7a74947e9df 100644 --- a/backends/bmv2/pna_nic/options.cpp +++ b/backends/bmv2/pna_nic/options.cpp @@ -1,6 +1,3 @@ #include "options.h" -#include "frontends/common/parser_options.h" -#include "lib/exename.h" - namespace P4::BMV2 {} // namespace P4::BMV2 diff --git a/backends/bmv2/pna_nic/pnaNic.cpp b/backends/bmv2/pna_nic/pnaNic.cpp index 33b5e70dbf5..acfec9ffce6 100644 --- a/backends/bmv2/pna_nic/pnaNic.cpp +++ b/backends/bmv2/pna_nic/pnaNic.cpp @@ -149,24 +149,24 @@ Util::IJson *ExternConverter_Hash::convertExternObject(UNUSED ConversionContext auto parameters = mkParameters(primitive); primitive->emplace_non_null("source_info"_cs, s->sourceInfoJsonObj()); auto hash = new Util::JsonObject(); - hash->emplace("type"_cs, "extern"); - hash->emplace("value"_cs, em->object->controlPlaneName()); + hash->emplace("type", "extern"); + hash->emplace("value", em->object->controlPlaneName()); parameters->append(hash); if (mc->arguments->size() == 2) { // get_hash auto dst = ctxt->conv->convertLeftValue(mc->arguments->at(0)->expression); auto fieldList = new Util::JsonObject(); - fieldList->emplace("type"_cs, "field_list"); + fieldList->emplace("type", "field_list"); auto fieldsJson = ctxt->conv->convert(mc->arguments->at(1)->expression, true, false); - fieldList->emplace("value"_cs, fieldsJson); + fieldList->emplace("value", fieldsJson); parameters->append(dst); parameters->append(fieldList); } else { // get_hash with base and mod auto dst = ctxt->conv->convertLeftValue(mc->arguments->at(0)->expression); auto base = ctxt->conv->convert(mc->arguments->at(1)->expression); auto fieldList = new Util::JsonObject(); - fieldList->emplace("type"_cs, "field_list"); + fieldList->emplace("type", "field_list"); auto fieldsJson = ctxt->conv->convert(mc->arguments->at(2)->expression, true, false); - fieldList->emplace("value"_cs, fieldsJson); + fieldList->emplace("value", fieldsJson); auto max = ctxt->conv->convert(mc->arguments->at(3)->expression); parameters->append(dst); parameters->append(base); @@ -207,14 +207,14 @@ Util::IJson *ExternConverter_InternetChecksum::convertExternObject( auto parameters = mkParameters(primitive); primitive->emplace_non_null("source_info"_cs, s->sourceInfoJsonObj()); auto cksum = new Util::JsonObject(); - cksum->emplace("type"_cs, "extern"); - cksum->emplace("value"_cs, em->object->controlPlaneName()); + cksum->emplace("type", "extern"); + cksum->emplace("value", em->object->controlPlaneName()); parameters->append(cksum); if (em->method->name == "add" || em->method->name == "subtract") { auto fieldList = new Util::JsonObject(); - fieldList->emplace("type"_cs, "field_list"); + fieldList->emplace("type", "field_list"); auto fieldsJson = ctxt->conv->convert(mc->arguments->at(0)->expression, true, false); - fieldList->emplace("value"_cs, fieldsJson); + fieldList->emplace("value", fieldsJson); parameters->append(fieldList); } else if (em->method->name != "clear") { if (mc->arguments->size() == 2) { // get_verify @@ -245,9 +245,9 @@ Util::IJson *ExternConverter_Register::convertExternObject( return nullptr; } auto reg = new Util::JsonObject(); - reg->emplace("type"_cs, "register_array"); + reg->emplace("type", "register_array"); cstring name = em->object->controlPlaneName(); - reg->emplace("value"_cs, name); + reg->emplace("value", name); if (em->method->name == "read") { auto primitive = mkPrimitive("register_read"_cs); auto parameters = mkParameters(primitive); @@ -277,14 +277,13 @@ void ExternConverter_Hash::convertExternInstance(ConversionContext *ctxt, const UNUSED const bool &emitExterns) { auto inst = c->to(); cstring name = inst->controlPlaneName(); - // auto pnaStructure = static_cast(ctxt->structure); auto pnaStructure = new PnaCodeGenerator(); // add hash instance auto jhash = new Util::JsonObject(); - jhash->emplace("name"_cs, name); - jhash->emplace("id"_cs, nextId("extern_instances"_cs)); - jhash->emplace("type"_cs, eb->getName()); + jhash->emplace("name", name); + jhash->emplace("id", nextId("extern_instances"_cs)); + jhash->emplace("type", eb->getName()); jhash->emplace_non_null("source_info"_cs, inst->sourceInfoJsonObj()); ctxt->json->externs->append(jhash); @@ -305,9 +304,9 @@ void ExternConverter_Hash::convertExternInstance(ConversionContext *ctxt, const cstring algo_name = algo->to()->name; algo_name = pnaStructure->convertHashAlgorithm(algo_name); auto k = new Util::JsonObject(); - k->emplace("name"_cs, "algo"); - k->emplace("type"_cs, "string"); - k->emplace("value"_cs, algo_name); + k->emplace("name", "algo"); + k->emplace("type", "string"); + k->emplace("value", algo_name); arr->append(k); } @@ -328,9 +327,9 @@ void ExternConverter_InternetChecksum::convertExternInstance(UNUSED ConversionCo } // add checksum instance auto jcksum = new Util::JsonObject(); - jcksum->emplace("name"_cs, name); - jcksum->emplace("id"_cs, nextId("extern_instances"_cs)); - jcksum->emplace("type"_cs, eb->getName()); + jcksum->emplace("name", name); + jcksum->emplace("id", nextId("extern_instances"_cs)); + jcksum->emplace("type", eb->getName()); jcksum->emplace_non_null("source_info"_cs, inst->sourceInfoJsonObj()); ctxt->json->externs->append(jcksum); } @@ -346,8 +345,8 @@ void ExternConverter_Register::convertExternInstance(UNUSED ConversionContext *c auto inst = c->to(); cstring name = inst->controlPlaneName(); auto jreg = new Util::JsonObject(); - jreg->emplace("name"_cs, name); - jreg->emplace("id"_cs, nextId("register_arrays"_cs)); + jreg->emplace("name", name); + jreg->emplace("id", nextId("register_arrays"_cs)); jreg->emplace_non_null("source_info"_cs, eb->sourceInfoJsonObj()); auto sz = eb->findParameterValue("size"_cs); CHECK_NULL(sz); @@ -357,7 +356,7 @@ void ExternConverter_Register::convertExternInstance(UNUSED ConversionContext *c } if (sz->to()->value == 0) error(ErrorType::ERR_UNSUPPORTED, "%1%: direct registers are not supported", inst); - jreg->emplace("size"_cs, sz->to()->value); + jreg->emplace("size", sz->to()->value); if (!eb->instanceType->is()) { modelError("%1%: Expected a generic specialized type", eb->instanceType); return; @@ -378,7 +377,7 @@ void ExternConverter_Register::convertExternInstance(UNUSED ConversionContext *c ::P4::error(ErrorType::ERR_UNKNOWN, "%1%: unknown width", st->arguments->at(0)); return; } - jreg->emplace("bitwidth"_cs, width); + jreg->emplace("bitwidth", width); ctxt->json->register_arrays->append(jreg); } diff --git a/backends/bmv2/pna_nic/pnaNic.h b/backends/bmv2/pna_nic/pnaNic.h index 51aea20646f..e0d89ff2056 100644 --- a/backends/bmv2/pna_nic/pnaNic.h +++ b/backends/bmv2/pna_nic/pnaNic.h @@ -38,20 +38,20 @@ class PnaNicExpressionConverter : public ExpressionConverter { cstring ptName = param->type->toString(); if (PnaProgramStructure::isCounterMetadata(ptName)) { // check if its counter metadata auto jsn = new Util::JsonObject(); - jsn->emplace("name"_cs, param->toString()); - jsn->emplace("type"_cs, "hexstr"); - auto bitwidth = param->type->width_bits(); + jsn->emplace("name", param->toString()); + jsn->emplace("type", "hexstr"); + auto bitwidth = 0; // encode the counter type from enum -> int if (fieldName == "BYTES") { cstring repr = BMV2::stringRepr(0, ROUNDUP(bitwidth, 32)); - jsn->emplace("value"_cs, repr); + jsn->emplace("value", repr); } else if (fieldName == "PACKETS") { cstring repr = BMV2::stringRepr(1, ROUNDUP(bitwidth, 32)); - jsn->emplace("value"_cs, repr); + jsn->emplace("value", repr); } else if (fieldName == "PACKETS_AND_BYTES") { cstring repr = BMV2::stringRepr(2, ROUNDUP(bitwidth, 32)); - jsn->emplace("value"_cs, repr); + jsn->emplace("value", repr); } else { modelError("%1%: Exptected a PNA_CounterType_t", fieldName); return nullptr; @@ -61,7 +61,7 @@ class PnaNicExpressionConverter : public ExpressionConverter { auto jsn = new Util::JsonObject(); // encode the metadata type and field in json - jsn->emplace("type"_cs, "field"); + jsn->emplace("type", "field"); auto a = mkArrayField(jsn, "value"_cs); a->append(ptName.exceptLast(2)); a->append(fieldName); @@ -76,9 +76,6 @@ class PnaNicExpressionConverter : public ExpressionConverter { class PnaCodeGenerator : public PortableCodeGenerator { public: - // PnaCodeGenerator(P4::ReferenceMap *refMap, P4::TypeMap *typeMap) - // : PortableCodeGenerator(refMap, typeMap) {} - void create(ConversionContext *ctxt, P4::PortableProgramStructure *structure); void createParsers(ConversionContext *ctxt, P4::PortableProgramStructure *structure); void createControls(ConversionContext *ctxt, P4::PortableProgramStructure *structure); diff --git a/backends/bmv2/psa_switch/options.h b/backends/bmv2/psa_switch/options.h index 910d3e247c5..2bee4a2f793 100644 --- a/backends/bmv2/psa_switch/options.h +++ b/backends/bmv2/psa_switch/options.h @@ -18,7 +18,7 @@ limitations under the License. #define BACKENDS_BMV2_PSA_SWITCH_OPTIONS_H_ #include "backends/bmv2/portable_common/options.h" -#include "backends/bmv2/psa_switch/midend.h" +#include "midend.h" namespace P4::BMV2 { diff --git a/backends/bmv2/psa_switch/psaSwitch.h b/backends/bmv2/psa_switch/psaSwitch.h index 17837c90299..43fd0eee716 100644 --- a/backends/bmv2/psa_switch/psaSwitch.h +++ b/backends/bmv2/psa_switch/psaSwitch.h @@ -79,9 +79,6 @@ class PsaSwitchExpressionConverter : public ExpressionConverter { class PsaCodeGenerator : public PortableCodeGenerator { public: - // PsaCodeGenerator(P4::ReferenceMap *refMap, P4::TypeMap *typeMap) - // : PortableCodeGenerator(refMap, typeMap) {} - void create(ConversionContext *ctxt, P4::PortableProgramStructure *structure); void createParsers(ConversionContext *ctxt, P4::PortableProgramStructure *structure); void createControls(ConversionContext *ctxt, P4::PortableProgramStructure *structure); diff --git a/backends/common/psaProgramStructure.cpp b/backends/common/psaProgramStructure.cpp index dc738da7546..288f0949737 100644 --- a/backends/common/psaProgramStructure.cpp +++ b/backends/common/psaProgramStructure.cpp @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -#include "backends/common/psaProgramStructure.h" +#include "psaProgramStructure.h" namespace P4 {