1 /********************* */
4 ** Top contributors (to current version):
5 ** Tim King, Morgan Deters, Paul Meng
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2017 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 Global (command-line, set-option, ...) parameters for SMT.
14 ** Global (command-line, set-option, ...) parameters for SMT.
17 #include "cvc4_public.h"
19 #ifndef __CVC4__OPTIONS__OPTIONS_H
20 #define __CVC4__OPTIONS__OPTIONS_H
27 #include "base/listener.h"
28 #include "base/modal_exception.h"
30 #include "options/argument_extender.h"
31 #include "options/language.h"
32 #include "options/option_exception.h"
33 #include "options/printer_modes.h"
40 }/* CVC4::options namespace */
42 class CVC4_PUBLIC Options
{
43 /** The struct that holds all option values. */
44 options::OptionsHolder
* d_holder
;
46 /** The handler for the options of the theory. */
47 options::OptionsHandler
* d_handler
;
49 /** The current Options in effect */
50 static CVC4_THREAD_LOCAL Options
* s_current
;
52 /** Listeners for options::forceLogicString being set. */
53 ListenerCollection d_forceLogicListeners
;
55 /** Listeners for notifyBeforeSearch. */
56 ListenerCollection d_beforeSearchListeners
;
58 /** Listeners for options::tlimit. */
59 ListenerCollection d_tlimitListeners
;
61 /** Listeners for options::tlimit-per. */
62 ListenerCollection d_tlimitPerListeners
;
64 /** Listeners for options::rlimit. */
65 ListenerCollection d_rlimitListeners
;
67 /** Listeners for options::tlimit-per. */
68 ListenerCollection d_rlimitPerListeners
;
70 /** Listeners for options::useTheoryList. */
71 ListenerCollection d_useTheoryListListeners
;
73 /** Listeners for options::defaultExprDepth. */
74 ListenerCollection d_setDefaultExprDepthListeners
;
76 /** Listeners for options::defaultDagThresh. */
77 ListenerCollection d_setDefaultDagThreshListeners
;
79 /** Listeners for options::printExprTypes. */
80 ListenerCollection d_setPrintExprTypesListeners
;
82 /** Listeners for options::dumpModeString. */
83 ListenerCollection d_setDumpModeListeners
;
85 /** Listeners for options::printSuccess. */
86 ListenerCollection d_setPrintSuccessListeners
;
88 /** Listeners for options::dumpToFileName. */
89 ListenerCollection d_dumpToFileListeners
;
91 /** Listeners for options::regularChannelName. */
92 ListenerCollection d_setRegularChannelListeners
;
94 /** Listeners for options::diagnosticChannelName. */
95 ListenerCollection d_setDiagnosticChannelListeners
;
97 /** Listeners for options::replayFilename. */
98 ListenerCollection d_setReplayFilenameListeners
;
101 static ListenerCollection::Registration
* registerAndNotify(
102 ListenerCollection
& collection
, Listener
* listener
, bool notify
);
104 /** Low-level assignment function for options */
106 void assign(T
, std::string option
, std::string value
);
107 /** Low-level assignment function for bool-valued options */
109 void assignBool(T
, std::string option
, bool value
);
111 friend class options::OptionsHandler
;
114 * Options cannot be copied as they are given an explicit list of
115 * Listeners to respond to.
117 Options(const Options
& options
) CVC4_UNDEFINED
;
120 * Options cannot be assigned as they are given an explicit list of
121 * Listeners to respond to.
123 Options
& operator=(const Options
& options
) CVC4_UNDEFINED
;
125 static std::string
formatThreadOptionException(const std::string
& option
);
127 static const size_t s_maxoptlen
= 128;
128 static const unsigned s_preemptAdditional
= 6;
131 class CVC4_PUBLIC OptionsScope
{
133 Options
* d_oldOptions
;
135 OptionsScope(Options
* newOptions
) :
136 d_oldOptions(Options::s_current
)
138 Options::s_current
= newOptions
;
141 Options::s_current
= d_oldOptions
;
145 /** Return true if current Options are null */
146 static inline bool isCurrentNull() {
147 return s_current
== NULL
;
150 /** Get the current Options in effect */
151 static inline Options
* current() {
159 * Copies the value of the options stored in OptionsHolder into the current
161 * This does not copy the listeners in the Options object.
163 void copyValues(const Options
& options
);
166 * Set the value of the given option. Use of this default
167 * implementation causes a compile-time error; write-able
168 * options specialize this template with a real implementation.
171 void set(T
, const typename
T::type
&) {
172 // Flag a compile-time error. Write-able options specialize
173 // this template to provide an implementation.
174 T::you_are_trying_to_assign_to_a_read_only_option
;
178 * Set the value of the given option by key.
180 void setOption(const std::string
& key
, const std::string
& optionarg
)
181 throw(OptionException
, ModalException
);
184 /** Get the value of the given option. Const access only. */
186 const typename
T::type
& operator[](T
) const;
189 * Gets the value of the given option by key and returns value as a string.
191 std::string
getOption(const std::string
& key
) const
192 throw(OptionException
);
194 // Get accessor functions.
195 InputLanguage
getInputLanguage() const;
196 InstFormatMode
getInstFormatMode() const;
197 OutputLanguage
getOutputLanguage() const;
198 bool getCheckProofs() const;
199 bool getContinuedExecution() const;
200 bool getDumpInstantiations() const;
201 bool getDumpModels() const;
202 bool getDumpProofs() const;
203 bool getDumpSynth() const;
204 bool getDumpUnsatCores() const;
205 bool getEarlyExit() const;
206 bool getFallbackSequential() const;
207 bool getFilesystemAccess() const;
208 bool getForceNoLimitCpuWhileDump() const;
209 bool getHelp() const;
210 bool getIncrementalParallel() const;
211 bool getIncrementalSolving() const;
212 bool getInteractive() const;
213 bool getInteractivePrompt() const;
214 bool getLanguageHelp() const;
215 bool getMemoryMap() const;
216 bool getParseOnly() const;
217 bool getProduceModels() const;
218 bool getProof() const;
219 bool getSegvSpin() const;
220 bool getSemanticChecks() const;
221 bool getStatistics() const;
222 bool getStatsEveryQuery() const;
223 bool getStatsHideZeros() const;
224 bool getStrictParsing() const;
225 int getTearDownIncremental() const;
226 bool getVersion() const;
227 bool getWaitToJoin() const;
228 const std::string
& getForceLogicString() const;
229 const std::vector
<std::string
>& getThreadArgv() const;
230 int getSharingFilterByLength() const;
231 int getThreadId() const;
232 int getVerbosity() const;
233 std::istream
* getIn() const;
234 std::ostream
* getErr();
235 std::ostream
* getOut();
236 std::ostream
* getOutConst() const; // TODO: Remove this.
237 std::string
getBinaryName() const;
238 std::string
getReplayInputFilename() const;
239 unsigned getParseStep() const;
240 unsigned getThreadStackSize() const;
241 unsigned getThreads() const;
244 // TODO: Document these.
245 void setInputLanguage(InputLanguage
);
246 void setInteractive(bool);
247 void setOut(std::ostream
*);
248 void setOutputLanguage(OutputLanguage
);
249 void setSharingFilterByLength(int length
);
250 void setThreadId(int);
252 bool wasSetByUserCeGuidedInst() const;
253 bool wasSetByUserDumpSynth() const;
254 bool wasSetByUserEarlyExit() const;
255 bool wasSetByUserForceLogicString() const;
256 bool wasSetByUserIncrementalSolving() const;
257 bool wasSetByUserInteractive() const;
258 bool wasSetByUserThreadStackSize() const;
259 bool wasSetByUserThreads() const;
261 // Static accessor functions.
262 // TODO: Document these.
263 static int currentGetSharingFilterByLength();
264 static int currentGetThreadId();
265 static std::ostream
* currentGetOut();
268 * Returns true iff the value of the given option was set
269 * by the user via a command-line option or SmtEngine::setOption().
270 * (Options::set() is low-level and doesn't count.) Returns false
274 bool wasSetByUser(T
) const;
277 * Get a description of the command-line flags accepted by
278 * parseOptions. The returned string will be escaped so that it is
279 * suitable as an argument to printf. */
280 std::string
getDescription() const;
283 * Print overall command-line option usage message, prefixed by
284 * "msg"---which could be an error message causing the usage
285 * output in the first place, e.g. "no such option --foo"
287 static void printUsage(const std::string msg
, std::ostream
& out
);
290 * Print command-line option usage message for only the most-commonly
291 * used options. The message is prefixed by "msg"---which could be
292 * an error message causing the usage output in the first place, e.g.
293 * "no such option --foo"
295 static void printShortUsage(const std::string msg
, std::ostream
& out
);
297 /** Print help for the --lang command line option */
298 static void printLanguageHelp(std::ostream
& out
);
301 * Look up long command-line option names that bear some similarity
302 * to the given name. Returns an empty string if there are no
305 static std::string
suggestCommandLineOptions(const std::string
& optionName
);
308 * Look up SMT option names that bear some similarity to
309 * the given name. Don't include the initial ":". This might be
310 * useful in case of typos. Can return an empty vector if there are
313 static std::vector
<std::string
> suggestSmtOptions(
314 const std::string
& optionName
);
317 * Initialize the Options object options based on the given
318 * command-line arguments given in argc and argv. The return value
319 * is what's left of the command line (that is, the non-option
322 * This function uses getopt_long() and is not thread safe.
324 * Preconditions: options and argv must be non-null.
326 static std::vector
<std::string
> parseOptions(Options
* options
,
327 int argc
, char* argv
[])
328 throw(OptionException
);
331 * Get the setting for all options.
333 std::vector
<std::vector
<std::string
> > getOptions() const;
336 * Registers a listener for the notification, notifyBeforeSearch.
338 * The memory for the Registration is controlled by the user and must
339 * be destroyed before the Options object is.
341 * This has multiple usages so having a notifyIfSet flag does not add
342 * clarity. Users should check the relevant flags before registering this.
344 ListenerCollection::Registration
* registerBeforeSearchListener(
349 * Registers a listener for options::forceLogic being set.
351 * If notifyIfSet is true, this calls notify on the listener
352 * if the option was set by the user.
354 * The memory for the Registration is controlled by the user and must
355 * be destroyed before the Options object is.
357 ListenerCollection::Registration
* registerForceLogicListener(
358 Listener
* listener
, bool notifyIfSet
);
361 * Registers a listener for options::tlimit being set.
363 * If notifyIfSet is true, this calls notify on the listener
364 * if the option was set by the user.
366 * The memory for the Registration is controlled by the user and must
367 * be destroyed before the Options object is.
369 ListenerCollection::Registration
* registerTlimitListener(
370 Listener
* listener
, bool notifyIfSet
);
373 * Registers a listener for options::tlimit-per being set.
375 * If notifyIfSet is true, this calls notify on the listener
376 * if the option was set by the user.
378 * The memory for the Registration is controlled by the user and must
379 * be destroyed before the Options object is.
381 ListenerCollection::Registration
* registerTlimitPerListener(
382 Listener
* listener
, bool notifyIfSet
);
386 * Registers a listener for options::rlimit being set.
388 * If notifyIfSet is true, this calls notify on the listener
389 * if the option was set by the user.
391 * The memory for the Registration is controlled by the user and must
392 * be destroyed before the Options object is.
394 ListenerCollection::Registration
* registerRlimitListener(
395 Listener
* listener
, bool notifyIfSet
);
398 * Registers a listener for options::rlimit-per being set.
400 * If notifyIfSet is true, this calls notify on the listener
401 * if the option was set by the user.
403 * The memory for the Registration is controlled by the user and must
404 * be destroyed before the Options object is.
406 ListenerCollection::Registration
* registerRlimitPerListener(
407 Listener
* listener
, bool notifyIfSet
);
410 * Registers a listener for options::useTheoryList being set.
412 * If notifyIfSet is true, this calls notify on the listener
413 * if the option was set by the user.
415 * The memory for the Registration is controlled by the user and must
416 * be destroyed before the Options object is.
418 ListenerCollection::Registration
* registerUseTheoryListListener(
419 Listener
* listener
, bool notifyIfSet
);
423 * Registers a listener for options::defaultExprDepth being set.
425 * If notifyIfSet is true, this calls notify on the listener
426 * if the option was set by the user.
428 * The memory for the Registration is controlled by the user and must
429 * be destroyed before the Options object is.
431 ListenerCollection::Registration
* registerSetDefaultExprDepthListener(
432 Listener
* listener
, bool notifyIfSet
);
435 * Registers a listener for options::defaultDagThresh being set.
437 * If notifyIfSet is true, this calls notify on the listener
438 * if the option was set by the user.
440 * The memory for the Registration is controlled by the user and must
441 * be destroyed before the Options object is.
443 ListenerCollection::Registration
* registerSetDefaultExprDagListener(
444 Listener
* listener
, bool notifyIfSet
);
447 * Registers a listener for options::printExprTypes being set.
449 * If notifyIfSet is true, this calls notify on the listener
450 * if the option was set by the user.
452 * The memory for the Registration is controlled by the user and must
453 * be destroyed before the Options object is.
455 ListenerCollection::Registration
* registerSetPrintExprTypesListener(
456 Listener
* listener
, bool notifyIfSet
);
459 * Registers a listener for options::dumpModeString being set.
461 * If notifyIfSet is true, this calls notify on the listener
462 * if the option was set by the user.
464 * The memory for the Registration is controlled by the user and must
465 * be destroyed before the Options object is.
467 ListenerCollection::Registration
* registerSetDumpModeListener(
468 Listener
* listener
, bool notifyIfSet
);
471 * Registers a listener for options::printSuccess being set.
473 * If notifyIfSet is true, this calls notify on the listener
474 * if the option was set by the user.
476 * The memory for the Registration is controlled by the user and must
477 * be destroyed before the Options object is.
479 ListenerCollection::Registration
* registerSetPrintSuccessListener(
480 Listener
* listener
, bool notifyIfSet
);
483 * Registers a listener for options::dumpToFileName being set.
485 * If notifyIfSet is true, this calls notify on the listener
486 * if the option was set by the user.
488 * The memory for the Registration is controlled by the user and must
489 * be destroyed before the Options object is.
491 ListenerCollection::Registration
* registerDumpToFileNameListener(
492 Listener
* listener
, bool notifyIfSet
);
495 * Registers a listener for options::regularChannelName being set.
497 * If notifyIfSet is true, this calls notify on the listener
498 * if the option was set by the user.
500 * The memory for the Registration is controlled by the user and must
501 * be destroyed before the Options object is.
503 ListenerCollection::Registration
* registerSetRegularOutputChannelListener(
504 Listener
* listener
, bool notifyIfSet
);
507 * Registers a listener for options::diagnosticChannelName being set.
509 * If notifyIfSet is true, this calls notify on the listener
510 * if the option was set by the user.
512 * The memory for the Registration is controlled by the user and must
513 * be destroyed before the Options object is.
515 ListenerCollection::Registration
* registerSetDiagnosticOutputChannelListener(
516 Listener
* listener
, bool notifyIfSet
);
519 * Registers a listener for options::replayLogFilename being set.
521 * If notifyIfSet is true, this calls notify on the listener
522 * if the option was set by the user.
524 * The memory for the Registration is controlled by the user and must
525 * be destroyed before the Options object is.
527 ListenerCollection::Registration
* registerSetReplayLogFilename(
528 Listener
* listener
, bool notifyIfSet
);
530 /** Sends a std::flush to getErr(). */
533 /** Sends a std::flush to getOut(). */
539 * Internal procedure for implementing the parseOptions function.
540 * Initializes the options object based on the given command-line
541 * arguments. This uses an ArgumentExtender containing the
542 * command-line arguments. Nonoptions are stored into nonoptions.
544 * This is not thread safe.
546 * Preconditions: options, extender and nonoptions are non-null.
548 static void parseOptionsRecursive(Options
* options
,
549 options::ArgumentExtender
* extender
,
550 std::vector
<std::string
>* nonoptions
)
551 throw(OptionException
);
552 };/* class Options */
554 }/* CVC4 namespace */
556 #endif /* __CVC4__OPTIONS__OPTIONS_H */