39 static std::map<cstring, funcType> *cvtForType;
42 bool replaceNextWithLast;
44 : structure(structure), p4lib(P4::P4CoreLibrary::instance()), replaceNextWithLast(
false) {
45 setName(
"ExpressionConverter");
47 const IR::Type *getFieldType(
const IR::Type_StructLike *ht,
cstring fieldName);
48 const IR::Node *postorder(IR::Constant *expression)
override;
49 const IR::Node *postorder(IR::Member *field)
override;
50 const IR::Node *postorder(IR::FieldList *fl)
override;
51 const IR::Node *postorder(IR::Mask *expression)
override;
52 const IR::Node *postorder(IR::ActionArg *arg)
override;
53 const IR::Node *postorder(IR::Primitive *primitive)
override;
54 const IR::Node *postorder(IR::PathExpression *ref)
override;
55 const IR::Node *postorder(IR::ConcreteHeaderRef *nhr)
override;
56 const IR::Node *postorder(IR::HeaderStackItemRef *ref)
override;
57 const IR::Node *postorder(IR::GlobalRef *gr)
override;
58 const IR::Node *postorder(IR::Equ *equ)
override;
59 const IR::Node *postorder(IR::Neq *neq)
override;
60 const IR::Expression *convert(
const IR::Node *node) {
61 auto result = node->apply(*
this);
62 return result->
to<IR::Expression>();
64 static void addConverter(
cstring type, funcType);
65 static funcType get(
cstring type);
97class ExternConverter {
98 static std::map<cstring, ExternConverter *> *cvtForType;
101 virtual const IR::Type_Extern *convertExternType(
ProgramStructure *,
const IR::Type_Extern *,
103 virtual const IR::Declaration_Instance *convertExternInstance(
107 const IR::Declaration_Instance *,
108 const IR::Primitive *);
109 virtual bool convertAsGlobal(
ProgramStructure *,
const IR::Declaration_Instance *) {
113 virtual ~ExternConverter() =
default;
118 static ExternConverter *get(
cstring type);
119 static ExternConverter *get(
const IR::Type_Extern *type) {
return get(type->name); }
120 static ExternConverter *get(
const IR::Declaration_Instance *ext) {
121 return get(ext->type->to<IR::Type_Extern>());
123 static const IR::Type_Extern *cvtExternType(
ProgramStructure *s,
const IR::Type_Extern *e,
125 return get(e)->convertExternType(s, e, name);
127 static const IR::Declaration_Instance *cvtExternInstance(
130 return get(di)->convertExternInstance(s, di, name, scope);
133 const IR::Declaration_Instance *di,
134 const IR::Primitive *p) {
135 return get(di)->convertExternCall(s, di, p);
137 static bool cvtAsGlobal(
ProgramStructure *s,
const IR::Declaration_Instance *di) {
138 return get(di)->convertAsGlobal(s, di);
183 std::map<cstring, cstring> reserved_names = {{
"standard_metadata_t"_cs,
"type"_cs},
184 {
"standard_metadata"_cs,
"metadata"_cs},
185 {
"egress"_cs,
"control"_cs}};
188 auto it = reserved_names.find(nodeName);
189 if (it == reserved_names.end())
return;
190 if (it->second != kind)
191 ::P4::error(ErrorType::ERR_INVALID,
"%1%: invalid name; it can only be used for %2%",
195 checkReserved(node, nodeName,
nullptr);
199 explicit DiscoverStructure(
ProgramStructure *structure) : structure(structure) {
200 CHECK_NULL(structure);
201 setName(
"DiscoverStructure");
204 void postorder(
const IR::ParserException *ex)
override {
205 warn(ErrorType::WARN_UNSUPPORTED,
"%1%: parser exception is not translated to P4-16", ex);
207 void postorder(
const IR::Metadata *md)
override {
208 structure->metadata.emplace(md);
209 checkReserved(md, md->name,
"metadata"_cs);
211 void postorder(
const IR::Header *hd)
override {
212 structure->headers.emplace(hd);
213 checkReserved(hd, hd->name);
215 void postorder(
const IR::Type_StructLike *t)
override {
216 structure->types.emplace(t);
217 checkReserved(t, t->name,
"type"_cs);
219 void postorder(
const IR::V1Control *control)
override {
220 structure->controls.emplace(control);
221 checkReserved(control, control->name,
"control"_cs);
223 void postorder(
const IR::V1Parser *parser)
override {
224 structure->parserStates.emplace(parser);
225 checkReserved(parser, parser->name);
227 void postorder(
const IR::V1Table *table)
override {
228 structure->tables.emplace(table);
229 checkReserved(table, table->name);
231 void postorder(
const IR::ActionFunction *action)
override {
232 structure->actions.emplace(action);
233 checkReserved(action, action->name);
235 void postorder(
const IR::HeaderStack *stack)
override {
236 structure->stacks.emplace(stack);
237 checkReserved(stack, stack->name);
239 void postorder(
const IR::Counter *count)
override {
240 structure->counters.emplace(count);
241 checkReserved(count, count->name);
243 void postorder(
const IR::Register *reg)
override {
244 structure->registers.emplace(reg);
245 checkReserved(reg, reg->name);
247 void postorder(
const IR::ActionProfile *ap)
override {
248 structure->action_profiles.emplace(ap);
249 checkReserved(ap, ap->name);
251 void postorder(
const IR::FieldList *fl)
override {
252 structure->field_lists.emplace(fl);
253 checkReserved(fl, fl->name);
255 void postorder(
const IR::FieldListCalculation *flc)
override {
256 structure->field_list_calculations.emplace(flc);
257 checkReserved(flc, flc->name);
259 void postorder(
const IR::CalculatedField *cf)
override {
260 structure->calculated_fields.push_back(cf);
262 void postorder(
const IR::Meter *m)
override {
263 structure->meters.emplace(m);
264 checkReserved(m, m->name);
266 void postorder(
const IR::ActionSelector *as)
override {
267 structure->action_selectors.emplace(as);
268 checkReserved(as, as->name);
270 void postorder(
const IR::Type_Extern *ext)
override {
271 structure->extern_types.emplace(ext);
272 checkReserved(ext, ext->name);
274 void postorder(
const IR::Declaration_Instance *ext)
override {
275 structure->externs.emplace(ext);
276 checkReserved(ext, ext->name);
278 void postorder(
const IR::ParserValueSet *pvs)
override {
279 structure->value_sets.emplace(pvs);
280 checkReserved(pvs, pvs->name);
288 explicit ComputeCallGraph(
ProgramStructure *structure) : structure(structure) {
289 CHECK_NULL(structure);
290 setName(
"ComputeCallGraph");
293 void postorder(
const IR::V1Parser *parser)
override {
294 LOG3(
"Scanning parser " << parser->name);
295 structure->parsers.add(parser->name);
296 if (!parser->default_return.name.isNullOrEmpty())
297 structure->parsers.calls(parser->name, parser->default_return);
298 if (parser->cases !=
nullptr)
299 for (
auto ce : *parser->cases) structure->parsers.calls(parser->name, ce->action.name);
300 for (
auto expr : parser->stmts) {
301 if (expr->is<IR::Primitive>()) {
302 auto primitive = expr->to<IR::Primitive>();
303 if (primitive->name ==
"extract") {
304 BUG_CHECK(primitive->operands.size() == 1,
"Expected 1 operand for %1%",
306 auto dest = primitive->operands.at(0);
307 LOG3(
"Parser " << parser->name <<
" extracts into " << dest);
308 structure->extracts[parser->name].push_back(dest);
313 void postorder(
const IR::Primitive *primitive)
override {
314 auto name = primitive->name;
315 const IR::GlobalRef *glob =
nullptr;
316 const IR::Declaration_Instance *extrn =
nullptr;
317 if (!primitive->operands.empty()) glob = primitive->operands[0]->to<IR::GlobalRef>();
318 if (glob) extrn = glob->obj->to<IR::Declaration_Instance>();
321 auto parent = findContext<IR::ActionFunction>();
322 BUG_CHECK(parent !=
nullptr,
"%1%: Extern call not within action", primitive);
323 structure->calledExterns.calls(parent->name, extrn->name.name);
325 }
else if (primitive->name ==
"count") {
327 auto ctrref = primitive->operands.at(0);
328 const IR::Counter *ctr =
nullptr;
329 if (
auto gr = ctrref->to<IR::GlobalRef>())
330 ctr = gr->obj->to<IR::Counter>();
331 else if (
auto nr = ctrref->to<IR::PathExpression>())
332 ctr = structure->counters.get(nr->path->name);
333 if (ctr ==
nullptr) {
334 ::P4::error(ErrorType::ERR_NOT_FOUND,
"%1%: Cannot find counter", ctrref);
337 auto parent = findContext<IR::ActionFunction>();
338 BUG_CHECK(parent !=
nullptr,
"%1%: Counter call not within action", primitive);
339 structure->calledCounters.calls(parent->name, ctr->name.name);
341 }
else if (primitive->name ==
"execute_meter") {
342 auto mtrref = primitive->operands.at(0);
343 const IR::Meter *mtr =
nullptr;
344 if (
auto gr = mtrref->to<IR::GlobalRef>())
345 mtr = gr->obj->to<IR::Meter>();
346 else if (
auto nr = mtrref->to<IR::PathExpression>())
347 mtr = structure->meters.get(nr->path->name);
348 if (mtr ==
nullptr) {
349 ::P4::error(ErrorType::ERR_NOT_FOUND,
"%1%: Cannot find meter", mtrref);
352 auto parent = findContext<IR::ActionFunction>();
353 BUG_CHECK(parent !=
nullptr,
"%1%: not within action", primitive);
354 structure->calledMeters.calls(parent->name, mtr->name.name);
356 }
else if (primitive->name ==
"register_read" || primitive->name ==
"register_write") {
357 const IR::Expression *regref;
358 if (primitive->name ==
"register_read")
359 regref = primitive->operands.at(1);
361 regref = primitive->operands.at(0);
362 const IR::Register *reg =
nullptr;
363 if (
auto gr = regref->to<IR::GlobalRef>())
364 reg = gr->obj->to<IR::Register>();
365 else if (
auto nr = regref->to<IR::PathExpression>())
366 reg = structure->registers.get(nr->path->name);
367 if (reg ==
nullptr) {
368 ::P4::error(ErrorType::ERR_NOT_FOUND,
"%1%: Cannot find register", regref);
371 auto parent = findContext<IR::ActionFunction>();
372 BUG_CHECK(parent !=
nullptr,
"%1%: not within action", primitive);
373 structure->calledRegisters.calls(parent->name, reg->name.name);
375 }
else if (structure->actions.contains(name)) {
376 auto parent = findContext<IR::ActionFunction>();
377 BUG_CHECK(parent !=
nullptr,
"%1%: Action call not within action", primitive);
378 structure->calledActions.calls(parent->name, name);
379 }
else if (structure->controls.contains(name)) {
380 auto parent = findContext<IR::V1Control>();
381 BUG_CHECK(parent !=
nullptr,
"%1%: Control call not within control", primitive);
382 structure->calledControls.calls(parent->name, name);
385 void postorder(
const IR::GlobalRef *gref)
override {
387 if (
auto af = findContext<IR::ActionFunction>()) {
389 }
else if (
auto di = findContext<IR::Declaration_Instance>()) {
392 BUG(
"%1%: GlobalRef not within action or extern", gref);
394 if (
auto ctr = gref->obj->to<IR::Counter>())
395 structure->calledCounters.calls(caller, ctr->name.name);
396 else if (
auto mtr = gref->obj->to<IR::Meter>())
397 structure->calledMeters.calls(caller, mtr->name.name);
398 else if (
auto reg = gref->obj->to<IR::Register>())
399 structure->calledRegisters.calls(caller, reg->name.name);
400 else if (
auto ext = gref->obj->to<IR::Declaration_Instance>())
401 structure->calledExterns.calls(caller, ext->name.name);
412 explicit ComputeTableCallGraph(
ProgramStructure *structure) : structure(structure) {
413 CHECK_NULL(structure);
414 setName(
"ComputeTableCallGraph");
417 void postorder(
const IR::Apply *apply)
override {
418 LOG3(
"Scanning " << apply->name);
419 auto tbl = structure->tables.get(apply->name.name);
420 if (tbl ==
nullptr) {
421 ::P4::error(ErrorType::ERR_NOT_FOUND,
"%1%: Could not find table", apply->name);
424 auto parent = findContext<IR::V1Control>();
426 ::P4::error(ErrorType::ERR_UNEXPECTED,
"%1%: Apply not within a control block?", apply);
430 auto ctrl = get(structure->tableMapping, tbl);
433 if (!structure->calledControls.isCallee(parent->name) &&
434 parent->name != P4V1::V1Model::instance.ingress.name &&
435 parent->name != P4V1::V1Model::instance.egress.name)
438 if (ctrl !=
nullptr && ctrl != parent) {
439 auto previous = get(structure->tableInvocation, tbl);
441 "%1%: Table invoked from two different controls: %2% and %3%", tbl, apply,
444 LOG3(
"Invoking " << tbl <<
" in " << parent->name);
445 structure->tableMapping.emplace(tbl, parent);
446 structure->tableInvocation.emplace(tbl, apply);
514 const IR::Type_Header *fixedHeaderType;
516 const IR::Expression *headerLength;
526 std::map<cstring, HeaderSplit *> fixedPart;
531 HeaderSplit *splitHeaderType(
const IR::Type_Header *type) {
533 auto fixed = ::P4::get(fixedPart, type->name.name);
534 if (fixed !=
nullptr)
return fixed;
536 const IR::Expression *headerLength =
nullptr;
538 const IR::Type_Header *fixedHeaderType =
nullptr;
541 for (
auto f : type->fields) {
542 if (f->type->is<IR::Type_Varbits>()) {
543 cstring hname = structure->makeUniqueName(type->name.name);
544 if (fixedHeaderType !=
nullptr) {
546 "%1%: header types with multiple varbit fields are not supported",
550 fixedHeaderType =
new IR::Type_Header(
IR::ID(hname), fields);
552 auto anno = f->getAnnotation(IR::Annotation::lengthAnnotation);
553 BUG_CHECK(anno !=
nullptr,
"No length annotation on varbit field", f);
554 BUG_CHECK(anno->getExpr().size() == 1,
"Expected exactly 1 argument",
556 headerLength = anno->getExpr(0);
559 }
else if (fixedHeaderType ==
nullptr) {
564 if (fixedHeaderType !=
nullptr) {
565 LOG3(
"Extracted fixed-size header type from " << type <<
" into " << fixedHeaderType);
566 fixed =
new HeaderSplit;
567 fixed->fixedHeaderType = fixedHeaderType;
568 fixed->headerLength = headerLength;
569 fixedPart.emplace(type->name.name, fixed);
570 allTypeDecls.push_back(fixedHeaderType);
583 class RewriteLength final :
public Transform {
584 const IR::Type_Header *header;
585 const IR::Declaration *var;
588 explicit RewriteLength(
const IR::Type_Header *header,
const IR::Declaration *var)
589 : header(header), var(var) {
590 setName(
"RewriteLength");
593 const IR::Node *postorder(IR::PathExpression *expression)
override {
594 if (expression->path->absolute)
return expression;
595 for (
auto f : header->fields) {
596 if (f->name == expression->path->name)
597 return new IR::Member(expression->srcInfo,
new IR::PathExpression(var->name),
606 CHECK_NULL(structure);
607 setName(
"FixExtracts");
610 const IR::Node *postorder(IR::P4Program *program)
override {
613 allTypeDecls.append(program->objects);
614 program->objects = allTypeDecls;
618 const IR::Node *postorder(IR::P4Parser *parser)
override {
619 if (!varDecls.empty()) {
620 parser->parserLocals.append(varDecls);
626 const IR::Node *postorder(IR::MethodCallStatement *statement)
override {
627 auto mce = getOriginal<IR::MethodCallStatement>()->methodCall;
628 LOG3(
"Looking up in extracts " << dbp(mce));
629 auto ht = ::P4::get(structure->extractsSynthesized, mce);
635 BUG_CHECK(mce->arguments->size() == 1,
"%1%: expected 1 argument", mce);
636 auto arg = mce->arguments->at(0);
638 auto fixed = splitHeaderType(ht);
639 if (fixed ==
nullptr)
return statement;
640 CHECK_NULL(fixed->headerLength);
641 CHECK_NULL(fixed->fixedHeaderType);
644 cstring varName = structure->makeUniqueName(
"tmp_hdr"_cs);
646 new IR::Declaration_Variable(
IR::ID(varName), fixed->fixedHeaderType->to<IR::Type>());
647 varDecls.push_back(var);
650 auto member = mce->method->to<IR::Member>();
653 typeArgs->push_back(fixed->fixedHeaderType->getP4Type());
654 auto lookaheadMethod =
655 new IR::Member(member->expr, P4::P4CoreLibrary::instance().packetIn.lookahead.name);
656 auto lookahead =
new IR::MethodCallExpression(mce->srcInfo, lookaheadMethod, typeArgs,
659 new IR::AssignmentStatement(mce->srcInfo,
new IR::PathExpression(varName), lookahead);
660 result->push_back(assign);
661 LOG3(
"Created lookahead " << assign);
664 RewriteLength rewrite(fixed->fixedHeaderType, var);
665 rewrite.setCalledBy(
this);
666 auto length = fixed->headerLength->apply(rewrite);
668 args->push_back(arg->clone());
669 auto type = IR::Type_Bits::get(P4::P4CoreLibrary::instance().packetIn.extractSecondArgSize);
671 args->push_back(
new IR::Argument(cast));
672 auto expression =
new IR::MethodCallExpression(mce->srcInfo, mce->method->clone(), args);
673 result->push_back(
new IR::MethodCallStatement(expression));
737 DetectDuplicates() { setName(
"DetectDuplicates"); }
739 bool preorder(
const IR::V1Program *program)
override {
740 auto &map = program->scope;
741 auto firstWithKey = map.begin();
742 while (firstWithKey != map.end()) {
743 auto key = firstWithKey->first;
744 auto range = map.equal_range(key);
745 for (
auto s = range.first; s != range.second; s++) {
747 for (n++; n != range.second; n++) {
750 if (e1->node_type_name() == e2->node_type_name()) {
751 if (e1->srcInfo.getStart().isValid())
752 ::P4::error(ErrorType::ERR_DUPLICATE,
"%1%: same name as %2%", e1, e2);
756 "%1% is invalid; name %2% is reserved", e2, key);
760 firstWithKey = range.second;
791class InsertCompilerGeneratedStartState :
public Transform {
800 explicit InsertCompilerGeneratedStartState(
ProgramStructure *structure) : structure(structure) {
801 setName(
"InsertCompilerGeneratedStartState");
802 structure->allNames.insert({IR::ParserState::start, 0});
803 structure->allNames.insert({
"InstanceType"_cs, 0});
804 newStartState = structure->makeUniqueName(IR::ParserState::start);
805 newInstanceType = structure->makeUniqueName(
"InstanceType"_cs);
808 const IR::Node *postorder(IR::P4Program *program)
override {
809 allTypeDecls.append(program->objects);
810 program->objects = allTypeDecls;
815 const IR::Node *postorder(IR::ParserState *state)
override {
816 if (structure->parserEntryPoints.empty())
return state;
817 if (state->name == IR::ParserState::start) {
818 state->name = newStartState;
824 const IR::Node *postorder(IR::Path *path)
override {
825 if (structure->parserEntryPoints.empty())
return path;
829 if (path->name.name != IR::ParserState::start)
return path;
831 auto pe = getContext()->node->
to<IR::PathExpression>();
832 auto sc = findContext<IR::SelectCase>();
833 auto ps = findContext<IR::ParserState>();
835 if (pe && ((sc && pe->equiv(*sc->state->to<IR::PathExpression>())) ||
837 (ps && pe->equiv(*ps->selectExpression->to<IR::PathExpression>()))))
838 path->name = newStartState;
842 const IR::Node *postorder(IR::P4Parser *parser)
override {
843 if (structure->parserEntryPoints.empty())
return parser;
846 members.push_back(
new IR::SerEnumMember(
"START",
new IR::Constant(0)));
847 selCases.push_back(
new IR::SelectCase(
848 new IR::Member(
new IR::TypeNameExpression(
new IR::Type_Name(newInstanceType)),
850 new IR::PathExpression(
new IR::Path(newStartState))));
854 for (
auto p : structure->parserEntryPoints) {
855 members.push_back(
new IR::SerEnumMember(p.first,
new IR::Constant(idx++)));
856 selCases.push_back(
new IR::SelectCase(
857 new IR::Member(
new IR::TypeNameExpression(
new IR::Type_Name(newInstanceType)),
859 new IR::PathExpression(
new IR::Path(p.second->name))));
861 auto instEnum =
new IR::Type_SerEnum(
863 {
new IR::Annotation(IR::Annotation::nameAnnotation,
".$InstanceType"_cs)},
864 IR::Type_Bits::get(32), members);
865 allTypeDecls.push_back(instEnum);
868 selExpr.push_back(
new IR::Cast(
869 new IR::Type_Name(newInstanceType),
870 new IR::Member(
new IR::PathExpression(
new IR::Path(
"standard_metadata"_cs)),
871 "instance_type"_cs)));
872 auto selects =
new IR::SelectExpression(
new IR::ListExpression(selExpr), selCases);
873 auto startState =
new IR::ParserState(
874 IR::ParserState::start,
875 {
new IR::Annotation(IR::Annotation::nameAnnotation,
".$start"_cs)}, selects);
876 parserStates.push_back(startState);
878 if (!parserStates.empty()) {
879 parser->states.append(parserStates);
880 parserStates.clear();
908 const IR::Type_Struct *stdType =
nullptr;
909 const IR::Type_Struct *userType =
nullptr;
910 const IR::Type_Struct *intrType =
nullptr;
911 const IR::Type_Struct *queueType =
nullptr;
912 const IR::StructField *intrField =
nullptr;
913 const IR::StructField *queueField =
nullptr;
916 explicit MoveIntrinsicMetadata(
ProgramStructure *structure) : structure(structure) {
917 CHECK_NULL(structure);
918 setName(
"MoveIntrinsicMetadata");
920 const IR::Node *preorder(IR::P4Program *program)
override {
921 stdType = program->getDeclsByName(structure->v1model.standardMetadataType.name)
923 ->
to<IR::Type_Struct>();
924 userType = program->getDeclsByName(structure->v1model.metadataType.name)
926 ->to<IR::Type_Struct>();
928 CHECK_NULL(userType);
929 intrField = userType->getField(structure->v1model.intrinsicMetadata.name);
930 if (intrField !=
nullptr) {
931 auto intrTypeName = intrField->type;
932 auto tn = intrTypeName->to<IR::Type_Name>();
933 BUG_CHECK(tn,
"%1%: expected a Type_Name", intrTypeName);
934 auto nt = program->getDeclsByName(tn->path->name)->nextOrDefault();
935 if (nt ==
nullptr || !nt->is<IR::Type_Struct>()) {
936 ::P4::error(ErrorType::ERR_INVALID,
"%1%: expected a structure", tn);
939 intrType = nt->to<IR::Type_Struct>();
940 LOG2(
"Intrinsic metadata type " << intrType);
943 queueField = userType->getField(structure->v1model.queueingMetadata.name);
944 if (queueField !=
nullptr) {
945 auto queueTypeName = queueField->type;
946 auto tn = queueTypeName->to<IR::Type_Name>();
947 BUG_CHECK(tn,
"%1%: expected a Type_Name", queueTypeName);
948 auto nt = program->getDeclsByName(tn->path->name)->nextOrDefault();
949 if (nt ==
nullptr || !nt->is<IR::Type_Struct>()) {
950 ::P4::error(ErrorType::ERR_INVALID,
"%1%: expected a structure", tn);
953 queueType = nt->to<IR::Type_Struct>();
954 LOG2(
"Queueing metadata type " << queueType);
959 const IR::Node *postorder(IR::Type_Struct *type)
override {
960 if (getOriginal() == stdType) {
961 if (intrType !=
nullptr) {
962 for (
auto f : intrType->fields) {
963 if (type->fields.getDeclaration(f->name) ==
nullptr) {
965 "%1%: no such field in standard_metadata", f->name);
966 LOG2(
"standard_metadata: " << type);
970 if (queueType !=
nullptr) {
971 for (
auto f : queueType->fields) {
972 if (type->fields.getDeclaration(f->name) ==
nullptr) {
974 "%1%: no such field in standard_metadata", f->name);
975 LOG2(
"standard_metadata: " << type);
983 const IR::Node *postorder(IR::StructField *field)
override {
984 if (getOriginal() == intrField || getOriginal() == queueField)
990 const IR::Node *postorder(IR::Member *member)
override {
994 if (member->member != structure->v1model.intrinsicMetadata.name &&
995 member->member != structure->v1model.queueingMetadata.name)
997 auto pe = member->expr->
to<IR::PathExpression>();
998 if (pe ==
nullptr || pe->path->absolute)
return member;
999 if (pe->path->name == structure->v1model.parser.metadataParam.name) {
1000 LOG2(
"Renaming reference " << member);
1001 return new IR::PathExpression(
new IR::Path(
1002 member->expr->srcInfo,
1003 IR::ID(pe->path->name.srcInfo, structure->v1model.standardMetadata.name)));
1014 void add(
const IR::Primitive *primitive,
unsigned operand) {
1015 if (primitive->operands.size() <= operand) {
1020 auto expression = primitive->operands.at(operand);
1021 if (!expression->is<IR::PathExpression>()) {
1022 ::P4::error(ErrorType::ERR_EXPECTED,
"%1%: expected a field list", expression);
1025 auto nr = expression->to<IR::PathExpression>();
1026 auto fl = structure->field_lists.get(nr->path->name);
1027 if (fl ==
nullptr) {
1028 ::P4::error(ErrorType::ERR_EXPECTED,
"%1%: Expected a field list", expression);
1031 LOG3(
"Recirculated " << nr->path->name);
1032 structure->allFieldLists.emplace(fl);
1036 explicit FindRecirculated(
ProgramStructure *structure) : structure(structure) {
1037 CHECK_NULL(structure);
1038 setName(
"FindRecirculated");
1041 void postorder(
const IR::Primitive *primitive)
override {
1042 if (primitive->name ==
"recirculate" || primitive->name ==
"resubmit") {
1044 }
else if (primitive->name.startsWith(
"clone") && primitive->operands.size() == 2) {
Definition frontends/p4-14/fromv1.0/programStructure.h:32