Skip to content

Commit f703650

Browse files
author
Daniel Kroening
committed
smt2_dect now uses temporary_filet
1 parent 4694ffe commit f703650

File tree

2 files changed

+19
-72
lines changed

2 files changed

+19
-72
lines changed

src/solvers/smt2/smt2_dec.cpp

Lines changed: 19 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,6 @@ Author: Daniel Kroening, [email protected]
88

99
#include "smt2_dec.h"
1010

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-
2311
#include <util/arith_tools.h>
2412
#include <util/ieee_float.h>
2513
#include <util/run.h>
@@ -44,53 +32,27 @@ std::string smt2_dect::decision_procedure_text() const
4432
"(unknown)");
4533
}
4634

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-
6935
decision_proceduret::resultt smt2_dect::dec_solve()
7036
{
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_", "");
8040

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+
}
8648

8749
std::vector<std::string> argv;
8850
std::string stdin_filename;
8951

9052
switch(solver)
9153
{
9254
case solvert::BOOLECTOR:
93-
argv = {"boolector", "--smt2", smt2_temp_file.temp_problem_filename, "-m"};
55+
argv = {"boolector", "--smt2", temp_file_problem(), "-m"};
9456
break;
9557

9658
case solvert::CVC3:
@@ -100,13 +62,13 @@ decision_proceduret::resultt smt2_dect::dec_solve()
10062
"smtlib",
10163
"-output-lang",
10264
"smtlib",
103-
smt2_temp_file.temp_problem_filename};
65+
temp_file_problem()};
10466
break;
10567

10668
case solvert::CVC4:
10769
// The flags --bitblast=eager --bv-div-zero-const help but only
10870
// 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()};
11072
break;
11173

11274
case solvert::MATHSAT:
@@ -129,38 +91,33 @@ decision_proceduret::resultt smt2_dect::dec_solve()
12991
"-theory.fp.bit_blast_mode=2",
13092
"-theory.arr.mode=1"};
13193

132-
stdin_filename = smt2_temp_file.temp_problem_filename;
94+
stdin_filename = temp_file_problem();
13395
break;
13496

13597
case solvert::YICES:
13698
// command = "yices -smt -e " // Calling convention for older versions
13799
// Convention for 2.2.1
138-
argv = {"yices-smt2", smt2_temp_file.temp_problem_filename};
100+
argv = {"yices-smt2", temp_file_problem()};
139101
break;
140102

141103
case solvert::Z3:
142-
argv = {"z3", "-smt2", smt2_temp_file.temp_problem_filename};
104+
argv = {"z3", "-smt2", temp_file_problem()};
143105
break;
144106

145107
default:
146108
assert(false);
147109
}
148110

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());
155113

156114
if(res<0)
157115
{
158116
error() << "error running SMT2 solver" << eom;
159117
return decision_proceduret::resultt::D_ERROR;
160118
}
161119

162-
std::ifstream in(smt2_temp_file.temp_stdout_filename);
163-
120+
std::ifstream in(temp_file_stdout());
164121
return read_result(in);
165122
}
166123

src/solvers/smt2/smt2_dec.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include "smt2_conv.h"
1616

17-
class smt2_temp_filet
18-
{
19-
public:
20-
smt2_temp_filet();
21-
~smt2_temp_filet();
22-
23-
std::ofstream temp_problem;
24-
std::string temp_problem_filename, temp_stdout_filename, temp_stderr_filename;
25-
};
26-
2717
class smt2_stringstreamt
2818
{
2919
protected:

0 commit comments

Comments
 (0)