Skip to content

Commit dfc1407

Browse files
authored
Merge pull request #2868 from diffblue/smt2-uses-run
smt2_dec now uses run() instead of system()
2 parents 2c451e9 + 4694ffe commit dfc1407

File tree

2 files changed

+64
-60
lines changed

2 files changed

+64
-60
lines changed

src/solvers/smt2/smt2_dec.cpp

Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ Author: Daniel Kroening, [email protected]
1616
defined(__unix__) || \
1717
defined(__CYGWIN__) || \
1818
defined(__MACH__)
19+
// for unlink()
1920
#include <unistd.h>
2021
#endif
2122

23+
#include <util/arith_tools.h>
24+
#include <util/ieee_float.h>
25+
#include <util/run.h>
2226
#include <util/std_expr.h>
2327
#include <util/std_types.h>
2428
#include <util/tempfile.h>
25-
#include <util/arith_tools.h>
26-
#include <util/ieee_float.h>
2729

2830
#include "smt2irep.h"
2931

@@ -44,22 +46,24 @@ std::string smt2_dect::decision_procedure_text() const
4446

4547
smt2_temp_filet::smt2_temp_filet()
4648
{
47-
temp_out_filename=get_temporary_file("smt2_dec_out_", "");
49+
temp_problem_filename = get_temporary_file("smt2_dec_problem_", "");
4850

49-
temp_out.open(
50-
temp_out_filename.c_str(),
51-
std::ios_base::out | std::ios_base::trunc);
51+
temp_problem.open(
52+
temp_problem_filename.c_str(), std::ios_base::out | std::ios_base::trunc);
5253
}
5354

5455
smt2_temp_filet::~smt2_temp_filet()
5556
{
56-
temp_out.close();
57+
temp_problem.close();
5758

58-
if(temp_out_filename!="")
59-
unlink(temp_out_filename.c_str());
59+
if(!temp_problem_filename.empty())
60+
unlink(temp_problem_filename.c_str());
6061

61-
if(temp_result_filename!="")
62-
unlink(temp_result_filename.c_str());
62+
if(!temp_stdout_filename.empty())
63+
unlink(temp_stdout_filename.c_str());
64+
65+
if(!temp_stderr_filename.empty())
66+
unlink(temp_stderr_filename.c_str());
6367
}
6468

6569
decision_proceduret::resultt smt2_dect::dec_solve()
@@ -68,94 +72,94 @@ decision_proceduret::resultt smt2_dect::dec_solve()
6872
smt2_temp_filet smt2_temp_file;
6973

7074
// copy from string buffer into file
71-
smt2_temp_file.temp_out << stringstream.str();
75+
smt2_temp_file.temp_problem << stringstream.str();
7276

7377
// this finishes up and closes the SMT2 file
74-
write_footer(smt2_temp_file.temp_out);
75-
smt2_temp_file.temp_out.close();
78+
write_footer(smt2_temp_file.temp_problem);
79+
smt2_temp_file.temp_problem.close();
80+
81+
smt2_temp_file.temp_stdout_filename =
82+
get_temporary_file("smt2_dec_stdout_", "");
7683

77-
smt2_temp_file.temp_result_filename=
78-
get_temporary_file("smt2_dec_result_", "");
84+
smt2_temp_file.temp_stderr_filename =
85+
get_temporary_file("smt2_dec_stderr_", "");
7986

80-
std::string command;
87+
std::vector<std::string> argv;
88+
std::string stdin_filename;
8189

