15static const opt table[] = {
16#define OPTION(N, V, L, H, D) {#N, (int) (V), D},
23static const opt table[] = {
24#define OPTION(N, V, L, H, D) {#N, (int) (V), (int) (L), (int) (H), D},
31#define size_table (sizeof table / sizeof *table)
36static void check_table_sorted (
void) {
40 if (
p &&
strcmp (
p->name, o->name) >= 0)
41 kissat_fatal (
"option '%s' before option '%s'",
p->name, o->name);
68 if (!
strcmp (val_str,
"true")) {
72 if (!
strcmp (val_str,
"false")) {
77 char const *
p = val_str;
85 const unsigned max = -(unsigned) INT_MIN;
86 unsigned res = ch -
'0';
87 while (isdigit ((ch = *
p++))) {
91 const unsigned digit = ch -
'0';
92 if (max - digit < res)
100 if (!isdigit ((ch = *
p++)))
105 const unsigned digit = ch -
'0';
106 for (
unsigned i = 0; i < digit; i++) {
113 while (isdigit (ch = *
p++))
118 }
else if (ch ==
'^')
120 const unsigned base = res;
121 if (!isdigit ((ch = *
p++)))
123 unsigned exp = ch -
'0';
126 while (isdigit (ch = *
p++))
130 }
else if (isdigit (ch = *
p++))
135 const unsigned digit = ch -
'0';
142 for (
unsigned i = 1; i < exp; i++) {
143 if (max / base < res)
154 if (sign > 0 && res == max)
162 if (arg[0] !=
'-' || arg[1] !=
'-')
164 char const *
p = arg + 2, *q =
name;
165 if (
p[0] ==
'n' &&
p[1] ==
'o' &&
p[2] ==
'-')
167 while (*
p && *
p == *q)
176#ifdef KISSAT_NOPTIONS
182 return o ? o->
value : 0;
197static void kissat_printf_usage (
const char *option,
const char *fmt, ...) {
199 printf (
" %-26s ", option);
203 fputc (
'\n', stdout);
206static void check_ranges (
void) {
207#define OPTION(N, V, L, H, D) \
209 if ((int) (L) > (int) (H)) \
210 kissat_fatal ("minimum '%d' of option '%s' above maximum '%d'", \
211 (int) (L), #N, (int) (H)); \
212 if ((int) (V) < (int) (L)) \
214 "default value '%d' of option '%s' below minimum '%d'", \
215 (int) (V), #N, (int) (L)); \
216 if ((int) (V) > (int) (H)) \
218 "default value '%d' of option '%s' above maximum '%d'", \
219 (int) (V), #N, (int) (H)); \
225static void check_name_length (
void) {
227#define OPTION(N, V, L, H, D) \
228 if (strlen (#N) + 1 > kissat_options_max_name_buffer_size) \
229 kissat_fatal ("option '%s' name length %zu " \
230 "exceeds maximum name buffer size %zu", \
231 #N, strlen (#N), kissat_options_max_name_buffer_size);
243int kissat_options_set_opt (options *options,
const opt *o,
int value) {
246 int *
p = (
int *) options + (o - table);
258int kissat_options_set (options *options,
const char *
name,
int value) {
262 return kissat_options_set_opt (options, o,
value);
267 check_name_length ();
268 check_table_sorted ();
269#define OPTION(N, V, L, H, D) \
270 KISSAT_assert ((L) <= (V)); \
271 KISSAT_assert ((V) <= (H)); \
277#define FORMAT_OPTION_LIMIT(V) \
278 (((V) == INT_MIN || (V) == INT_MAX) \
280 : kissat_format_value (&format, false, (V)))
282void kissat_options_usage (
void) {
284 check_name_length ();
285 check_table_sorted ();
287 memset (&format, 0,
sizeof format);
288#define OPTION(N, V, L, H, D) \
290 const bool b = ((L) == 0 && (H) == 1); \
293 sprintf (buffer, "--%s=<bool>", #N); \
295 const char *low_str = FORMAT_OPTION_LIMIT ((L)); \
296 const char *high_str = FORMAT_OPTION_LIMIT ((H)); \
297 sprintf (buffer, "--%s=%s..%s", #N, low_str, high_str); \
299 const char *val_str = kissat_format_value (&format, b, (V)); \
300 kissat_printf_usage (buffer, "%s [%s]", D, val_str); \
306bool kissat_options_parse_arg (
const char *arg,
char *buffer,
308 if (arg[0] !=
'-' || arg[1] !=
'-')
312 while ((ch = *
p) && ch !=
'=')
316 const size_t len =
p -
name;
317 if (len >= kissat_options_max_name_buffer_size)
332 if (arg[2] ==
'n' && arg[3] ==
'o' && arg[4] ==
'-') {
335 if (!o || o->low > (
value = 0))
339 if (!o || o->high < (
value = 1))
349static bool ignore_embedded_option_for_fuzzing (
const char *
name) {
362void kissat_print_embedded_option_list () {
363#define OPTION(N, V, L, H, D) \
364 if (!ignore_embedded_option_for_fuzzing (#N)) \
365 printf ("c --%s=%d\n", #N, (int) (V));
370static bool ignore_range_option_for_fuzzing (
const char *
name) {
394void kissat_print_option_range_list (
void) {
395#define OPTION(N, V, L, H, D) \
396 if (!ignore_range_option_for_fuzzing (#N)) \
397 printf ("%s %d %d %d\n", #N, (int) (L), (int) (V), (int) (H));
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_NAMESPACE_IMPL_START typedef signed char value
void kissat_fatal(const char *fmt,...)
#define KISSAT_assert(ignore)
const opt * kissat_options_end
void kissat_init_options(void)
int kissat_options_get(const char *name)
const opt * kissat_options_begin
const opt * kissat_options_has(const char *name)
bool kissat_parse_option_value(const char *val_str, int *res_ptr)
const char * kissat_parse_option_name(const char *arg, const char *name)