CBMC
solver_factory.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Solver Factory
4 
5 Author: Daniel Kroening, Peter Schrammel
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_GOTO_CHECKER_SOLVER_FACTORY_H
13 #define CPROVER_GOTO_CHECKER_SOLVER_FACTORY_H
14 
15 #include <solvers/prop/prop.h>
16 #include <solvers/smt2/smt2_dec.h>
17 
18 #include <memory>
19 
20 class cmdlinet;
21 class message_handlert;
22 class namespacet;
23 class optionst;
25 
26 class solver_factoryt final
27 {
28 public:
31  const optionst &_options,
32  const namespacet &_ns,
33  message_handlert &_message_handler,
34  bool _output_xml_in_refinement);
35 
36  // The solver class,
37  // which owns a variety of allocated objects.
38  class solvert final
39  {
40  public:
41  explicit solvert(std::unique_ptr<decision_proceduret> p);
42  solvert(std::unique_ptr<decision_proceduret> p1, std::unique_ptr<propt> p2);
43  solvert(
44  std::unique_ptr<decision_proceduret> p1,
45  std::unique_ptr<std::ofstream> p2);
46 
49 
50  void set_decision_procedure(std::unique_ptr<decision_proceduret> p);
51  void set_prop(std::unique_ptr<propt> p);
52  void set_ofstream(std::unique_ptr<std::ofstream> p);
53 
54  // the objects are deleted in the opposite order they appear below
55  std::unique_ptr<std::ofstream> ofstream_ptr;
56  std::unique_ptr<propt> prop_ptr;
57  std::unique_ptr<decision_proceduret> decision_procedure_ptr;
58  };
59 
61  virtual std::unique_ptr<solvert> get_solver();
62 
63  virtual ~solver_factoryt() = default;
64 
65 protected:
66  const optionst &options;
67  const namespacet &ns;
70 
71  std::unique_ptr<solvert> get_default();
72  std::unique_ptr<solvert> get_dimacs();
73  std::unique_ptr<solvert> get_external_sat();
74  std::unique_ptr<solvert> get_bv_refinement();
75  std::unique_ptr<solvert> get_string_refinement();
76  std::unique_ptr<solvert> get_incremental_smt2(std::string solver_command);
77  std::unique_ptr<solvert> get_smt2(smt2_dect::solvert solver);
78 
80 
84  void
86 
87  // consistency checks during solver creation
88  void no_beautification();
89  void no_incremental_check();
90 };
91 
94 void parse_solver_options(const cmdlinet &cmdline, optionst &options);
95 
96 #define OPT_SOLVER \
97  "(smt1)" /* rejected, will eventually disappear */ \
98  "(smt2)" \
99  "(fpa)" \
100  "(cvc3)" \
101  "(cvc4)(cvc5)(bitwuzla)(boolector)(yices)(z3)" \
102  "(mathsat)" \
103  "(cprover-smt2)" \
104  "(incremental-smt2-solver):" \
105  "(sat-solver):" \
106  "(external-sat-solver):" \
107  "(no-sat-preprocessor)" \
108  "(beautify)" \
109  "(dimacs)" \
110  "(refine)" \
111  "(max-node-refinement):" \
112  "(refine-arrays)" \
113  "(refine-arithmetic)" \
114  "(outfile):" \
115  "(dump-smt-formula):" \
116  "(write-solver-stats-to):"
117 
118 #define HELP_SOLVER \
119  " {y--sat-solver} {usolver} \t use specified SAT solver\n" \
120  " {y--external-sat-solver} {ucmd} \t command to invoke SAT solver process\n" \
121  " {y--no-sat-preprocessor} \t disable the SAT solver's simplifier\n" \
122  " {y--dimacs} \t generate CNF in DIMACS format\n" \
123  " {y--beautify} \t beautify the counterexample (greedy heuristic)\n" \
124  " {y--smt1} \t use default SMT1 solver (obsolete)\n" \
125  " {y--smt2} \t use default SMT2 solver (Z3)\n" \
126  " {y--bitwuzla} \t use Bitwuzla\n" \
127  " {y--boolector} \t use Boolector\n" \
128  " {y--cprover-smt2} \t use CPROVER SMT2 solver\n" \
129  " {y--cvc3} \t use CVC3\n" \
130  " {y--cvc4} \t use CVC4\n" \
131  " {y--cvc5} \t use CVC5\n" \
132  " {y--mathsat} \t use MathSAT\n" \
133  " {y--yices} \t use Yices\n" \
134  " {y--z3} \t use Z3\n" \
135  " {y--fpa} \t use theory of floating-point arithmetic\n" \
136  " {y--refine} \t use refinement procedure (experimental)\n" \
137  " {y--refine-arrays} \t use refinement for arrays only\n" \
138  " {y--refine-arithmetic} \t refinement of arithmetic expressions only\n" \
139  " {y--max-node-refinement} \t " \
140  "maximum refinement iterations for arithmetic expressions\n" \
141  " {y--incremental-smt2-solver} {ucmd} \t " \
142  "command to invoke external SMT solver for incremental solving " \
143  "(experimental)\n" \
144  " {y--outfile} {ufilename} \t output formula to given file\n" \
145  " {y--dump-smt-formula} {ufilename} \t " \
146  "output smt incremental formula to the given file\n" \
147  " {y--write-solver-stats-to} {ujson-file} \t " \
148  "collect the solver query complexity\n"
149 
150 #endif // CPROVER_GOTO_CHECKER_SOLVER_FACTORY_H
An interface for a decision procedure for satisfiability problems.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
std::unique_ptr< propt > prop_ptr
std::unique_ptr< decision_proceduret > decision_procedure_ptr
solvert(std::unique_ptr< decision_proceduret > p)
void set_decision_procedure(std::unique_ptr< decision_proceduret > p)
std::unique_ptr< std::ofstream > ofstream_ptr
decision_proceduret & decision_procedure() const
stack_decision_proceduret & stack_decision_procedure() const
void set_ofstream(std::unique_ptr< std::ofstream > p)
void set_prop(std::unique_ptr< propt > p)
message_handlert & message_handler
const optionst & options
const namespacet & ns
std::unique_ptr< solvert > get_external_sat()
std::unique_ptr< solvert > get_default()
solver_factoryt(const optionst &_options, const namespacet &_ns, message_handlert &_message_handler, bool _output_xml_in_refinement)
Note: The solver returned will hold a reference to the namespace ns.
std::unique_ptr< solvert > get_dimacs()
void set_decision_procedure_time_limit(decision_proceduret &decision_procedure)
Sets the timeout of decision_procedure if the solver-time-limit option has a positive value (in secon...
std::unique_ptr< solvert > get_string_refinement()
the string refinement adds to the bit vector refinement specifications for functions from the Java st...
std::unique_ptr< solvert > get_smt2(smt2_dect::solvert solver)
const bool output_xml_in_refinement
smt2_dect::solvert get_smt2_solver_type() const
Uses the options to pick an SMT 2.0 solver.
virtual ~solver_factoryt()=default
virtual std::unique_ptr< solvert > get_solver()
Returns a solvert object.
std::unique_ptr< solvert > get_incremental_smt2(std::string solver_command)
std::unique_ptr< solvert > get_bv_refinement()
void solver(std::vector< framet > &frames, const std::unordered_set< symbol_exprt, irep_hash > &address_taken, const solver_optionst &solver_options, const namespacet &ns, std::vector< propertyt > &properties, std::size_t property_index)
Definition: solver.cpp:44
void parse_solver_options(const cmdlinet &cmdline, optionst &options)
Parse solver-related command-line parameters in cmdline and set corresponding values in options.