Skip to content

Commit f438391

Browse files
author
Daniel Kroening
committed
an SMT2 solver using boolbv and satcheckt
1 parent 000c9d2 commit f438391

File tree

3 files changed

+111
-5
lines changed

3 files changed

+111
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ src/goto-instrument/goto-instrument.exe
104104
src/jbmc/jbmc
105105
src/musketeer/musketeer
106106
src/musketeer/musketeer.exe
107+
src/solvers/smt2/smt2_solver
107108
src/symex/symex
108109
src/symex/symex.exe
109110
src/goto-diff/goto-diff

src/solvers/Makefile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ INCLUDES += -I .. \
213213
$(SMVSAT_INCLUDE) $(SQUOLEM2_INC) $(CUDD_INCLUDE) $(GLUCOSE_INCLUDE) \
214214
$(PRECOSAT_INCLUDE) $(PICOSAT_INCLUDE) $(LINGELING_INCLUDE)
215215

216-
CLEANFILES = solvers$(LIBEXT)
216+
CLEANFILES = solvers$(LIBEXT) smt2_solver$(EXEEXT)
217217

218-
all: solvers$(LIBEXT)
218+
all: solvers$(LIBEXT) smt2_solver$(EXEEXT)
219219

220220
ifneq ($(SQUOLEM2),)
221221
CP_CXXFLAGS += -DHAVE_QBF_CORE
@@ -229,9 +229,15 @@ endif
229229

230230
-include $(SRC:.cpp=.d)
231231

232-
###############################################################################
233-
234-
solvers$(LIBEXT): $(OBJ) $(CHAFF_LIB) $(BOOLEFORCE_LIB) $(MINISAT_LIB) \
232+
SOLVER_LIB = $(CHAFF_LIB) $(BOOLEFORCE_LIB) $(MINISAT_LIB) \
235233
$(MINISAT2_LIB) $(SMVSAT_LIB) $(SQUOLEM2_LIB) $(CUDD_LIB) \
236234
$(PRECOSAT_LIB) $(PICOSAT_LIB) $(LINGELING_LIB) $(GLUCOSE_LIB)
235+
236+
###############################################################################
237+
238+
solvers$(LIBEXT): $(OBJ) $(SOLVER_LIB)
237239
$(LINKLIB) $(LIBSOLVER)
240+
241+
smt2_solver$(EXEEXT): $(OBJ) smt2/smt2_solver$(OBJEXT) \
242+
../util/util$(LIBEXT) ../big-int/big-int$(LIBEXT) $(SOLVER_LIB)
243+
$(LINKBIN) $(LIBSOLVER)

src/solvers/smt2/smt2_solver.cpp

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*******************************************************************\
2+
3+
Module: SMT2 Solver that uses boolbv and the default SAT solver
4+
5+
Author: Daniel Kroening, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#include <fstream>
10+
#include <iostream>
11+
12+
#include "smt2_parser.h"
13+
14+
#include <util/namespace.h>
15+
#include <util/symbol_table.h>
16+
#include <util/cout_message.h>
17+
#include <solvers/sat/satcheck.h>
18+
#include <solvers/flattening/boolbv.h>
19+
20+
class smt2_solvert:public smt2_parsert
21+
{
22+
public:
23+
smt2_solvert(
24+
std::ifstream &_in,
25+
decision_proceduret &_solver):
26+
smt2_parsert(_in),
27+
solver(_solver)
28+
{
29+
}
30+
31+
protected:
32+
decision_proceduret &solver;
33+
34+
void command(const std::string &) override;
35+
};
36+
37+
void smt2_solvert::command(const std::string &c)
38+
{
39+
if(c=="assert")
40+
{
41+
exprt e=expression();
42+
solver.set_to_true(e);
43+
}
44+
else if(c=="check-sat")
45+
{
46+
switch(solver())
47+
{
48+
case decision_proceduret::resultt::D_SATISFIABLE:
49+
std::cout << "(sat)\n";
50+
break;
51+
52+
case decision_proceduret::resultt::D_UNSATISFIABLE:
53+
std::cout << "(unsat)\n";
54+
break;
55+
56+
case decision_proceduret::resultt::D_ERROR:
57+
std::cout << "(error)\n";
58+
}
59+
}
60+
else
61+
smt2_parsert::command(c);
62+
}
63+
64+
int main(int argc, const char *argv[])
65+
{
66+
if(argc!=2)
67+
return 1;
68+
69+
std::ifstream in(argv[1]);
70+
if(!in)
71+
{
72+
std::cerr << "failed to open " << argv[1] << '\n';
73+
return 1;
74+
}
75+
76+
symbol_tablet symbol_table;
77+
namespacet ns(symbol_table);
78+
79+
console_message_handlert message_handler;
80+
messaget message(message_handler);
81+
82+
// this is our default verbosity
83+
message_handler.set_verbosity(messaget::M_STATISTICS);
84+
85+
satcheckt satcheck;
86+
boolbvt boolbv(ns, satcheck);
87+
satcheck.set_message_handler(message_handler);
88+
boolbv.set_message_handler(message_handler);
89+
90+
smt2_solvert smt2_solver(in, boolbv);
91+
smt2_solver.set_message_handler(message_handler);
92+
93+
smt2_solver.parse();
94+
95+
if(!smt2_solver)
96+
return 20;
97+
else
98+
return 0;
99+
}

0 commit comments

Comments
 (0)