-
Notifications
You must be signed in to change notification settings - Fork 455
/
Copy pathspec.cpp
672 lines (608 loc) · 24.9 KB
/
spec.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
#include "constants.h"
#include "dpdkArch.h"
#include "dpdkAsmOpt.h"
#include "dpdkHelpers.h"
#include "ir/annotations.h"
#include "ir/dbprint.h"
#include "printUtils.h"
namespace P4 {
using namespace P4::DBPrint;
ordered_map<cstring, int> DPDK::CollectDirectCounterMeter::directMeterCounterSizeMap = {};
auto &directMeterCounterSizeMap = DPDK::CollectDirectCounterMeter::directMeterCounterSizeMap;
ordered_map<cstring, cstring> DPDK::ShortenTokenLength::origNameMap = {};
auto &origNameMap = DPDK::ShortenTokenLength::origNameMap;
void add_space(std::ostream &out, int size) { out << std::setfill(' ') << std::setw(size) << " "; }
void add_comment(std::ostream &out, cstring str, std::string_view sep = "") {
if (origNameMap.count(str)) {
out << sep << ";oldname:" << origNameMap.at(str) << "\n";
}
}
std::ostream &IR::DpdkAsmProgram::toSpec(std::ostream &out) const {
for (auto l : globals) {
l->toSpec(out) << std::endl;
}
out << std::endl;
for (auto h : headerType) {
add_comment(out, h->name.toString());
h->toSpec(out) << std::endl;
}
for (auto s : structType) {
add_comment(out, s->name.toString());
s->toSpec(out) << std::endl;
}
for (auto hi : headerInstance) {
add_comment(out, hi->name->toString());
hi->toSpec(out) << std::endl;
}
for (auto s : externDeclarations) {
add_comment(out, s->name.toString());
s->toSpec(out);
}
for (auto a : actions) {
add_comment(out, a->name.toString());
a->toSpec(out) << std::endl << std::endl;
}
for (auto t : tables) {
add_comment(out, t->name);
t->toSpec(out) << std::endl << std::endl;
}
for (auto s : selectors) {
add_comment(out, s->name);
s->toSpec(out) << std::endl;
}
for (auto s : learners) {
add_comment(out, s->name);
s->toSpec(out) << std::endl;
}
for (auto s : statements) {
s->toSpec(out) << std::endl;
}
return out;
}
std::ostream &IR::DpdkAsmStatement::toSpec(std::ostream &out) const {
BUG("asm statement %1% not implemented", this);
return out;
}
std::ostream &IR::DpdkDeclaration::toSpec(std::ostream &out) const {
// TBD
return out;
}
std::ostream &IR::DpdkExternDeclaration::toSpec(std::ostream &out) const {
if (DPDK::toStr(getType()) == "Hash") {
auto args = arguments;
if (args->size() == 0) {
::P4::error(ErrorType::ERR_INVALID,
"Hash extern declaration %1% must contain hash algorithm \n", Name());
} else {
auto hashAlg = args->at(0)->expression;
unsigned hashAlgValue = CRC1;
if (hashAlg->is<IR::Constant>())
hashAlgValue = hashAlg->to<IR::Constant>()->asUnsigned();
if (hashAlgValue == TOEPLITZ) {
auto hashDecl = new IR::DpdkHashDeclStatement(Name());
hashDecl->toSpec(out) << std::endl;
}
}
} else if (DPDK::toStr(getType()) == "Register") {
auto args = arguments;
if (args->size() == 0) {
::P4::error(ErrorType::ERR_INVALID,
"Register extern declaration %1% must contain a size parameter\n", Name());
} else {
auto size = args->at(0)->expression;
auto init_val = args->size() == 2 ? args->at(1)->expression : nullptr;
auto regDecl = new IR::DpdkRegisterDeclStatement(Name(), size, init_val);
regDecl->toSpec(out) << std::endl;
}
} else if (DPDK::toStr(getType()) == "Counter") {
auto args = arguments;
unsigned value = 0;
if (args->size() < 2) {
::P4::error(ErrorType::ERR_INVALID,
"Counter extern declaration %1% must contain 2 parameters\n", Name());
} else {
auto n_counters = args->at(0)->expression;
auto counter_type = args->at(1)->expression;
if (counter_type->is<IR::Constant>())
value = counter_type->to<IR::Constant>()->asUnsigned();
if (value == 2) {
// For PACKETS_AND_BYTES counter type, two regarray declarations are emitted and
// the counter name is suffixed with _packets and _bytes.
auto regDecl = new IR::DpdkRegisterDeclStatement(Name() + "_packets", n_counters,
new IR::Constant(0));
regDecl->toSpec(out) << std::endl << std::endl;
regDecl = new IR::DpdkRegisterDeclStatement(Name() + "_bytes", n_counters,
new IR::Constant(0));
regDecl->toSpec(out) << std::endl;
} else {
auto regDecl =
new IR::DpdkRegisterDeclStatement(Name(), n_counters, new IR::Constant(0));
regDecl->toSpec(out) << std::endl;
}
}
} else if (DPDK::toStr(getType()) == "DirectCounter") {
auto args = arguments;
unsigned value = 0;
if (args->size() != 1) {
::P4::error(ErrorType::ERR_INVALID,
"Counter extern declaration %1% must contain 1 parameters\n", Name());
} else {
IR::Expression *n_counters = nullptr;
if (directMeterCounterSizeMap.count(Name())) {
n_counters = new IR::Constant(directMeterCounterSizeMap.at(Name()));
} else {
BUG("%1%: Direct Counter size is not populated", Name());
}
auto counter_type = args->at(0)->expression;
if (counter_type->is<IR::Constant>())
value = counter_type->to<IR::Constant>()->asUnsigned();
if (value == 2) {
// For PACKETS_AND_BYTES counter type, two regarray declarations are emitted and
// the counter name is suffixed with _packets and _bytes
auto regDecl = new IR::DpdkRegisterDeclStatement(Name() + "_packets", n_counters,
new IR::Constant(0));
regDecl->toSpec(out) << std::endl << std::endl;
regDecl = new IR::DpdkRegisterDeclStatement(Name() + "_bytes", n_counters,
new IR::Constant(0));
regDecl->toSpec(out) << std::endl;
} else {
auto regDecl =
new IR::DpdkRegisterDeclStatement(Name(), n_counters, new IR::Constant(0));
regDecl->toSpec(out) << std::endl;
}
}
} else if (DPDK::toStr(getType()) == "Meter") {
auto args = arguments;
if (args->size() < 2) {
::P4::error(ErrorType::ERR_INVALID,
"Meter extern declaration %1% must contain a size parameter"
" and meter type parameter",
Name());
} else {
auto n_meters = args->at(0)->expression;
auto metDecl = new IR::DpdkMeterDeclStatement(Name(), n_meters);
metDecl->toSpec(out) << std::endl;
}
} else if (DPDK::toStr(getType()) == "DirectMeter") {
auto args = arguments;
if (args->size() < 1) {
::P4::error(ErrorType::ERR_INVALID,
"Meter extern declaration %1% must have "
"meter type parameter",
Name());
} else {
IR::Expression *n_meters = nullptr;
if (directMeterCounterSizeMap.count(Name())) {
n_meters = new IR::Constant(directMeterCounterSizeMap.at(Name()));
} else {
BUG("%1%, Direct Meter size is not populated", Name());
}
auto metDecl = new IR::DpdkMeterDeclStatement(Name(), n_meters);
metDecl->toSpec(out) << std::endl;
}
}
return out;
}
std::ostream &IR::DpdkHeaderType::toSpec(std::ostream &out) const {
out << "struct " << name << " {" << std::endl;
for (auto it = fields.begin(); it != fields.end(); ++it) {
add_comment(out, (*it)->name.toString(), "\t");
if (auto t = (*it)->type->to<IR::Type_Bits>())
out << "\tbit<" << t->width_bits() << ">";
else if (auto t = (*it)->type->to<IR::Type_Name>())
out << "\t" << t->path->name;
else if ((*it)->type->to<IR::Type_Boolean>())
out << "\tbool";
else if (auto t = (*it)->type->to<IR::Type_Varbits>())
out << "\tvarbit<" << t->size << ">";
else {
BUG("Unsupported type: %1% ", *it);
}
out << " " << (*it)->externalName();
out << std::endl;
}
out << "}" << std::endl;
return out;
}
std::ostream &IR::DpdkHeaderInstance::toSpec(std::ostream &out) const {
out << "header " << name->toString() << " instanceof " << headerType->name.name;
return out;
}
std::ostream &IR::DpdkStructType::toSpec(std::ostream &out) const {
if (getAnnotation("__packet_data__"_cs)) {
for (auto it = fields.begin(); it != fields.end(); ++it) {
add_comment(out, (*it)->name.toString());
if (auto t = (*it)->type->to<IR::Type_Name>()) {
out << "header " << (*it)->name << " instanceof " << t->path->name;
} else if (auto t = (*it)->type->to<IR::Type_Stack>()) {
if (!t->elementType->is<IR::Type_Name>())
BUG("%1% Unsupported type", t->elementType);
cstring type_name = t->elementType->to<IR::Type_Name>()->path->name;
if (!t->size->is<IR::Constant>()) {
BUG("Header stack index in %1% must be compile-time constant", t);
}
for (auto i = 0; i < t->size->to<IR::Constant>()->value; i++) {
out << "header " << (*it)->name << "_" << i << " instanceof " << type_name
<< std::endl;
}
} else {
BUG("Unsupported type %1%", *it);
}
out << std::endl;
}
} else {
out << "struct " << name << " {" << std::endl;
for (auto it = fields.begin(); it != fields.end(); ++it) {
add_comment(out, (*it)->name.toString(), "\t");
if (auto t = (*it)->type->to<IR::Type_Bits>())
out << "\tbit<" << t->width_bits() << ">";
else if (auto t = (*it)->type->to<IR::Type_Name>()) {
if (t->path->name == "error") {
out << "\tbit<8>";
} else {
out << "\t" << t->path;
}
} else if ((*it)->type->to<IR::Type_Error>()) {
// DPDK implements error type as bit<8>
out << "\tbit<8>";
} else if ((*it)->type->to<IR::Type_Boolean>()) {
// DPDK implements bool as bit<8>
out << "\tbit<8>";
} else {
std::cout << (*it)->type->node_type_name() << std::endl;
BUG("Unsupported type");
}
out << " " << (*it)->externalName();
out << std::endl;
}
out << "}" << std::endl;
if (getAnnotation("__metadata__"_cs)) {
out << "metadata instanceof " << name << std::endl;
}
}
return out;
}
std::ostream &IR::DpdkListStatement::toSpec(std::ostream &out) const {
out << "apply {" << std::endl;
for (auto s : statements) {
out << "\t";
s->toSpec(out);
if (!s->to<IR::DpdkLabelStatement>()) out << std::endl;
}
out << "}" << std::endl;
return out;
}
std::ostream &IR::DpdkApplyStatement::toSpec(std::ostream &out) const {
out << "table " << table;
return out;
}
std::ostream &IR::DpdkMirrorStatement::toSpec(std::ostream &out) const {
out << "mirror " << DPDK::toStr(slotId) << " " << DPDK::toStr(sessionId);
return out;
}
std::ostream &IR::DpdkLearnStatement::toSpec(std::ostream &out) const {
out << "learn " << action << " ";
if (argument) out << DPDK::toStr(argument) << " ";
out << DPDK::toStr(timeout);
return out;
}
std::ostream &IR::DpdkEmitStatement::toSpec(std::ostream &out) const {
out << "emit " << DPDK::toStr(header);
return out;
}
std::ostream &IR::DpdkExtractStatement::toSpec(std::ostream &out) const {
out << "extract " << DPDK::toStr(header);
if (length) out << " " << DPDK::toStr(length);
return out;
}
std::ostream &IR::DpdkLookaheadStatement::toSpec(std::ostream &out) const {
out << "lookahead " << DPDK::toStr(header);
return out;
}
std::ostream &IR::DpdkJmpStatement::toSpec(std::ostream &out) const {
out << instruction << " " << label;
return out;
}
std::ostream &IR::DpdkJmpHeaderStatement::toSpec(std::ostream &out) const {
out << instruction << " " << label << " " << DPDK::toStr(header);
return out;
}
std::ostream &IR::DpdkJmpActionStatement::toSpec(std::ostream &out) const {
out << instruction << " " << label << " " << action;
return out;
}
std::ostream &IR::DpdkJmpCondStatement::toSpec(std::ostream &out) const {
out << instruction << " " << label << " " << DPDK::toStr(src1) << " " << DPDK::toStr(src2);
return out;
}
std::ostream &IR::DpdkBinaryStatement::toSpec(std::ostream &out) const {
BUG_CHECK(dst->equiv(*src1),
"The first source field %1% in a binary operation"
"must be the same as the destination field %2% to be supported by DPDK",
src1, dst);
out << instruction << " " << DPDK::toStr(dst) << " " << DPDK::toStr(src2);
return out;
}
std::ostream &IR::DpdkUnaryStatement::toSpec(std::ostream &out) const {
out << instruction << " " << DPDK::toStr(dst) << " " << DPDK::toStr(src);
return out;
}
std::ostream &IR::DpdkRxStatement::toSpec(std::ostream &out) const {
out << "rx " << DPDK::toStr(port);
return out;
}
std::ostream &IR::DpdkTxStatement::toSpec(std::ostream &out) const {
out << "tx " << DPDK::toStr(port);
return out;
}
std::ostream &IR::DpdkReturnStatement::toSpec(std::ostream &out) const {
out << "return ";
return out;
}
std::ostream &IR::DpdkRearmStatement::toSpec(std::ostream &out) const {
out << "rearm";
if (timeout) out << " " << DPDK::toStr(timeout);
return out;
}
std::ostream &IR::DpdkRecirculateStatement::toSpec(std::ostream &out) const {
out << "recirculate";
return out;
}
std::ostream &IR::DpdkRecircidStatement::toSpec(std::ostream &out) const {
out << "recircid " << DPDK::toStr(pass);
return out;
}
std::ostream &IR::DpdkLabelStatement::toSpec(std::ostream &out) const {
out << label << " :";
return out;
}
std::ostream &IR::DpdkTable::toSpec(std::ostream &out) const {
out << "table " << name << " {" << std::endl;
if (match_keys) {
out << "\tkey {" << std::endl;
for (auto key : match_keys->keyElements) {
out << "\t\t" << DPDK::toStr(key->expression) << " ";
if ((key->matchType)->toString() == "ternary" ||
(key->matchType)->toString() == "optional" ||
(key->matchType)->toString() == "range") {
out << "wildcard" << std::endl;
} else {
out << DPDK::toStr(key->matchType) << std::endl;
}
}
out << "\t}" << std::endl;
}
out << "\tactions {" << std::endl;
for (auto action : actions->actionList) {
if (action->expression->toString() == "NoAction") {
out << "\t\tNoAction";
} else {
out << "\t\t" << DPDK::toStr(action->expression);
}
if (action->hasAnnotation(IR::Annotation::tableOnlyAnnotation)) out << " @tableonly";
if (action->hasAnnotation(IR::Annotation::defaultOnlyAnnotation)) out << " @defaultonly";
out << std::endl;
}
out << "\t}" << std::endl;
if (default_action->toString() == "NoAction")
out << "\tdefault_action NoAction";
else
out << "\tdefault_action " << DPDK::toStr(default_action);
if (default_action->to<IR::MethodCallExpression>()->arguments->size() == 0) {
out << " args none ";
} else {
out << " args ";
auto mce = default_action->to<IR::MethodCallExpression>();
auto earg = mce->arguments->at(0)->expression;
if (earg->is<IR::ListExpression>()) {
auto paramCount = earg->to<IR::ListExpression>()->components.size();
for (unsigned i = 0; i < paramCount; i++) {
if (earg->to<IR::ListExpression>()->components.at(i)->is<IR::Constant>()) {
auto val = earg->to<IR::ListExpression>()
->components.at(i)
->to<IR::Constant>()
->asUnsigned();
out << default_action_paraList.parameters.at(i)->toString() << " ";
out << "0x" << std::hex << std::uppercase << val << " ";
} else if (earg->to<IR::ListExpression>()
->components.at(i)
->is<IR::BoolLiteral>()) {
earg->dbprint(std::cout);
auto val = earg->to<IR::ListExpression>()
->components.at(i)
->to<IR::BoolLiteral>()
->value;
out << default_action_paraList.parameters.at(i)->toString() << " ";
out << "0x" << std::hex << std::uppercase << val << " ";
} else {
BUG("Unsupported parameter type in default action in DPDK Target");
}
}
}
}
auto def = properties->getProperty("default_action");
if (def->isConstant) out << "const";
out << std::endl;
if (auto psa_implementation = properties->getProperty("psa_implementation")) {
out << "\taction_selector " << DPDK::toStr(psa_implementation->value) << std::endl;
}
if (auto size = properties->getProperty("size")) {
out << "\tsize " << DPDK::toStr(size->value) << "" << std::endl;
} else {
out << "\tsize 0x10000" << std::endl;
}
out << "}" << std::endl;
return out;
}
std::ostream &IR::DpdkSelector::toSpec(std::ostream &out) const {
out << "selector " << name << " {" << std::endl;
out << "\tgroup_id " << DPDK::toStr(group_id) << std::endl;
if (selectors) {
out << "\tselector {" << std::endl;
for (auto key : selectors->keyElements) {
out << "\t\t" << DPDK::toStr(key->expression) << std::endl;
}
out << "\t}" << std::endl;
}
out << "\tmember_id " << DPDK::toStr(member_id) << std::endl;
out << "\tn_groups_max 0x" << std::hex << std::uppercase << n_groups_max << std::endl;
out << "\tn_members_per_group_max 0x" << std::hex << std::uppercase << n_members_per_group_max
<< std::endl;
out << "}" << std::endl;
return out;
}
std::ostream &IR::DpdkLearner::toSpec(std::ostream &out) const {
out << "learner " << name << " {" << std::endl;
if (match_keys) {
out << "\tkey {" << std::endl;
for (auto key : match_keys->keyElements) {
out << "\t\t" << DPDK::toStr(key->expression) << std::endl;
}
}
out << "\t}" << std::endl;
out << "\tactions {" << std::endl;
for (auto action : actions->actionList) {
out << "\t\t" << DPDK::toStr(action->expression);
if (action->getAnnotation("tableonly"_cs)) out << " @tableonly";
if (action->getAnnotation("defaultonly"_cs)) out << " @defaultonly";
out << std::endl;
}
out << "\t}" << std::endl;
out << "\tdefault_action " << DPDK::toStr(default_action);
if (default_action->to<IR::MethodCallExpression>()->arguments->size() == 0) {
out << " args none ";
} else {
BUG("non-zero default action arguments not supported yet");
}
out << std::endl;
if (auto size = properties->getProperty("size")) {
out << "\tsize " << DPDK::toStr(size->value) << "" << std::endl;
} else {
out << "\tsize 0x" << std::hex << std::uppercase << default_learner_table_size << std::endl;
}
// The initial timeout values
// This initializes 8 timeout values which can later be configured through control plane APIs.
out << "\ttimeout {" << std::endl;
for (unsigned int i = 0; i < dpdk_learner_max_configurable_timeout_values; i++)
out << "\t\t" << std::dec << default_learner_table_timeout[i] << std::endl;
out << "\n\t\t}";
out << "\n}" << std::endl;
return out;
}
std::ostream &IR::DpdkAction::toSpec(std::ostream &out) const {
out << "action " << name.toString() << " args ";
if (para.parameters.size() == 0) out << "none ";
for (auto p : para.parameters) {
out << "instanceof " << p->type << " ";
if (p != para.parameters.back()) out << " ";
}
out << "{" << std::endl;
for (auto i : statements) {
out << "\t";
i->toSpec(out);
if (!i->to<IR::DpdkLabelStatement>()) out << std::endl;
}
out << "\treturn" << std::endl;
out << "}";
return out;
}
std::ostream &IR::DpdkChecksumAddStatement::toSpec(std::ostream &out) const {
out << "ckadd " << "h.cksum_state." << intermediate_value << " " << DPDK::toStr(field);
return out;
}
std::ostream &IR::DpdkChecksumSubStatement::toSpec(std::ostream &out) const {
out << "cksub " << "h.cksum_state." << intermediate_value << " " << DPDK::toStr(field);
return out;
}
std::ostream &IR::DpdkChecksumClearStatement::toSpec(std::ostream &out) const {
out << "mov " << "h.cksum_state." << intermediate_value << " " << "0x0";
return out;
}
std::ostream &IR::DpdkHashDeclStatement::toSpec(std::ostream &out) const {
add_comment(out, hash);
out << "rss " << hash;
return out;
}
std::ostream &IR::DpdkGetHashStatement::toSpec(std::ostream &out) const {
out << instr << " " << hash << " " << DPDK::toStr(dst) << " ";
if (auto l = fields->to<IR::ListExpression>()) {
if (l->components.size() == 1) {
out << " " << DPDK::toStr(l->components.at(0));
out << " " << DPDK::toStr(l->components.at(0));
} else {
out << " " << DPDK::toStr(l->components.at(0));
out << " " << DPDK::toStr(l->components.at(l->components.size() - 1));
}
} else {
::P4::error(ErrorType::ERR_INVALID, "%1%: get_hash's arg is not a ListExpression.", this);
}
return out;
}
std::ostream &IR::DpdkGetChecksumStatement::toSpec(std::ostream &out) const {
out << "mov " << DPDK::toStr(dst) << " " << "h.cksum_state." << intermediate_value;
return out;
}
std::ostream &IR::DpdkCastStatement::toSpec(std::ostream &out) const {
out << "mov " << DPDK::toStr(dst) << " " << DPDK::toStr(src);
return out;
}
std::ostream &IR::DpdkVerifyStatement::toSpec(std::ostream &out) const {
out << "verify " << DPDK::toStr(condition) << " " << DPDK::toStr(error);
return out;
}
std::ostream &IR::DpdkMeterDeclStatement::toSpec(std::ostream &out) const {
add_comment(out, meter);
out << "metarray " << meter << " size " << DPDK::toStr(size);
return out;
}
std::ostream &IR::DpdkMeterExecuteStatement::toSpec(std::ostream &out) const {
out << "meter " << meter << " " << DPDK::toStr(index) << " " << DPDK::toStr(length);
out << " " << DPDK::toStr(color_in) << " " << DPDK::toStr(color_out);
return out;
}
/// DPDK target uses Registers for implementing using Counters, atomic register add instruction
/// is used for incrementing the counter. Packet counters are incremented by packet length
/// specified as parameter and byte counters are incremente by 1.
std::ostream &IR::DpdkCounterCountStatement::toSpec(std::ostream &out) const {
add_comment(out, counter);
out << "regadd " << counter << " " << DPDK::toStr(index) << " ";
if (incr)
out << DPDK::toStr(incr);
else
out << "1";
return out;
}
std::ostream &IR::DpdkGetTableEntryIndex::toSpec(std::ostream &out) const {
out << "entryid " << DPDK::toStr(index) << " ";
return out;
}
std::ostream &IR::DpdkRegisterDeclStatement::toSpec(std::ostream &out) const {
add_comment(out, reg);
out << "regarray " << reg << " size " << DPDK::toStr(size) << " initval ";
if (init_val)
out << DPDK::toStr(init_val);
else
out << "0";
return out;
}
std::ostream &IR::DpdkRegisterReadStatement::toSpec(std::ostream &out) const {
out << "regrd " << DPDK::toStr(dst) << " " << reg << " " << DPDK::toStr(index);
return out;
}
std::ostream &IR::DpdkRegisterWriteStatement::toSpec(std::ostream &out) const {
out << "regwr " << reg << " " << DPDK::toStr(index) << " " << DPDK::toStr(src);
return out;
}
std::ostream &IR::DpdkValidateStatement::toSpec(std::ostream &out) const {
out << "validate " << DPDK::toStr(header);
return out;
}
std::ostream &IR::DpdkInvalidateStatement::toSpec(std::ostream &out) const {
out << "invalidate " << DPDK::toStr(header);
return out;
}
std::ostream &IR::DpdkDropStatement::toSpec(std::ostream &out) const {
out << "drop";
return out;
}
} // namespace P4