Skip to content

Commit b079f1d

Browse files
Cleaned PNA_NIC PSA_SWITCH code
Signed-off-by: Rupesh Chiluka <[email protected]>
1 parent 4005380 commit b079f1d

File tree

8 files changed

+38
-48
lines changed

8 files changed

+38
-48
lines changed

backends/bmv2/pna_nic/main.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ limitations under the License.
2020
#include <string>
2121

2222
#include "backends/bmv2/common/JsonObjects.h"
23-
#include "backends/bmv2/pna_nic/midend.h"
24-
#include "backends/bmv2/pna_nic/options.h"
25-
#include "backends/bmv2/pna_nic/pnaNic.h"
23+
#include "midend.h"
24+
#include "options.h"
25+
#include "pnaNic.h"
2626
#include "backends/bmv2/pna_nic/version.h"
2727
#include "control-plane/p4RuntimeSerializer.h"
2828
#include "frontends/common/applyOptionsPragmas.h"

backends/bmv2/pna_nic/options.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
#include "options.h"
22

3-
#include "frontends/common/parser_options.h"
4-
#include "lib/exename.h"
5-
63
namespace P4::BMV2 {} // namespace P4::BMV2

backends/bmv2/pna_nic/options.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ limitations under the License.
1717
#ifndef BACKENDS_BMV2_PNA_NIC_OPTIONS_H_
1818
#define BACKENDS_BMV2_PNA_NIC_OPTIONS_H_
1919

20-
#include "backends/bmv2/pna_nic/midend.h"
2120
#include "backends/bmv2/portable_common/options.h"
21+
#include "midend.h"
2222

