1 /********************* */
2 /*! \file options_handler.cpp
4 ** Top contributors (to current version):
5 ** Aina Niemetz, Tim King, Mathias Preiner
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8 ** in the top-level source directory and their institutional affiliations.
9 ** All rights reserved. See the file COPYING in the top-level source
10 ** directory for licensing information.\endverbatim
12 ** \brief Interface for custom handlers and predicates options.
14 ** Interface for custom handlers and predicates options.
17 #include "options/options_handler.h"
23 #include "cvc4autoconfig.h"
25 #include "base/check.h"
26 #include "base/configuration.h"
27 #include "base/configuration_private.h"
28 #include "base/exception.h"
29 #include "base/modal_exception.h"
30 #include "base/output.h"
31 #include "lib/strtok_r.h"
32 #include "options/base_options.h"
33 #include "options/bv_options.h"
34 #include "options/decision_options.h"
35 #include "options/didyoumean.h"
36 #include "options/language.h"
37 #include "options/option_exception.h"
38 #include "options/smt_options.h"
39 #include "options/theory_options.h"
47 void throwLazyBBUnsupported(options::SatSolverMode m
)
49 std::string sat_solver
;
50 if (m
== options::SatSolverMode::CADICAL
)
52 sat_solver
= "CaDiCaL";
54 else if (m
== options::SatSolverMode::KISSAT
)
56 sat_solver
= "Kissat";
60 Assert(m
== options::SatSolverMode::CRYPTOMINISAT
);
61 sat_solver
= "CryptoMiniSat";
63 std::string
indent(25, ' ');
64 throw OptionException(sat_solver
+ " does not support lazy bit-blasting.\n"
65 + indent
+ "Try --bv-sat-solver=minisat");
70 OptionsHandler::OptionsHandler(Options
* options
) : d_options(options
) { }
72 unsigned long OptionsHandler::limitHandler(std::string option
,
76 std::istringstream
convert(optarg
);
79 throw OptionException("option `" + option
80 + "` requires a number as an argument");
84 // theory/quantifiers/options_handlers.h
86 void OptionsHandler::checkInstWhenMode(std::string option
, InstWhenMode mode
)
88 if (mode
== InstWhenMode::PRE_FULL
)
90 throw OptionException(std::string("Mode pre-full for ") + option
91 + " is not supported in this release.");
95 // theory/bv/options_handlers.h
96 void OptionsHandler::abcEnabledBuild(std::string option
, bool value
)
100 std::stringstream ss
;
101 ss
<< "option `" << option
<< "' requires an abc-enabled build of CVC4; this binary was not built with abc support";
102 throw OptionException(ss
.str());
104 #endif /* CVC5_USE_ABC */
107 void OptionsHandler::abcEnabledBuild(std::string option
, std::string value
)
111 std::stringstream ss
;
112 ss
<< "option `" << option
<< "' requires an abc-enabled build of CVC4; this binary was not built with abc support";
113 throw OptionException(ss
.str());
115 #endif /* CVC5_USE_ABC */
118 void OptionsHandler::checkBvSatSolver(std::string option
, SatSolverMode m
)
120 if (m
== SatSolverMode::CRYPTOMINISAT
121 && !Configuration::isBuiltWithCryptominisat())
123 std::stringstream ss
;
124 ss
<< "option `" << option
125 << "' requires a CryptoMiniSat build of CVC4; this binary was not built "
126 "with CryptoMiniSat support";
127 throw OptionException(ss
.str());
130 if (m
== SatSolverMode::CADICAL
&& !Configuration::isBuiltWithCadical())
132 std::stringstream ss
;
133 ss
<< "option `" << option
134 << "' requires a CaDiCaL build of CVC4; this binary was not built with "
136 throw OptionException(ss
.str());
139 if (m
== SatSolverMode::KISSAT
&& !Configuration::isBuiltWithKissat())
141 std::stringstream ss
;
142 ss
<< "option `" << option
143 << "' requires a Kissat build of CVC4; this binary was not built with "
145 throw OptionException(ss
.str());
148 if (options::bvSolver() != options::BVSolver::BITBLAST
149 && (m
== SatSolverMode::CRYPTOMINISAT
|| m
== SatSolverMode::CADICAL
150 || m
== SatSolverMode::KISSAT
))
152 if (options::bitblastMode() == options::BitblastMode::LAZY
153 && options::bitblastMode
.wasSetByUser())
155 throwLazyBBUnsupported(m
);
157 if (!options::bitvectorToBool
.wasSetByUser())
159 options::bitvectorToBool
.set(true);
164 void OptionsHandler::checkBitblastMode(std::string option
, BitblastMode m
)
166 if (m
== options::BitblastMode::LAZY
)
168 if (!options::bitvectorPropagate
.wasSetByUser())
170 options::bitvectorPropagate
.set(true);
172 if (!options::bitvectorEqualitySolver
.wasSetByUser())
174 options::bitvectorEqualitySolver
.set(true);
177 if (!options::bitvectorInequalitySolver
.wasSetByUser())
179 options::bitvectorInequalitySolver
.set(true);
181 if (!options::bitvectorAlgebraicSolver
.wasSetByUser())
183 options::bitvectorAlgebraicSolver
.set(true);
185 if (options::bvSatSolver() != options::SatSolverMode::MINISAT
)
187 throwLazyBBUnsupported(options::bvSatSolver());
190 else if (m
== BitblastMode::EAGER
)
192 if (!options::bitvectorToBool
.wasSetByUser())
194 options::bitvectorToBool
.set(true);
199 void OptionsHandler::setBitblastAig(std::string option
, bool arg
)
202 if(options::bitblastMode
.wasSetByUser()) {
203 if (options::bitblastMode() != options::BitblastMode::EAGER
)
205 throw OptionException("bitblast-aig must be used with eager bitblaster");
208 options::BitblastMode mode
= stringToBitblastMode("", "eager");
209 options::bitblastMode
.set(mode
);
211 if(!options::bitvectorAigSimplifications
.wasSetByUser()) {
212 options::bitvectorAigSimplifications
.set("balance;drw");
217 // printer/options_handlers.h
218 const std::string
OptionsHandler::s_instFormatHelp
= "\
219 Inst format modes currently supported by the --inst-format option:\n\
222 + Print instantiations as a list in the output language format.\n\
225 + Print instantiations as SZS compliant proof.\n\
228 InstFormatMode
OptionsHandler::stringToInstFormatMode(std::string option
,
231 if(optarg
== "default") {
232 return InstFormatMode::DEFAULT
;
233 } else if(optarg
== "szs") {
234 return InstFormatMode::SZS
;
235 } else if(optarg
== "help") {
236 puts(s_instFormatHelp
.c_str());
239 throw OptionException(std::string("unknown option for --inst-format: `") +
240 optarg
+ "'. Try --inst-format help.");
244 // decision/options_handlers.h
245 void OptionsHandler::setDecisionModeStopOnly(std::string option
, DecisionMode m
)
247 options::decisionStopOnly
.set(m
== DecisionMode::RELEVANCY
);
250 void OptionsHandler::setProduceAssertions(std::string option
, bool value
)
252 options::produceAssertions
.set(value
);
253 options::interactiveMode
.set(value
);
256 void OptionsHandler::statsEnabledBuild(std::string option
, bool value
)
258 #ifndef CVC5_STATISTICS_ON
260 std::stringstream ss
;
261 ss
<< "option `" << option
<< "' requires a statistics-enabled build of CVC4; this binary was not built with statistics support";
262 throw OptionException(ss
.str());
264 #endif /* CVC5_STATISTICS_ON */
267 void OptionsHandler::threadN(std::string option
) {
268 throw OptionException(option
+ " is not a real option by itself. Use e.g. --thread0=\"--random-seed=10 --random-freq=0.02\" --thread1=\"--random-seed=20 --random-freq=0.05\"");
271 // expr/options_handlers.h
272 void OptionsHandler::setDefaultExprDepthPredicate(std::string option
, int depth
) {
274 throw OptionException("--expr-depth requires a positive argument, or -1.");
278 void OptionsHandler::setDefaultDagThreshPredicate(std::string option
, int dag
) {
280 throw OptionException("--dag-thresh requires a nonnegative argument.");
284 // main/options_handlers.h
286 static void print_config (const char * str
, std::string config
) {
289 if (s
.size() < sz
) s
.resize(sz
, ' ');
290 std::cout
<< s
<< ": " << config
<< std::endl
;
293 static void print_config_cond (const char * str
, bool cond
= false) {
294 print_config(str
, cond
? "yes" : "no");
297 void OptionsHandler::copyright(std::string option
) {
298 std::cout
<< Configuration::copyright() << std::endl
;
302 void OptionsHandler::showConfiguration(std::string option
) {
303 std::cout
<< Configuration::about() << std::endl
;
305 print_config ("version", Configuration::getVersionString());
307 if(Configuration::isGitBuild()) {
308 const char* branchName
= Configuration::getGitBranchName();
309 if(*branchName
== '\0') { branchName
= "-"; }
310 std::stringstream ss
;
313 << std::string(Configuration::getGitCommit()).substr(0, 8)
314 << (Configuration::hasGitModifications() ? " (with modifications)" : "")
316 print_config("scm", ss
.str());
318 print_config_cond("scm", false);
321 std::cout
<< std::endl
;
323 std::stringstream ss
;
324 ss
<< Configuration::getVersionMajor() << "."
325 << Configuration::getVersionMinor() << "."
326 << Configuration::getVersionRelease();
327 print_config("library", ss
.str());
329 std::cout
<< std::endl
;
331 print_config_cond("debug code", Configuration::isDebugBuild());
332 print_config_cond("statistics", Configuration::isStatisticsBuild());
333 print_config_cond("tracing", Configuration::isTracingBuild());
334 print_config_cond("dumping", Configuration::isDumpingBuild());
335 print_config_cond("muzzled", Configuration::isMuzzledBuild());
336 print_config_cond("assertions", Configuration::isAssertionBuild());
337 print_config_cond("coverage", Configuration::isCoverageBuild());
338 print_config_cond("profiling", Configuration::isProfilingBuild());
339 print_config_cond("asan", Configuration::isAsanBuild());
340 print_config_cond("ubsan", Configuration::isUbsanBuild());
341 print_config_cond("tsan", Configuration::isTsanBuild());
342 print_config_cond("competition", Configuration::isCompetitionBuild());
344 std::cout
<< std::endl
;
346 print_config_cond("abc", Configuration::isBuiltWithAbc());
347 print_config_cond("cln", Configuration::isBuiltWithCln());
348 print_config_cond("glpk", Configuration::isBuiltWithGlpk());
349 print_config_cond("cadical", Configuration::isBuiltWithCadical());
350 print_config_cond("cryptominisat", Configuration::isBuiltWithCryptominisat());
351 print_config_cond("gmp", Configuration::isBuiltWithGmp());
352 print_config_cond("kissat", Configuration::isBuiltWithKissat());
353 print_config_cond("poly", Configuration::isBuiltWithPoly());
354 print_config_cond("editline", Configuration::isBuiltWithEditline());
355 print_config_cond("symfpu", Configuration::isBuiltWithSymFPU());
360 static void printTags(unsigned ntags
, char const* const* tags
)
362 std::cout
<< "available tags:";
363 for (unsigned i
= 0; i
< ntags
; ++ i
)
365 std::cout
<< " " << tags
[i
] << std::endl
;
367 std::cout
<< std::endl
;
370 void OptionsHandler::showDebugTags(std::string option
)
372 if (!Configuration::isDebugBuild())
374 throw OptionException("debug tags not available in non-debug builds");
376 else if (!Configuration::isTracingBuild())
378 throw OptionException("debug tags not available in non-tracing builds");
380 printTags(Configuration::getNumDebugTags(),Configuration::getDebugTags());
384 void OptionsHandler::showTraceTags(std::string option
)
386 if (!Configuration::isTracingBuild())
388 throw OptionException("trace tags not available in non-tracing build");
390 printTags(Configuration::getNumTraceTags(), Configuration::getTraceTags());
394 static std::string
suggestTags(char const* const* validTags
,
395 std::string inputTag
,
396 char const* const* additionalTags
)
398 DidYouMean didYouMean
;
401 for (size_t i
= 0; (opt
= validTags
[i
]) != nullptr; ++i
)
403 didYouMean
.addWord(validTags
[i
]);
405 if (additionalTags
!= nullptr)
407 for (size_t i
= 0; (opt
= additionalTags
[i
]) != nullptr; ++i
)
409 didYouMean
.addWord(additionalTags
[i
]);
413 return didYouMean
.getMatchAsString(inputTag
);
416 void OptionsHandler::enableTraceTag(std::string option
, std::string optarg
)
418 if(!Configuration::isTracingBuild())
420 throw OptionException("trace tags not available in non-tracing builds");
422 else if(!Configuration::isTraceTag(optarg
.c_str()))
424 if (optarg
== "help")
427 Configuration::getNumTraceTags(), Configuration::getTraceTags());
431 throw OptionException(
432 std::string("trace tag ") + optarg
+ std::string(" not available.")
433 + suggestTags(Configuration::getTraceTags(), optarg
, nullptr));
438 void OptionsHandler::enableDebugTag(std::string option
, std::string optarg
)
440 if (!Configuration::isDebugBuild())
442 throw OptionException("debug tags not available in non-debug builds");
444 else if (!Configuration::isTracingBuild())
446 throw OptionException("debug tags not available in non-tracing builds");
449 if (!Configuration::isDebugTag(optarg
.c_str())
450 && !Configuration::isTraceTag(optarg
.c_str()))
452 if (optarg
== "help")
455 Configuration::getNumDebugTags(), Configuration::getDebugTags());
459 throw OptionException(std::string("debug tag ") + optarg
460 + std::string(" not available.")
461 + suggestTags(Configuration::getDebugTags(),
463 Configuration::getTraceTags()));
469 OutputLanguage
OptionsHandler::stringToOutputLanguage(std::string option
,
472 if(optarg
== "help") {
473 options::languageHelp
.set(true);
474 return language::output::LANG_AUTO
;
478 return language::toOutputLanguage(optarg
);
479 } catch(OptionException
& oe
) {
480 throw OptionException("Error in " + option
+ ": " + oe
.getMessage() +
481 "\nTry --output-language help");
487 InputLanguage
OptionsHandler::stringToInputLanguage(std::string option
,
490 if(optarg
== "help") {
491 options::languageHelp
.set(true);
492 return language::input::LANG_AUTO
;
496 return language::toInputLanguage(optarg
);
497 } catch(OptionException
& oe
) {
498 throw OptionException("Error in " + option
+ ": " + oe
.getMessage() + "\nTry --lang help");
504 /* options/base_options_handlers.h */
505 void OptionsHandler::setVerbosity(std::string option
, int value
)
507 if(Configuration::isMuzzledBuild()) {
508 DebugChannel
.setStream(&cvc5::null_os
);
509 TraceChannel
.setStream(&cvc5::null_os
);
510 NoticeChannel
.setStream(&cvc5::null_os
);
511 ChatChannel
.setStream(&cvc5::null_os
);
512 MessageChannel
.setStream(&cvc5::null_os
);
513 WarningChannel
.setStream(&cvc5::null_os
);
516 ChatChannel
.setStream(&cvc5::null_os
);
518 ChatChannel
.setStream(&std::cout
);
521 NoticeChannel
.setStream(&cvc5::null_os
);
523 NoticeChannel
.setStream(&std::cout
);
526 MessageChannel
.setStream(&cvc5::null_os
);
527 WarningChannel
.setStream(&cvc5::null_os
);
529 MessageChannel
.setStream(&std::cout
);
530 WarningChannel
.setStream(&std::cerr
);
535 void OptionsHandler::increaseVerbosity(std::string option
) {
536 options::verbosity
.set(options::verbosity() + 1);
537 setVerbosity(option
, options::verbosity());
540 void OptionsHandler::decreaseVerbosity(std::string option
) {
541 options::verbosity
.set(options::verbosity() - 1);
542 setVerbosity(option
, options::verbosity());
545 } // namespace options