@@ -152,8 +152,9 @@ bool ToP4::preorder(const IR::P4Program *program) {
152152 for (auto a : program->objects ) {
153153 // Check where this declaration originates
154154 auto sourceFileOpt = ifSystemFile (a);
155- // Errors can come from multiple files
156- if (!a->is <IR ::Type_Error>() && sourceFileOpt.has_value ()) {
155+ // Errors and match_kinds can come from multiple files
156+ if (!a->is <IR ::Type_Error>() && !a->is <IR ::Declaration_MatchKind>() &&
157+ sourceFileOpt.has_value ()) {
157158 /* FIXME -- when including a user header file (sourceFile !=
158159 * mainFile), do we want to emit an #include of it or not? Probably
159160 * not when translating from P4-14, as that would create a P4-16
@@ -692,10 +693,19 @@ bool ToP4::preorder(const IR::Type_Error *d) {
692693
693694bool ToP4::preorder (const IR ::Declaration_MatchKind *d) {
694695 dump (1 );
696+
697+ const auto userMatchKinds = d->getDeclarations ()
698+ ->where ([this ](const IR ::IDeclaration *e) {
699+ // only print if not from a system file
700+ return !ifSystemFile (e->getNode ()).has_value ();
701+ })
702+ ->toVector ();
703+ if (userMatchKinds.empty ()) return false ;
704+
695705 builder.append (" match_kind " );
696706 builder.blockStart ();
697707 bool first = true ;
698- for (auto a : *d-> getDeclarations () ) {
708+ for (auto a : userMatchKinds ) {
699709 if (!first) builder.append (" ,\n " );
700710 dump (1 , a->getNode (), 1 );
701711 first = false ;
0 commit comments