2323
namespace P4::BMV2 {
2424

backends/bmv2/pna_nic/pnaNic.cpp

+25-26
Original file line numberDiff line numberDiff line change
@@ -149,24 +149,24 @@ Util::IJson *ExternConverter_Hash::convertExternObject(UNUSED ConversionContext
149149
auto parameters = mkParameters(primitive);
150150
primitive->emplace_non_null("source_info"_cs, s->sourceInfoJsonObj());
151151
auto hash = new Util::JsonObject();
152-
hash->emplace("type"_cs, "extern");
153-
hash->emplace("value"_cs, em->object->controlPlaneName());
152+
hash->emplace("type", "extern");
153+
hash->emplace("value", em->object->controlPlaneName());
154154
parameters->append(hash);
155155
if (mc->arguments->size() == 2) { // get_hash
156156
auto dst = ctxt->conv->convertLeftValue(mc->arguments->at(0)->expression);
157157
auto fieldList = new Util::JsonObject();
158-
fieldList->emplace("type"_cs, "field_list");
158+
fieldList->emplace("type", "field_list");
159159
auto fieldsJson = ctxt->conv->convert(mc->arguments->at(1)->expression, true, false);
160-
fieldList->emplace("value"_cs, fieldsJson);
160+
fieldList->emplace("value", fieldsJson);
161161
parameters->append(dst);
162162
parameters->append(fieldList);
163163
} else { // get_hash with base and mod
164164
auto dst = ctxt->conv->convertLeftValue(mc->arguments->at(0)->expression);
165165
auto base = ctxt->conv->convert(mc->arguments->at(1)->expression);
166166
auto fieldList = new Util::JsonObject();
167-
fieldList->emplace("type"_cs, "field_list");
167+
fieldList->emplace("type", "field_list");
168168
auto fieldsJson = ctxt->conv->convert(mc->arguments->at(2)->expression, true, false);
169-
fieldList->emplace("value"_cs, fieldsJson);
169+
fieldList->emplace("value", fieldsJson);
170170
auto max = ctxt->conv->convert(mc->arguments->at(3)->expression);
171171
parameters->append(dst);
172172
parameters->append(base);
@@ -207,14 +207,14 @@ Util::IJson *ExternConverter_InternetChecksum::convertExternObject(
207207
auto parameters = mkParameters(primitive);
208208
primitive->emplace_non_null("source_info"_cs, s->sourceInfoJsonObj());
209209
auto cksum = new Util::JsonObject();
210-
cksum->emplace("type"_cs, "extern");
211-
cksum->emplace("value"_cs, em->object->controlPlaneName());
210+
cksum->emplace("type", "extern");
211+
cksum->emplace("value", em->object->controlPlaneName());
212212
parameters->append(cksum);
213213
if (em->method->name == "add" || em->method->name == "subtract") {
214214
auto fieldList = new Util::JsonObject();
215-
fieldList->emplace("type"_cs, "field_list");
215+
fieldList->emplace("type", "field_list");
216216
auto fieldsJson = ctxt->conv->convert(mc->arguments->at(0)->expression, true, false);
217-
fieldList->emplace("value"_cs, fieldsJson);
217+
fieldList->emplace("value", fieldsJson);
218218
parameters->append(fieldList);
219219
} else if (em->method->name != "clear") {
220220
if (mc->arguments->size() == 2) { // get_verify
@@ -245,9 +245,9 @@ Util::IJson *ExternConverter_Register::convertExternObject(
245245
return nullptr;
246246
}
247247
auto reg = new Util::JsonObject();
248-
reg->emplace("type"_cs, "register_array");
248+
reg->emplace("type", "register_array");
249249
cstring name = em->object->controlPlaneName();
250-
reg->emplace("value"_cs, name);
250+
reg->emplace("value", name);
251251
if (em->method->name == "read") {
252252
auto primitive = mkPrimitive("register_read"_cs);
253253
auto parameters = mkParameters(primitive);
@@ -277,14 +277,13 @@ void ExternConverter_Hash::convertExternInstance(ConversionContext *ctxt, const
277277
UNUSED const bool &emitExterns) {
278278
auto inst = c->to<IR::Declaration_Instance>();
279279
cstring name = inst->controlPlaneName();
280-
// auto pnaStructure = static_cast<PnaCodeGenerator *>(ctxt->structure);
281280
auto pnaStructure = new PnaCodeGenerator();
282281

283282
// add hash instance
284283
auto jhash = new Util::JsonObject();
285-
jhash->emplace("name"_cs, name);
286-
jhash->emplace("id"_cs, nextId("extern_instances"_cs));
287-
jhash->emplace("type"_cs, eb->getName());
284+
jhash->emplace("name", name);
285+
jhash->emplace("id", nextId("extern_instances"_cs));
286+
jhash->emplace("type", eb->getName());
288287
jhash->emplace_non_null("source_info"_cs, inst->sourceInfoJsonObj());
289288
ctxt->json->externs->append(jhash);
290289

@@ -305,9 +304,9 @@ void ExternConverter_Hash::convertExternInstance(ConversionContext *ctxt, const
305304
cstring algo_name = algo->to<IR::Declaration_ID>()->name;
306305
algo_name = pnaStructure->convertHashAlgorithm(algo_name);
307306
auto k = new Util::JsonObject();
308-
k->emplace("name"_cs, "algo");
309-
k->emplace("type"_cs, "string");
310-
k->emplace("value"_cs, algo_name);
307+
k->emplace("name", "algo");
308+
k->emplace("type", "string");
309+
k->emplace("value", algo_name);
311310
arr->append(k);
312311
}
313312

@@ -328,9 +327,9 @@ void ExternConverter_InternetChecksum::convertExternInstance(UNUSED ConversionCo
328327
}
329328
// add checksum instance
330329
auto jcksum = new Util::JsonObject();
331-
jcksum->emplace("name"_cs, name);
332-
jcksum->emplace("id"_cs, nextId("extern_instances"_cs));
333-
jcksum->emplace("type"_cs, eb->getName());
330+
jcksum->emplace("name", name);
331+
jcksum->emplace("id", nextId("extern_instances"_cs));
332+
jcksum->emplace("type", eb->getName());
334333
jcksum->emplace_non_null("source_info"_cs, inst->sourceInfoJsonObj());
335334
ctxt->json->externs->append(jcksum);
336335
}
@@ -346,8 +345,8 @@ void ExternConverter_Register::convertExternInstance(UNUSED ConversionContext *c
346345
auto inst = c->to<IR::Declaration_Instance>();
347346
cstring name = inst->controlPlaneName();
348347
auto jreg = new Util::JsonObject();
349-
jreg->emplace("name"_cs, name);
350-
jreg->emplace("id"_cs, nextId("register_arrays"_cs));
348+
jreg->emplace("name", name);
349+
jreg->emplace("id", nextId("register_arrays"_cs));
351350
jreg->emplace_non_null("source_info"_cs, eb->sourceInfoJsonObj());
352351
auto sz = eb->findParameterValue("size"_cs);
353352
CHECK_NULL(sz);
@@ -357,7 +356,7 @@ void ExternConverter_Register::convertExternInstance(UNUSED ConversionContext *c
357356
}
358357
if (sz->to<IR::Constant>()->value == 0)
359358
error(ErrorType::ERR_UNSUPPORTED, "%1%: direct registers are not supported", inst);
360-
jreg->emplace("size"_cs, sz->to<IR::Constant>()->value);
359+
jreg->emplace("size", sz->to<IR::Constant>()->value);
361360
if (!eb->instanceType->is<IR::Type_SpecializedCanonical>()) {
362361
modelError("%1%: Expected a generic specialized type", eb->instanceType);
363362
return;
@@ -378,7 +377,7 @@ void ExternConverter_Register::convertExternInstance(UNUSED ConversionContext *c
378377
::P4::error(ErrorType::ERR_UNKNOWN, "%1%: unknown width", st->arguments->at(0));
379378
return;
380379
}
381-
jreg->emplace("bitwidth"_cs, width);
380+
jreg->emplace("bitwidth", width);
382381
ctxt->json->register_arrays->append(jreg);
383382
}
384383

backends/bmv2/pna_nic/pnaNic.h

+7-10
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ class PnaNicExpressionConverter : public ExpressionConverter {
3838
cstring ptName = param->type->toString();
3939
if (PnaProgramStructure::isCounterMetadata(ptName)) { // check if its counter metadata
4040
auto jsn = new Util::JsonObject();
41-
jsn->emplace("name"_cs, param->toString());
42-
jsn->emplace("type"_cs, "hexstr");
43-
auto bitwidth = param->type->width_bits();
41+
jsn->emplace("name", param->toString());
42+
jsn->emplace("type", "hexstr");
43+
auto bitwidth = 0;
4444

4545
// encode the counter type from enum -> int
4646
if (fieldName == "BYTES") {
4747
cstring repr = BMV2::stringRepr(0, ROUNDUP(bitwidth, 32));
48-
jsn->emplace("value"_cs, repr);
48+
jsn->emplace("value", repr);
4949
} else if (fieldName == "PACKETS") {
5050
cstring repr = BMV2::stringRepr(1, ROUNDUP(bitwidth, 32));
51-
jsn->emplace("value"_cs, repr);
51+
jsn->emplace("value", repr);
5252
} else if (fieldName == "PACKETS_AND_BYTES") {
5353
cstring repr = BMV2::stringRepr(2, ROUNDUP(bitwidth, 32));
54-
jsn->emplace("value"_cs, repr);
54+
jsn->emplace("value", repr);
5555
} else {
5656
modelError("%1%: Exptected a PNA_CounterType_t", fieldName);
5757
return nullptr;
@@ -61,7 +61,7 @@ class PnaNicExpressionConverter : public ExpressionConverter {
6161
auto jsn = new Util::JsonObject();
6262

6363
// encode the metadata type and field in json
64-
jsn->emplace("type"_cs, "field");
64+
jsn->emplace("type", "field");
6565
auto a = mkArrayField(jsn, "value"_cs);
6666
a->append(ptName.exceptLast(2));
6767
a->append(fieldName);
@@ -76,9 +76,6 @@ class PnaNicExpressionConverter : public ExpressionConverter {
7676

7777
class PnaCodeGenerator : public PortableCodeGenerator {
7878
public:
79-
// PnaCodeGenerator(P4::ReferenceMap *refMap, P4::TypeMap *typeMap)
80-
// : PortableCodeGenerator(refMap, typeMap) {}
81-
8279
void create(ConversionContext *ctxt, P4::PortableProgramStructure *structure);
8380
void createParsers(ConversionContext *ctxt, P4::PortableProgramStructure *structure);
8481
void createControls(ConversionContext *ctxt, P4::PortableProgramStructure *structure);

backends/bmv2/psa_switch/options.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ limitations under the License.
1818
#define BACKENDS_BMV2_PSA_SWITCH_OPTIONS_H_
1919

2020
#include "backends/bmv2/portable_common/options.h"
21-
#include "backends/bmv2/psa_switch/midend.h"
21+
#include "midend.h"
2222

2323
namespace P4::BMV2 {
2424

backends/bmv2/psa_switch/psaSwitch.h

-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ class PsaSwitchExpressionConverter : public ExpressionConverter {
7979

8080
class PsaCodeGenerator : public PortableCodeGenerator {
8181
public:
82-
// PsaCodeGenerator(P4::ReferenceMap *refMap, P4::TypeMap *typeMap)
83-
// : PortableCodeGenerator(refMap, typeMap) {}
84-
8582
void create(ConversionContext *ctxt, P4::PortableProgramStructure *structure);
8683
void createParsers(ConversionContext *ctxt, P4::PortableProgramStructure *structure);
8784
void createControls(ConversionContext *ctxt, P4::PortableProgramStructure *structure);

backends/common/psaProgramStructure.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
1515
limitations under the License.
1616
*/
1717

18-
#include "backends/common/psaProgramStructure.h"
18+
#include "psaProgramStructure.h"
1919

2020
namespace P4 {
2121

0 commit comments

Comments
 (0)