forked from dslab-epfl/cloud9-boolector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
btorpreco.cc
178 lines (157 loc) · 3.47 KB
/
btorpreco.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* Boolector: Satisfiablity Modulo Theories (SMT) solver.
* Copyright (C) 2010 Robert Daniel Brummayer, Armin Biere
*
* This file is part of Boolector.
*
* Boolector is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Boolector is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef BTOR_USE_PRECOSAT
#include "../precosat/precosat.hh"
#include "../precosat/precobnr.hh"
extern "C" {
#include "btorpreco.h"
using namespace PrecoSat;
static Solver solver;
static bool initialized;
static void * emgr;
static void * (*new_for_precosat) (void*, size_t);
static void (*delete_for_precosat) (void*, void *, size_t);
static void *(*resize_for_precosat) (void*, void *, size_t, size_t);
static int added_original_clauses;
static int
btor_precosat_lsbsign_lit (int lit)
{
return 2 * abs (lit) + (lit < 0);
}
const char *
btor_precosat_version (void)
{
return precosat_version ();
}
void
btor_precosat_init (void)
{
if (initialized) solver.reset ();
assert (emgr);
assert (new_for_precosat);
assert (delete_for_precosat);
assert (resize_for_precosat);
solver.set (emgr,
new_for_precosat, delete_for_precosat, resize_for_precosat);
solver.init ();
solver.fxopts ();
initialized = true;
}
int
btor_precosat_add (int lit)
{
int res;
res = added_original_clauses;
solver.add (btor_precosat_lsbsign_lit (lit));
if (!lit)
added_original_clauses++;
return res;
}
int
btor_precosat_sat (int limit)
{
int res;
res = solver.solve (limit < 0 ? INT_MAX : limit);
if (res < 0)
res = 20;
else if (res > 0)
res = 10;
else
assert (!res);
return res;
}
int
btor_precosat_deref (int lit)
{
return solver.val (btor_precosat_lsbsign_lit (lit));
}
void
btor_precosat_reset (void)
{
emgr = 0;
new_for_precosat = 0;
delete_for_precosat = 0;
resize_for_precosat = 0;
added_original_clauses = 0;
solver.reset ();
initialized = false;
}
void
btor_precosat_set_output (FILE * file)
{
solver.set (file);
}
void
btor_precosat_set_prefix (const char * newprfx)
{
solver.setprfx (newprfx);
}
void
btor_precosat_enable_verbosity (void)
{
bool res;
res = solver.set ("verbose", 1);
assert (res);
}
int
btor_precosat_inc_max_var (void)
{
return solver.next ();
}
int
btor_precosat_variables (void)
{
return solver.getMaxVar ();
}
int
btor_precosat_added_original_clauses (void)
{
return added_original_clauses;
}
void
btor_precosat_set_new (void * e, void *(n)(void *, size_t))
{
assert (!emgr || emgr == e);
assert (!new_for_precosat);
emgr = e;
new_for_precosat = n;
}
void
btor_precosat_set_delete (void * e, void (d)(void *, void *, size_t))
{
assert (!emgr || emgr == e);
assert (!delete_for_precosat);
emgr = e;
delete_for_precosat = d;
}
void
btor_precosat_set_resize (void * e, void *(r)(void *, void *, size_t, size_t))
{
assert (!emgr || emgr == e);
assert (!resize_for_precosat);
emgr = e;
resize_for_precosat = r;
}
void
btor_precosat_stats (void)
{
solver.prstats ();
}
};
#endif