8
8
9
9
#include " smt2_dec.h"
10
10
11
- #include < cstdlib>
12
-
13
- #if defined(__linux__) || \
14
- defined (__FreeBSD_kernel__) || \
15
- defined(__GNU__) || \
16
- defined(__unix__) || \
17
- defined(__CYGWIN__) || \
18
- defined(__MACH__)
19
- // for unlink()
20
- #include < unistd.h>
21
- #endif
22
-
23
11
#include < util/arith_tools.h>
24
12
#include < util/ieee_float.h>
25
13
#include < util/run.h>
@@ -44,53 +32,27 @@ std::string smt2_dect::decision_procedure_text() const
44
32
" (unknown)" );
45
33
}
46
34
47
- smt2_temp_filet::smt2_temp_filet ()
48
- {
49
- temp_problem_filename = get_temporary_file (" smt2_dec_problem_" , " " );
50
-
51
- temp_problem.open (
52
- temp_problem_filename.c_str (), std::ios_base::out | std::ios_base::trunc);
53
- }
54
-
55
- smt2_temp_filet::~smt2_temp_filet ()
56
- {
57
- temp_problem.close ();
58
-
59
- if (!temp_problem_filename.empty ())
60
- unlink (temp_problem_filename.c_str ());
61
-
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 ());
67
- }
68
-
69
35
decision_proceduret::resultt smt2_dect::dec_solve ()
70
36
{
71
- // we write the problem into a file
72
- smt2_temp_filet smt2_temp_file;
73
-
74
- // copy from string buffer into file
75
- smt2_temp_file.temp_problem << stringstream.str ();
76
-
77
- // this finishes up and closes the SMT2 file
78
- write_footer (smt2_temp_file.temp_problem );
79
- smt2_temp_file.temp_problem .close ();
37
+ temporary_filet temp_file_problem (" smt2_dec_problem_" , " " ),
38
+ temp_file_stdout (" smt2_dec_stdout_" , " " ),
39
+ temp_file_stderr (" smt2_dec_stderr_" , " " );
80
40
81
- smt2_temp_file.temp_stdout_filename =
82
- get_temporary_file (" smt2_dec_stdout_" , " " );
83
-
84
- smt2_temp_file.temp_stderr_filename =
85
- get_temporary_file (" smt2_dec_stderr_" , " " );
41
+ {
42
+ // we write the problem into a file
43
+ std::ofstream problem_out (
44
+ temp_file_problem (), std::ios_base::out | std::ios_base::trunc);
45
+ problem_out << stringstream.str ();
46
+ write_footer (problem_out);
47
+ }
86
48
87
49
std::vector<std::string> argv;
88
50
std::string stdin_filename;
89
51
90
52
switch (solver)
91
53
{
92
54
case solvert::BOOLECTOR:
93
- argv = {" boolector" , " --smt2" , smt2_temp_file. temp_problem_filename , " -m" };
55
+ argv = {" boolector" , " --smt2" , temp_file_problem () , " -m" };
94
56
break ;
95
57
96
58
case solvert::CVC3:
@@ -100,13 +62,13 @@ decision_proceduret::resultt smt2_dect::dec_solve()
100
62
" smtlib" ,
101
63
" -output-lang" ,
102
64
" smtlib" ,
103
- smt2_temp_file. temp_problem_filename };
65
+ temp_file_problem () };
104
66
break ;
105
67
106
68
case solvert::CVC4:
107
69
// The flags --bitblast=eager --bv-div-zero-const help but only
108
70
// work for pure bit-vector formulas.
109
- argv = {" cvc4" , " -L" , " smt2" , smt2_temp_file. temp_problem_filename };
71
+ argv = {" cvc4" , " -L" , " smt2" , temp_file_problem () };
110
72
break ;
111
73
112
74
case solvert::MATHSAT:
@@ -129,38 +91,33 @@ decision_proceduret::resultt smt2_dect::dec_solve()
129
91
" -theory.fp.bit_blast_mode=2" ,
130
92
" -theory.arr.mode=1" };
131
93
132
- stdin_filename = smt2_temp_file. temp_problem_filename ;
94
+ stdin_filename = temp_file_problem () ;
133
95
break ;
134
96
135
97
case solvert::YICES:
136
98
// command = "yices -smt -e " // Calling convention for older versions
137
99
// Convention for 2.2.1
138
- argv = {" yices-smt2" , smt2_temp_file. temp_problem_filename };
100
+ argv = {" yices-smt2" , temp_file_problem () };
139
101
break ;
140
102
141
103
case solvert::Z3:
142
- argv = {" z3" , " -smt2" , smt2_temp_file. temp_problem_filename };
104
+ argv = {" z3" , " -smt2" , temp_file_problem () };
143
105
break ;
144
106
145
107
default :
146
108
assert (false );
147
109
}
148
110
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 );
111
+ int res =
112
+ run (argv[0 ], argv, stdin_filename, temp_file_stdout (), temp_file_stderr ());
155
113
156
114
if (res<0 )
157
115
{
158
116
error () << " error running SMT2 solver" << eom;
159
117
return decision_proceduret::resultt::D_ERROR;
160
118
}
161
119
162
- std::ifstream in (smt2_temp_file.temp_stdout_filename );
163
-
120
+ std::ifstream in (temp_file_stdout ());
164
121
return read_result (in);
165
122
}
166
123
0 commit comments