@@ -54,12 +54,11 @@ void generateTDIBfrtJson(bool isTDI, const IR::P4Program *program, DPDK::DpdkOpt
5454
5555 std::filesystem::path filename = isTDI ? options.tdiFile : options.bfRtSchema ;
5656 auto p4rt = new P4::BFRT::BFRuntimeSchemaGenerator (*p4Runtime.p4Info , isTDI, options);
57- std::ostream *out = openFile (filename, false );
58- if (!out) {
57+ if (auto out = openFile (filename, false )) {
58+ p4rt->serializeBFRuntimeSchema (out.get ());
59+ } else {
5960 ::P4::error (ErrorType::ERR_IO, " Could not open file: %1%" , filename);
60- return ;
6161 }
62- p4rt->serializeBFRuntimeSchema (out);
6362}
6463
6564int main (int argc, char *const argv[]) {
@@ -134,8 +133,10 @@ int main(int argc, char *const argv[]) {
134133 toplevel = midEnd.process (program);
135134 if (::P4::errorCount () > 1 || toplevel == nullptr || toplevel->getMain () == nullptr )
136135 return 1 ;
137- if (!options.dumpJsonFile .empty ())
138- JSONGenerator (*openFile (options.dumpJsonFile , true ), true ).emit (program);
136+ if (!options.dumpJsonFile .empty ()) {
137+ auto dumpJsonStream = openFile (options.dumpJsonFile , true );
138+ JSONGenerator (*dumpJsonStream, true ).emit (program);
139+ }
139140 } catch (const std::exception &bug) {
140141 std::cerr << bug.what () << std::endl;
141142 return 1 ;
@@ -148,8 +149,7 @@ int main(int argc, char *const argv[]) {
148149 if (::P4::errorCount () > 0 ) return 1 ;
149150
150151 if (!options.outputFile .empty ()) {
151- std::ostream *out = openFile (options.outputFile , false );
152- if (out != nullptr ) {
152+ if (auto out = openFile (options.outputFile , false )) {
153153 backend->codegen (*out);
154154 out->flush ();
155155 }
0 commit comments