8290
switch(solver)
8391
{
8492
case solvert::BOOLECTOR:
85-
command = "boolector --smt2 "
86-
+ smt2_temp_file.temp_out_filename
87-
+ " -m > "
88-
+ smt2_temp_file.temp_result_filename;
93+
argv = {"boolector", "--smt2", smt2_temp_file.temp_problem_filename, "-m"};
8994
break;
9095

9196
case solvert::CVC3:
92-
command = "cvc3 +model -lang smtlib -output-lang smtlib "
93-
+ smt2_temp_file.temp_out_filename
94-
+ " > "
95-
+ smt2_temp_file.temp_result_filename;
97+
argv = {"cvc3",
98+
"+model",
99+
"-lang",
100+
"smtlib",
101+
"-output-lang",
102+
"smtlib",
103+
smt2_temp_file.temp_problem_filename};
96104
break;
97105

98106
case solvert::CVC4:
99107
// The flags --bitblast=eager --bv-div-zero-const help but only
100108
// work for pure bit-vector formulas.
101-
command = "cvc4 -L smt2 "
102-
+ smt2_temp_file.temp_out_filename
103-
+ " > "
104-
+ smt2_temp_file.temp_result_filename;
109+
argv = {"cvc4", "-L", "smt2", smt2_temp_file.temp_problem_filename};
105110
break;
106111

107112
case solvert::MATHSAT:
108113
// The options below were recommended by Alberto Griggio
109114
// on 10 July 2013
110-
command = "mathsat -input=smt2"
111-
" -preprocessor.toplevel_propagation=true"
112-
" -preprocessor.simplification=7"
113-
" -dpll.branching_random_frequency=0.01"
114-
" -dpll.branching_random_invalidate_phase_cache=true"
115-
" -dpll.restart_strategy=3"
116-
" -dpll.glucose_var_activity=true"
117-
" -dpll.glucose_learnt_minimization=true"
118-
" -theory.bv.eager=true"
119-
" -theory.bv.bit_blast_mode=1"
120-
" -theory.bv.delay_propagated_eqs=true"
121-
" -theory.fp.mode=1"
122-
" -theory.fp.bit_blast_mode=2"
123-
" -theory.arr.mode=1"
124-
" < "+smt2_temp_file.temp_out_filename
125-
+ " > "+smt2_temp_file.temp_result_filename;
115+
116+
argv = {"mathsat",
117+
"-input=smt2",
118+
"-preprocessor.toplevel_propagation=true",
119+
"-preprocessor.simplification=7",
120+
"-dpll.branching_random_frequency=0.01",
121+
"-dpll.branching_random_invalidate_phase_cache=true",
122+
"-dpll.restart_strategy=3",
123+
"-dpll.glucose_var_activity=true",
124+
"-dpll.glucose_learnt_minimization=true",
125+
"-theory.bv.eager=true",
126+
"-theory.bv.bit_blast_mode=1",
127+
"-theory.bv.delay_propagated_eqs=true",
128+
"-theory.fp.mode=1",
129+
"-theory.fp.bit_blast_mode=2",
130+
"-theory.arr.mode=1"};
131+
132+
stdin_filename = smt2_temp_file.temp_problem_filename;
126133
break;
127134

128135
case solvert::YICES:
129136
// command = "yices -smt -e " // Calling convention for older versions
130-
command = "yices-smt2 " // Calling for 2.2.1
131-
+ smt2_temp_file.temp_out_filename
132-
+ " > "
133-
+ smt2_temp_file.temp_result_filename;
137+
// Convention for 2.2.1
138+
argv = {"yices-smt2", smt2_temp_file.temp_problem_filename};
134139
break;
135140

136141
case solvert::Z3:
137-
command = "z3 -smt2 "
138-
+ smt2_temp_file.temp_out_filename
139-
+ " > "
140-
+ smt2_temp_file.temp_result_filename;
142+
argv = {"z3", "-smt2", smt2_temp_file.temp_problem_filename};
141143
break;
142144

143145
default:
144146
assert(false);
145147
}
146148

147-
#if defined(__linux__) || defined(__APPLE__)
148-
command+=" 2>&1";
149-
#endif
149+
int res = run(
150+
argv[0],
151+
argv,
152+
stdin_filename,
153+
smt2_temp_file.temp_stdout_filename,
154+
smt2_temp_file.temp_stderr_filename);
150155

151-
int res=system(command.c_str());
152156
if(res<0)
153157
{
154158
error() << "error running SMT2 solver" << eom;
155159
return decision_proceduret::resultt::D_ERROR;
156160
}
157161

158-
std::ifstream in(smt2_temp_file.temp_result_filename.c_str());
162+
std::ifstream in(smt2_temp_file.temp_stdout_filename);
159163

160164
return read_result(in);
161165
}

src/solvers/smt2/smt2_dec.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class smt2_temp_filet
2020
smt2_temp_filet();
2121
~smt2_temp_filet();
2222

23-
std::ofstream temp_out;
24-
std::string temp_out_filename, temp_result_filename;
23+
std::ofstream temp_problem;
24+
std::string temp_problem_filename, temp_stdout_filename, temp_stderr_filename;
2525
};
2626

2727
class smt2_stringstreamt

0 commit comments

Comments
 (0)