klee
SolverCmdLine.cpp
Go to the documentation of this file.
1//===-- CmdLineOptions.cpp --------------------------------------*- C++ -*-===//
2//
3// The KLEE Symbolic Virtual Machine
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10/*
11 * This file groups command line options definitions and associated
12 * data that are common to both KLEE and Kleaver.
13 */
14
16
17#include "klee/Config/Version.h"
19
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/StringMap.h"
22#include "llvm/Support/CommandLine.h"
23
24using namespace llvm;
25
26namespace klee {
27
28cl::extrahelp TimeFormatInfo(
29 "\nTime format used by KLEE's options\n"
30 "\n"
31 " Time spans can be specified in two ways:\n"
32 " 1. As positive real numbers representing seconds, e.g. '10', '3.5' "
33 "but not 'INF', 'NaN', '1e3', '-4.5s'\n"
34 " 2. As a sequence of natural numbers with specified units, e.g. "
35 "'1h10min' (= '70min'), '5min10s' but not '3.5min', '8S'\n"
36 " The following units are supported: h, min, s, ms, us, ns.\n");
37
38cl::OptionCategory SolvingCat("Constraint solving options",
39 "These options impact constraint solving.");
40
41cl::opt<bool> UseFastCexSolver(
42 "use-fast-cex-solver", cl::init(false),
43 cl::desc("Enable an experimental range-based solver (default=false)"),
44 cl::cat(SolvingCat));
45
46cl::opt<bool> UseCexCache("use-cex-cache", cl::init(true),
47 cl::desc("Use the counterexample cache (default=true)"),
48 cl::cat(SolvingCat));
49
50cl::opt<bool> UseBranchCache("use-branch-cache", cl::init(true),
51 cl::desc("Use the branch cache (default=true)"),
52 cl::cat(SolvingCat));
53
54cl::opt<bool>
55 UseIndependentSolver("use-independent-solver", cl::init(true),
56 cl::desc("Use constraint independence (default=true)"),
57 cl::cat(SolvingCat));
58
59cl::opt<bool> DebugValidateSolver(
60 "debug-validate-solver", cl::init(false),
61 cl::desc("Crosscheck the results of the solver chain above the core solver "
62 "with the results of the core solver (default=false)"),
63 cl::cat(SolvingCat));
64
65cl::opt<std::string> MinQueryTimeToLog(
66 "min-query-time-to-log",
67 cl::desc("Set time threshold for queries logged in files. "
68 "Only queries longer than threshold will be logged. (default=0s)"),
69 cl::cat(SolvingCat));
70
71cl::opt<bool>
72 LogTimedOutQueries("log-timed-out-queries", cl::init(true),
73 cl::desc("Log queries that timed out. (default=true)."),
74 cl::cat(SolvingCat));
75
76cl::opt<std::string> MaxCoreSolverTime(
77 "max-solver-time",
78 cl::desc("Maximum amount of time for a single SMT query (default=0s (off)). "
79 "Enables --use-forked-solver"),
80 cl::cat(SolvingCat));
81
82cl::opt<bool> UseForkedCoreSolver(
83 "use-forked-solver",
84 cl::desc("Run the core SMT solver in a forked process (default=true)"),
85 cl::init(true), cl::cat(SolvingCat));
86
88 "solver-optimize-divides",
89 cl::desc("Optimize constant divides into add/shift/multiplies before "
90 "passing them to the core SMT solver (default=false)"),
91 cl::init(false), cl::cat(SolvingCat));
92
93cl::bits<QueryLoggingSolverType> QueryLoggingOptions(
94 "use-query-log",
95 cl::desc("Log queries to a file. Multiple options can be specified "
96 "separated by a comma. By default nothing is logged."),
97 cl::values(
98 clEnumValN(ALL_KQUERY, "all:kquery",
99 "All queries in .kquery (KQuery) format"),
100 clEnumValN(ALL_SMTLIB, "all:smt2",
101 "All queries in .smt2 (SMT-LIBv2) format"),
102 clEnumValN(
103 SOLVER_KQUERY, "solver:kquery",
104 "All queries reaching the solver in .kquery (KQuery) format"),
105 clEnumValN(
106 SOLVER_SMTLIB, "solver:smt2",
107 "All queries reaching the solver in .smt2 (SMT-LIBv2) format")),
108 cl::CommaSeparated, cl::cat(SolvingCat));
109
111 "debug-assignment-validating-solver", cl::init(false),
112 cl::desc("Debug the correctness of generated assignments (default=false)"),
113 cl::cat(SolvingCat));
114
115
116void KCommandLine::HideOptions(llvm::cl::OptionCategory &Category) {
117 StringMap<cl::Option *> &map = cl::getRegisteredOptions();
118
119 for (auto &elem : map) {
120#if LLVM_VERSION_CODE >= LLVM_VERSION(9, 0)
121 for (auto &cat : elem.second->Categories) {
122#else
123 {
124 auto &cat = elem.second->Category;
125#endif
126 if (cat == &Category) {
127 elem.second->setHiddenFlag(cl::Hidden);
128 }
129 }
130 }
131}
132
133#ifdef ENABLE_METASMT
134
135#ifdef METASMT_DEFAULT_BACKEND_IS_BTOR
136#define METASMT_DEFAULT_BACKEND_STR "(default = btor)."
137#define METASMT_DEFAULT_BACKEND METASMT_BACKEND_BOOLECTOR
138#elif METASMT_DEFAULT_BACKEND_IS_Z3
139#define METASMT_DEFAULT_BACKEND_STR "(default = z3)."
140#define METASMT_DEFAULT_BACKEND METASMT_BACKEND_Z3
141#elif METASMT_DEFAULT_BACKEND_IS_CVC4
142#define METASMT_DEFAULT_BACKEND_STR "(default = cvc4)."
143#define METASMT_DEFAULT_BACKEND METASMT_BACKEND_CVC4
144#elif METASMT_DEFAULT_BACKEND_IS_YICES2
145#define METASMT_DEFAULT_BACKEND_STR "(default = yices2)."
146#define METASMT_DEFAULT_BACKEND METASMT_BACKEND_YICES2
147#else
148#define METASMT_DEFAULT_BACKEND_STR "(default = stp)."
149#define METASMT_DEFAULT_BACKEND METASMT_BACKEND_STP
150#endif
151
152cl::opt<klee::MetaSMTBackendType>
153MetaSMTBackend("metasmt-backend",
154 cl::desc("Specify the MetaSMT solver backend type " METASMT_DEFAULT_BACKEND_STR),
155 cl::values(clEnumValN(METASMT_BACKEND_STP, "stp", "Use metaSMT with STP"),
156 clEnumValN(METASMT_BACKEND_Z3, "z3", "Use metaSMT with Z3"),
157 clEnumValN(METASMT_BACKEND_BOOLECTOR, "btor",
158 "Use metaSMT with Boolector"),
159 clEnumValN(METASMT_BACKEND_CVC4, "cvc4", "Use metaSMT with CVC4"),
160 clEnumValN(METASMT_BACKEND_YICES2, "yices2", "Use metaSMT with Yices2")),
161 cl::init(METASMT_DEFAULT_BACKEND),
162 cl::cat(SolvingCat));
163
164#undef METASMT_DEFAULT_BACKEND
165#undef METASMT_DEFAULT_BACKEND_STR
166
167#endif /* ENABLE_METASMT */
168
169// Pick the default core solver based on configuration
170#ifdef ENABLE_STP
171#define STP_IS_DEFAULT_STR " (default)"
172#define METASMT_IS_DEFAULT_STR ""
173#define Z3_IS_DEFAULT_STR ""
174#define DEFAULT_CORE_SOLVER STP_SOLVER
175#elif ENABLE_Z3
176#define STP_IS_DEFAULT_STR ""
177#define METASMT_IS_DEFAULT_STR ""
178#define Z3_IS_DEFAULT_STR " (default)"
179#define DEFAULT_CORE_SOLVER Z3_SOLVER
180#elif ENABLE_METASMT
181#define STP_IS_DEFAULT_STR ""
182#define METASMT_IS_DEFAULT_STR " (default)"
183#define Z3_IS_DEFAULT_STR ""
184#define DEFAULT_CORE_SOLVER METASMT_SOLVER
185#define Z3_IS_DEFAULT_STR ""
186#else
187#error "Unsupported solver configuration"
188#endif
189
190cl::opt<CoreSolverType> CoreSolverToUse(
191 "solver-backend", cl::desc("Specifiy the core solver backend to use"),
192 cl::values(clEnumValN(STP_SOLVER, "stp", "STP" STP_IS_DEFAULT_STR),
193 clEnumValN(METASMT_SOLVER, "metasmt",
194 "metaSMT" METASMT_IS_DEFAULT_STR),
195 clEnumValN(DUMMY_SOLVER, "dummy", "Dummy solver"),
196 clEnumValN(Z3_SOLVER, "z3", "Z3" Z3_IS_DEFAULT_STR)),
197 cl::init(DEFAULT_CORE_SOLVER), cl::cat(SolvingCat));
198
199cl::opt<CoreSolverType> DebugCrossCheckCoreSolverWith(
200 "debug-crosscheck-core-solver",
201 cl::desc(
202 "Specifiy a solver to use for crosschecking the results of the core solver"),
203 cl::values(clEnumValN(STP_SOLVER, "stp", "STP"),
204 clEnumValN(METASMT_SOLVER, "metasmt", "metaSMT"),
205 clEnumValN(DUMMY_SOLVER, "dummy", "Dummy solver"),
206 clEnumValN(Z3_SOLVER, "z3", "Z3"),
207 clEnumValN(NO_SOLVER, "none", "Do not crosscheck (default)")),
208 cl::init(NO_SOLVER), cl::cat(SolvingCat));
209} // namespace klee
210
211#undef STP_IS_DEFAULT_STR
212#undef METASMT_IS_DEFAULT_STR
213#undef Z3_IS_DEFAULT_STR
214#undef DEFAULT_CORE_SOLVER
static void HideOptions(llvm::cl::OptionCategory &Category)
Hide all options in the specified category.
Definition: main.cpp:291
llvm::cl::opt< CoreSolverType > CoreSolverToUse
cl::extrahelp TimeFormatInfo("\nTime format used by KLEE's options\n" "\n" " Time spans can be specified in two ways:\n" " 1. As positive real numbers representing seconds, e.g. '10', '3.5' " "but not 'INF', 'NaN', '1e3', '-4.5s'\n" " 2. As a sequence of natural numbers with specified units, e.g. " "'1h10min' (= '70min'), '5min10s' but not '3.5min', '8S'\n" " The following units are supported: h, min, s, ms, us, ns.\n")
llvm::cl::opt< bool > UseFastCexSolver
llvm::cl::opt< bool > LogTimedOutQueries
llvm::cl::opt< std::string > MaxCoreSolverTime
llvm::cl::opt< bool > DebugValidateSolver
llvm::cl::opt< std::string > MinQueryTimeToLog
@ SOLVER_SMTLIB
Log queries passed to solver in .smt2 (SMT-LIBv2) format.
Definition: SolverCmdLine.h:52
@ SOLVER_KQUERY
Log queries passed to solver in .kquery (KQuery) format.
Definition: SolverCmdLine.h:51
@ ALL_SMTLIB
Log all queries .smt2 (SMT-LIBv2) format.
Definition: SolverCmdLine.h:50
@ ALL_KQUERY
Log all queries in .kquery (KQuery) format.
Definition: SolverCmdLine.h:49
llvm::cl::opt< CoreSolverType > DebugCrossCheckCoreSolverWith
llvm::cl::opt< bool > UseAssignmentValidatingSolver
llvm::cl::opt< bool > UseIndependentSolver
llvm::cl::OptionCategory SolvingCat
@ NO_SOLVER
Definition: SolverCmdLine.h:62
@ METASMT_SOLVER
Definition: SolverCmdLine.h:59
@ Z3_SOLVER
Definition: SolverCmdLine.h:61
@ STP_SOLVER
Definition: SolverCmdLine.h:58
@ DUMMY_SOLVER
Definition: SolverCmdLine.h:60
llvm::cl::opt< bool > UseCexCache
llvm::cl::opt< bool > UseForkedCoreSolver
llvm::cl::opt< bool > CoreSolverOptimizeDivides
llvm::cl::bits< QueryLoggingSolverType > QueryLoggingOptions
llvm::cl::opt< bool > UseBranchCache