ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
CaDiCaL::Options Class Reference

#include <options.hpp>

Public Types

typedef Optioniterator
 
typedef const Optionconst_iterator
 

Public Member Functions

 Options (Internal *)
 
OPTIONS int & val (size_t idx)
 
bool set (const char *name, int)
 
int get (const char *name)
 
void print ()
 
void optimize (int val)
 
void copy (Options &other) const
 

Static Public Member Functions

static Optionhas (const char *name)
 
static void usage ()
 
static bool is_preprocessing_option (const char *name)
 
static bool parse_long_option (const char *, string &, int &)
 
static iterator begin ()
 
static iterator end ()
 

Static Public Attributes

static int reportdefault
 

Friends

struct Option
 

Detailed Description

Definition at line 315 of file options.hpp.

Member Typedef Documentation

◆ const_iterator

Definition at line 404 of file options.hpp.

◆ iterator

Definition at line 403 of file options.hpp.

Constructor & Destructor Documentation

◆ Options()

CaDiCaL::Options::Options ( Internal * s)

Definition at line 108 of file cadical_options.cpp.

108 : internal (s) {
109 CADICAL_assert (number_of_options == sizeof Options::table / sizeof (Option));
110
111 // First initialize them according to defaults in 'options.hpp'.
112 //
113 const char *prev = "";
114 size_t i = 0;
115#define OPTION(N, V, L, H, O, P, R, D) \
116 do { \
117 if ((L) > (V)) \
118 FATAL ("'" #N "' default '" #V "' " \
119 "lower minimum '" #L "' in 'options.hpp'"); \
120 if ((H) < (V)) \
121 FATAL ("'" #N "' default '" #V "' " \
122 "larger maximum '" #H "' in 'options.hpp'"); \
123 if (strcmp (prev, #N) > 0) \
124 FATAL ("'%s' ordered before '" #N "' in 'options.hpp'", prev); \
125 N = (int) (V); \
126 CADICAL_assert (&val (i) == &N); \
127 /* The order of initializing static data is undefined and thus */ \
128 /* it might be the case that the 'table' is not initialized yet. */ \
129 /* Thus this construction just reinitializes the table too even */ \
130 /* though it might not be necessary. */ \
131 CADICAL_assert (!table[i].name || !strcmp (table[i].name, #N)); \
132 table[i] = {#N, (int) (V), (int) (L), (int) (H), \
133 (int) (O), (bool) (P), D}; \
134 prev = #N; \
135 i++; \
136 } while (0);
137 OPTIONS
138#undef OPTION
139
140 // Check consistency in debugging mode.
141 //
142#ifndef CADICAL_NDEBUG
143 CADICAL_assert (i == number_of_options);
144 CADICAL_assert (!has ("aaaaa"));
145 CADICAL_assert (!has ("non-existing-option"));
146 CADICAL_assert (!has ("zzzzz"));
147#endif
148
149 // Now overwrite default options with environment values.
150 //
151#define OPTION(N, V, L, H, O, P, R, D) \
152 initialize_from_environment (N, #N, L, H);
153 OPTIONS
154#undef OPTION
155}
#define CADICAL_assert(ignore)
Definition global.h:14
friend struct Option
Definition options.hpp:321
static Option * has(const char *name)
#define OPTIONS
Definition options.hpp:24
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ begin()

static iterator CaDiCaL::Options::begin ( )
inlinestatic

Definition at line 406 of file options.hpp.

406{ return table; }

◆ copy()

void CaDiCaL::Options::copy ( Options & other) const

Definition at line 348 of file cadical_options.cpp.

348 {
349#ifdef LOGGING
350 Internal *internal = other.internal;
351#endif
352#define OPTION(N, V, L, H, O, P, R, D) \
353 if ((N) == (int) (V)) \
354 LOG ("keeping non default option '--%s=%s'", #N, #V); \
355 else if ((N) != (int) (V)) { \
356 LOG ("overwriting default option by '--%s=%d'", #N, N); \
357 other.N = N; \
358 }
359 OPTIONS
360#undef OPTION
361}
Here is the call graph for this function:

◆ end()

static iterator CaDiCaL::Options::end ( )
inlinestatic

Definition at line 407 of file options.hpp.

407{ return table + number_of_options; }

◆ get()

int CaDiCaL::Options::get ( const char * name)

Definition at line 191 of file cadical_options.cpp.

191 {
192 Option *o = has (name);
193 return o ? o->val (this) : 0;
194}
char * name
Definition main.h:24
Here is the call graph for this function:

◆ has()

Option * CaDiCaL::Options::has ( const char * name)
static

Definition at line 42 of file cadical_options.cpp.

42 {
43 size_t l = 0, r = number_of_options;
44 while (l < r) {
45 size_t m = l + (r - l) / 2;
46 Option *res = &table[m];
47 int tmp = strcmp (name, res->name);
48 if (!tmp)
49 return res;
50 if (tmp < 0)
51 r = m;
52 if (tmp > 0)
53 l = m + 1;
54 }
55 return 0;
56}
int strcmp()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_preprocessing_option()

bool CaDiCaL::Options::is_preprocessing_option ( const char * name)
static

Definition at line 319 of file cadical_options.cpp.

319 {
320 Option *o = has (name);
321 return o ? o->preprocessing : false;
322}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ optimize()

void CaDiCaL::Options::optimize ( int val)

Definition at line 250 of file cadical_options.cpp.

250 {
251
252 if (val < 0) {
253 LOG ("ignoring negative optimization mode '%d'", val);
254 return;
255 }
256
257 const int max_val = 31;
258 if (val > max_val) {
259 LOG ("optimization argument '%d' reduced to '%d'", val, max_val);
260 val = max_val;
261 }
262
263 int64_t factor2 = 1;
264 for (int i = 0; i < val && factor2 <= INT_MAX; i++)
265 factor2 *= 2;
266
267 int64_t factor10 = 1;
268 for (int i = 0; i < val && factor10 <= INT_MAX; i++)
269 factor10 *= 10;
270
271 unsigned increased = 0;
272#define OPTION(N, V, L, H, O, P, R, D) \
273 do { \
274 if (!(O)) \
275 break; \
276 const int64_t factor1 = ((O) == 1 ? factor2 : factor10); \
277 int64_t new_val = factor1 * (int64_t) (V); \
278 if (new_val > (H)) \
279 new_val = (H); \
280 if (new_val == (int) (V)) \
281 break; \
282 LOG ("optimization mode '%d' for '%s' " \
283 "gives '%" PRId64 "' instead of '%d", \
284 val, #N, new_val, (int) (V)); \
285 CADICAL_assert (new_val <= INT_MAX); \
286 N = (int) new_val; \
287 increased++; \
288 } while (0);
289 OPTIONS
290#undef OPTION
291 if (increased)
292 MSG ("optimization mode '-O%d' increased %u limits", val, increased);
293}
#define LOG(...)
OPTIONS int & val(size_t idx)
Definition options.hpp:363
#define MSG(...)
Definition message.hpp:49
Here is the call graph for this function:

◆ parse_long_option()

bool CaDiCaL::Options::parse_long_option ( const char * arg,
string & name,
int & val )
static

Definition at line 60 of file cadical_options.cpp.

60 {
61 if (arg[0] != '-' || arg[1] != '-')
62 return false;
63 const bool has_no_prefix =
64 (arg[2] == 'n' && arg[3] == 'o' && arg[4] == '-');
65 const size_t offset = has_no_prefix ? 5 : 2;
66 name = arg + offset;
67 const size_t pos = name.find_first_of ('=');
68 if (pos != string::npos)
69 name[pos] = 0;
70 if (!Options::has (name.c_str ()))
71 return false;
72 if (pos == string::npos)
73 val = !has_no_prefix;
74 else {
75 const char *val_str = name.c_str () + pos + 1;
76 if (!parse_int_str (val_str, val))
77 return false;
78 }
79 return true;
80}
bool pos
Definition globals.c:30
bool parse_int_str(const char *val_str, int &val)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print()

void CaDiCaL::Options::print ( )

Definition at line 198 of file cadical_options.cpp.

198 {
199 unsigned different = 0;
200#ifdef CADICAL_QUIET
201 const bool verbose = false;
202#endif
203 char buffer[256];
204 // We prefer the macro iteration here since '[VLH]' might be '1e9' etc.
205#define OPTION(N, V, L, H, O, P, R, D) \
206 if (N != (V)) \
207 different++; \
208 if (verbose || N != (V)) { \
209 if ((L) == 0 && (H) == 1) { \
210 snprintf (buffer, sizeof buffer, "--" #N "=%s", \
211 (N ? "true" : "false")); \
212 MSG (" %s%-30s%s (%s default %s'%s'%s)", \
213 ((N == (V)) ? "" : tout.bright_yellow_code ()), buffer, \
214 ((N == (V)) ? "" : tout.normal_code ()), \
215 ((N == (V)) ? "same as" : "different from"), \
216 ((N == (V)) ? tout.green_code () : tout.yellow_code ()), \
217 (bool) (V) ? "true" : "false", tout.normal_code ()); \
218 } else { \
219 snprintf (buffer, sizeof buffer, "--" #N "=%d", N); \
220 MSG (" %s%-30s%s (%s default %s'" #V "'%s)", \
221 ((N == (V)) ? "" : tout.bright_yellow_code ()), buffer, \
222 ((N == (V)) ? "" : tout.normal_code ()), \
223 ((N == (V)) ? "same as" : "different from"), \
224 ((N == (V)) ? tout.green_code () : tout.yellow_code ()), \
225 tout.normal_code ()); \
226 } \
227 }
228 OPTIONS
229#undef OPTION
230 if (!different)
231 MSG ("all options are set to their default value");
232}

◆ set()

bool CaDiCaL::Options::set ( const char * name,
int val )

Definition at line 183 of file cadical_options.cpp.

183 {
184 Option *o = has (name);
185 if (!o)
186 return false;
187 set (o, val);
188 return true;
189}
Here is the call graph for this function:

◆ usage()

void CaDiCaL::Options::usage ( )
static

Definition at line 236 of file cadical_options.cpp.

236 {
237 // We prefer the macro iteration here since '[VLH]' might be '1e9' etc.
238#define OPTION(N, V, L, H, O, P, R, D) \
239 if ((L) == 0 && (H) == 1) \
240 printf (" %-26s " D " [%s]\n", "--" #N "=bool", \
241 (bool) (V) ? "true" : "false"); \
242 else \
243 printf (" %-26s " D " [" #V "]\n", "--" #N "=" #L ".." #H);
244 OPTIONS
245#undef OPTION
246}
Here is the caller graph for this function:

◆ val()

OPTIONS int & CaDiCaL::Options::val ( size_t idx)
inline

Definition at line 363 of file options.hpp.

363 {
364 CADICAL_assert (idx < number_of_options);
365 return (&__start_of_options__ + 1)[idx];
366 }
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ Option

friend struct Option
friend

Definition at line 321 of file options.hpp.

Member Data Documentation

◆ reportdefault

int CaDiCaL::Options::reportdefault
static

Definition at line 341 of file options.hpp.


The documentation for this class was generated from the following files: