16
16
defined(__unix__) || \
17
17
defined(__CYGWIN__) || \
18
18
defined(__MACH__)
19
+ // for unlink()
19
20
#include < unistd.h>
20
21
#endif
21
22
23
+ #include < util/arith_tools.h>
24
+ #include < util/ieee_float.h>
25
+ #include < util/run.h>
22
26
#include < util/std_expr.h>
23
27
#include < util/std_types.h>
24
28
#include < util/tempfile.h>
25
- #include < util/arith_tools.h>
26
- #include < util/ieee_float.h>
27
29
28
30
#include " smt2irep.h"
29
31
@@ -44,22 +46,24 @@ std::string smt2_dect::decision_procedure_text() const
44
46
45
47
smt2_temp_filet::smt2_temp_filet ()
46
48
{
47
- temp_out_filename= get_temporary_file (" smt2_dec_out_ " , " " );
49
+ temp_problem_filename = get_temporary_file (" smt2_dec_problem_ " , " " );
48
50
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);
52
53
}
53
54
54
55
smt2_temp_filet::~smt2_temp_filet ()
55
56
{
56
- temp_out .close ();
57
+ temp_problem .close ();
57
58
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 ());
60
61
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 ());
63
67
}
64
68
65
69
decision_proceduret::resultt smt2_dect::dec_solve ()
@@ -68,94 +72,94 @@ decision_proceduret::resultt smt2_dect::dec_solve()
68
72
smt2_temp_filet smt2_temp_file;
69
73
70
74
// copy from string buffer into file
71
- smt2_temp_file.temp_out << stringstream.str ();
75
+ smt2_temp_file.temp_problem << stringstream.str ();
72
76
73
77
// 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_" , " " );
76
83
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_ " , " " );
79
86
80
- std::string command;
87
+ std::vector<std::string> argv;
88
+ std::string stdin_filename;
81
89
82
90
switch (solver)
83
91
{
84
92
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" };
89
94
break ;
90
95
91
96
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 };
96
104
break ;
97
105
98
106
case solvert::CVC4:
99
107
// The flags --bitblast=eager --bv-div-zero-const help but only
100
108
// 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 };
105
110
break ;
106
111
107
112
case solvert::MATHSAT:
108
113
// The options below were recommended by Alberto Griggio
109
114
// 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 ;
126
133
break ;
127
134
128
135
case solvert::YICES:
129
136
// 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 };
134
139
break ;
135
140
136
141
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 };
141
143
break ;
142
144
143
145
default :
144
146
assert (false );
145
147
}
146
148
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 );
150
155
151
- int res=system (command.c_str ());
152
156
if (res<0 )
153
157
{
154
158
error () << " error running SMT2 solver" << eom;
155
159
return decision_proceduret::resultt::D_ERROR;
156
160
}
157
161
158
- std::ifstream in (smt2_temp_file.temp_result_filename . c_str () );
162
+ std::ifstream in (smt2_temp_file.temp_stdout_filename );
159
163
160
164
return read_result (in);
161
165
}
0 commit comments