@@ -331,7 +331,8 @@ solver_factoryt::get_string_refinement()
331
331
332
332
std::unique_ptr<std::ofstream> open_outfile_and_check (
333
333
const std::string &filename,
334
- message_handlert &message_handler)
334
+ message_handlert &message_handler,
335
+ const std::string &arg_name)
335
336
{
336
337
if (filename.empty ())
337
338
return nullptr ;
@@ -345,7 +346,7 @@ std::unique_ptr<std::ofstream> open_outfile_and_check(
345
346
if (!*out)
346
347
{
347
348
throw invalid_command_line_argument_exceptiont (
348
- " failed to open file: " + filename, " --outfile " );
349
+ " failed to open file: " + filename, arg_name );
349
350
}
350
351
351
352
messaget log (message_handler);
@@ -360,22 +361,38 @@ solver_factoryt::get_incremental_smt2(std::string solver_command)
360
361
no_beautification ();
361
362
362
363
const std::string outfile_arg = options.get_option (" outfile" );
364
+ const std::string dump_smt_formula = options.get_option (" dump-smt-formula" );
365
+
366
+ if (!outfile_arg.empty () && !dump_smt_formula.empty ())
367
+ {
368
+ throw invalid_command_line_argument_exceptiont (
369
+ " Argument --outfile is incompatible with --dump-smt-formula. " ,
370
+ " --outfile" );
371
+ }
363
372
364
373
std::unique_ptr<smt_base_solver_processt> solver_process = nullptr ;
365
374
366
375
if (!outfile_arg.empty ())
367
376
{
368
377
bool on_std_out = outfile_arg == " -" ;
369
378
std::unique_ptr<std::ostream> outfile =
370
- on_std_out ? nullptr
371
- : open_outfile_and_check (outfile_arg, message_handler);
379
+ on_std_out
380
+ ? nullptr
381
+ : open_outfile_and_check (outfile_arg, message_handler, " --outfile" );
372
382
solver_process = util_make_unique<smt_incremental_dry_run_solvert>(
373
383
message_handler, on_std_out ? std::cout : *outfile, std::move (outfile));
374
384
}
375
385
else
376
386
{
387
+ const auto out_filename = options.get_option (" dump-smt-formula" );
388
+
389
+ // If no out_filename is provided `open_outfile_and_check` will return
390
+ // `nullptr`, and the solver will work normally without any logging.
377
391
solver_process = util_make_unique<smt_piped_solver_processt>(
378
- std::move (solver_command), message_handler);
392
+ std::move (solver_command),
393
+ message_handler,
394
+ open_outfile_and_check (
395
+ out_filename, message_handler, " --dump-smt-formula" ));
379
396
}
380
397
381
398
return util_make_unique<solvert>(
@@ -432,7 +449,7 @@ solver_factoryt::get_smt2(smt2_dect::solvert solver)
432
449
}
433
450
else
434
451
{
435
- auto out = open_outfile_and_check (filename, message_handler);
452
+ auto out = open_outfile_and_check (filename, message_handler, " --outfile " );
436
453
437
454
auto smt2_conv = util_make_unique<smt2_convt>(
438
455
ns,
@@ -574,6 +591,10 @@ void parse_solver_options(const cmdlinet &cmdline, optionst &options)
574
591
if (cmdline.isset (" outfile" ))
575
592
options.set_option (" outfile" , cmdline.get_value (" outfile" ));
576
593
594
+ if (cmdline.isset (" dump-smt-formula" ))
595
+ options.set_option (
596
+ " dump-smt-formula" , cmdline.get_value (" dump-smt-formula" ));
597
+
577
598
if (cmdline.isset (" write-solver-stats-to" ))
578
599
{
579
600
options.set_option (
0 commit comments