Skip to content

Commit a506981

Browse files
author
Enrico Steffinlongo
committed
Log SMT formula to file for new incremental solver
1 parent d3b72f2 commit a506981

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

src/goto-checker/solver_factory.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ std::unique_ptr<solver_factoryt::solvert> solver_factoryt::get_solver()
148148
const auto incremental_smt2_solver =
149149
options.get_option("incremental-smt2-solver");
150150
if(!incremental_smt2_solver.empty())
151-
return get_incremental_smt2(incremental_smt2_solver);
151+
{
152+
const auto out_filename = options.get_option("outfile");
153+
return get_incremental_smt2(incremental_smt2_solver, out_filename);
154+
}
152155
if(options.get_bool_option("smt2"))
153156
return get_smt2(get_smt2_solver_type());
154157
return get_default();
@@ -329,12 +332,30 @@ solver_factoryt::get_string_refinement()
329332
std::move(decision_procedure), std::move(prop));
330333
}
331334

332-
std::unique_ptr<solver_factoryt::solvert>
333-
solver_factoryt::get_incremental_smt2(std::string solver_command)
335+
std::unique_ptr<solver_factoryt::solvert> solver_factoryt::get_incremental_smt2(
336+
std::string solver_command,
337+
std::string outfile)
334338
{
335339
no_beautification();
340+
341+
std::unique_ptr<std::ofstream> out = nullptr;
342+
if(!outfile.empty())
343+
{
344+
#ifdef _MSC_VER
345+
out = util_make_unique<std::ofstream>(widen(outfile));
346+
#else
347+
out = util_make_unique<std::ofstream>(outfile);
348+
#endif
349+
350+
if(!*out)
351+
{
352+
throw invalid_command_line_argument_exceptiont(
353+
"failed to open file: " + outfile, "--outfile");
354+
}
355+
}
356+
336357
auto solver_process = util_make_unique<smt_piped_solver_processt>(
337-
std::move(solver_command), message_handler);
358+
std::move(solver_command), message_handler, std::move(out));
338359

339360
return util_make_unique<solvert>(
340361
util_make_unique<smt2_incremental_decision_proceduret>(

src/goto-checker/solver_factory.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ class solver_factoryt final
7676
std::unique_ptr<solvert> get_external_sat();
7777
std::unique_ptr<solvert> get_bv_refinement();
7878
std::unique_ptr<solvert> get_string_refinement();
79-
std::unique_ptr<solvert> get_incremental_smt2(std::string solver_command);
79+
std::unique_ptr<solvert>
80+
get_incremental_smt2(std::string solver_command, std::string outfile);
8081
std::unique_ptr<solvert> get_smt2(smt2_dect::solvert solver);
8182

8283
smt2_dect::solvert get_smt2_solver_type() const;

src/solvers/smt2_incremental/smt_solver_process.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
smt_piped_solver_processt::smt_piped_solver_processt(
1313
std::string command_line,
14-
message_handlert &message_handler)
14+
message_handlert &message_handler,
15+
std::unique_ptr<std::ostream> out_stream)
1516
: command_line_description{"\"" + command_line + "\""},
17+
out_stream(std::move(out_stream)),
1618
process{split_string(command_line, ' ', false, true), message_handler},
1719
log{message_handler}
1820
{
@@ -28,6 +30,15 @@ void smt_piped_solver_processt::send(const smt_commandt &smt_command)
2830
const std::string command_string = smt_to_smt2_string(smt_command);
2931
log.debug() << "Sending command to SMT2 solver - " << command_string
3032
<< messaget::eom;
33+
34+
if(out_stream != nullptr)
35+
{
36+
// Using std::endl to flush the stream as it is a debugging functionality,
37+
// and we can guarantee a consistent output in case of hanging after
38+
// (check-sat)
39+
*out_stream << command_string << std::endl;
40+
}
41+
3142
const auto response = process.send(command_string + "\n");
3243
switch(response)
3344
{

src/solvers/smt2_incremental/smt_solver_process.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
class smt_commandt;
77

8-
#include <solvers/smt2_incremental/smt_responses.h>
98
#include <util/message.h>
109
#include <util/piped_process.h>
1110

11+
#include <solvers/smt2_incremental/smt_responses.h>
12+
13+
#include <memory>
1214
#include <sstream>
1315
#include <string>
1416

@@ -35,9 +37,12 @@ class smt_piped_solver_processt : public smt_base_solver_processt
3537
/// The command and arguments for invoking the smt2 solver.
3638
/// \param message_handler:
3739
/// The messaging system to be used for logging purposes.
40+
/// \param out_stream:
41+
/// Pointer to the stream to print the SMT formula. `nullptr` if no output.
3842
smt_piped_solver_processt(
3943
std::string command_line,
40-
message_handlert &message_handler);
44+
message_handlert &message_handler,
45+
std::unique_ptr<std::ostream> out_stream);
4146

4247
const std::string &description() override;
4348

@@ -52,6 +57,8 @@ class smt_piped_solver_processt : public smt_base_solver_processt
5257
protected:
5358
/// The command line used to start the process.
5459
std::string command_line_description;
60+
/// Pointer to the stream to print the SMT formula. `nullptr` if no output.
61+
std::unique_ptr<std::ostream> out_stream;
5562
/// The raw solver sub process.
5663
piped_processt process;
5764
/// For buffering / combining communications from the solver to cbmc.

0 commit comments

Comments
 (0)