@@ -268,7 +268,8 @@ static LogicalResult doVerifyRoundTrip(Operation *op,
268
268
llvm::raw_string_ostream ostream (buffer);
269
269
if (useBytecode) {
270
270
if (failed (writeBytecodeToFile (op, ostream))) {
271
- op->emitOpError () << " failed to write bytecode, cannot verify round-trip.\n " ;
271
+ op->emitOpError ()
272
+ << " failed to write bytecode, cannot verify round-trip.\n " ;
272
273
return failure ();
273
274
}
274
275
} else {
@@ -281,7 +282,8 @@ static LogicalResult doVerifyRoundTrip(Operation *op,
281
282
roundtripModule =
282
283
parseSourceString<Operation *>(ostream.str (), parseConfig);
283
284
if (!roundtripModule) {
284
- op->emitOpError () << " failed to parse bytecode back, cannot verify round-trip.\n " ;
285
+ op->emitOpError ()
286
+ << " failed to parse bytecode back, cannot verify round-trip.\n " ;
285
287
return failure ();
286
288
}
287
289
}
@@ -300,7 +302,8 @@ static LogicalResult doVerifyRoundTrip(Operation *op,
300
302
}
301
303
if (reference != roundtrip) {
302
304
// TODO implement a diff.
303
- return op->emitOpError () << " roundTrip testing roundtripped module differs from reference:\n <<<<<<Reference\n "
305
+ return op->emitOpError () << " roundTrip testing roundtripped module differs "
306
+ " from reference:\n <<<<<<Reference\n "
304
307
<< reference << " \n =====\n "
305
308
<< roundtrip << " \n >>>>>roundtripped\n " ;
306
309
}
@@ -443,6 +446,36 @@ static LogicalResult processBuffer(raw_ostream &os,
443
446
return sourceMgrHandler.verify ();
444
447
}
445
448
449
+ std::pair<std::string, std::string>
450
+ mlir::registerAndParseCLIOptions (int argc, char **argv,
451
+ llvm::StringRef toolName,
452
+ DialectRegistry ®istry) {
453
+ static cl::opt<std::string> inputFilename (
454
+ cl::Positional, cl::desc (" <input file>" ), cl::init (" -" ));
455
+
456
+ static cl::opt<std::string> outputFilename (" o" , cl::desc (" Output filename" ),
457
+ cl::value_desc (" filename" ),
458
+ cl::init (" -" ));
459
+ // Register any command line options.
460
+ MlirOptMainConfig::registerCLOptions (registry);
461
+ registerAsmPrinterCLOptions ();
462
+ registerMLIRContextCLOptions ();
463
+ registerPassManagerCLOptions ();
464
+ registerDefaultTimingManagerCLOptions ();
465
+ tracing::DebugCounter::registerCLOptions ();
466
+
467
+ // Build the list of dialects as a header for the --help message.
468
+ std::string helpHeader = (toolName + " \n Available Dialects: " ).str ();
469
+ {
470
+ llvm::raw_string_ostream os (helpHeader);
471
+ interleaveComma (registry.getDialectNames (), os,
472
+ [&](auto name) { os << name; });
473
+ }
474
+ // Parse pass names in main to ensure static initialization completed.
475
+ cl::ParseCommandLineOptions (argc, argv, helpHeader);
476
+ return std::make_pair (inputFilename.getValue (), outputFilename.getValue ());
477
+ }
478
+
446
479
LogicalResult mlir::MlirOptMain (llvm::raw_ostream &outputStream,
447
480
std::unique_ptr<llvm::MemoryBuffer> buffer,
448
481
DialectRegistry ®istry,
@@ -477,34 +510,13 @@ LogicalResult mlir::MlirOptMain(llvm::raw_ostream &outputStream,
477
510
/* insertMarkerInOutput=*/ true );
478
511
}
479
512
480
- LogicalResult mlir::MlirOptMain (int argc, char **argv, llvm::StringRef toolName,
513
+ LogicalResult mlir::MlirOptMain (int argc, char **argv,
514
+ llvm::StringRef inputFilename,
515
+ llvm::StringRef outputFilename,
481
516
DialectRegistry ®istry) {
482
- static cl::opt<std::string> inputFilename (
483
- cl::Positional, cl::desc (" <input file>" ), cl::init (" -" ));
484
-
485
- static cl::opt<std::string> outputFilename (" o" , cl::desc (" Output filename" ),
486
- cl::value_desc (" filename" ),
487
- cl::init (" -" ));
488
517
489
518
InitLLVM y (argc, argv);
490
519
491
- // Register any command line options.
492
- MlirOptMainConfig::registerCLOptions (registry);
493
- registerAsmPrinterCLOptions ();
494
- registerMLIRContextCLOptions ();
495
- registerPassManagerCLOptions ();
496
- registerDefaultTimingManagerCLOptions ();
497
- tracing::DebugCounter::registerCLOptions ();
498
-
499
- // Build the list of dialects as a header for the --help message.
500
- std::string helpHeader = (toolName + " \n Available Dialects: " ).str ();
501
- {
502
- llvm::raw_string_ostream os (helpHeader);
503
- interleaveComma (registry.getDialectNames (), os,
504
- [&](auto name) { os << name; });
505
- }
506
- // Parse pass names in main to ensure static initialization completed.
507
- cl::ParseCommandLineOptions (argc, argv, helpHeader);
508
520
MlirOptMainConfig config = MlirOptMainConfig::createFromCLOptions ();
509
521
510
522
// When reading from stdin and the input is a tty, it is often a user mistake
@@ -535,3 +547,14 @@ LogicalResult mlir::MlirOptMain(int argc, char **argv, llvm::StringRef toolName,
535
547
output->keep ();
536
548
return success ();
537
549
}
550
+
551
+ LogicalResult mlir::MlirOptMain (int argc, char **argv, llvm::StringRef toolName,
552
+ DialectRegistry ®istry) {
553
+
554
+ // Register and parse command line options.
555
+ std::string inputFilename, outputFilename;
556
+ std::tie (inputFilename, outputFilename) =
557
+ registerAndParseCLIOptions (argc, argv, toolName, registry);
558
+
559
+ return MlirOptMain (argc, argv, inputFilename, outputFilename, registry);
560
+ }
0 commit comments