ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
kptions.c File Reference
#include "options.h"
#include "error.h"
#include "print.h"
#include <ctype.h>
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for kptions.c:

Go to the source code of this file.

Macros

#define OPTION(N, V, L, H, D)
 
#define size_table   (sizeof table / sizeof *table)
 

Functions

const optkissat_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)
 
void kissat_init_options (void)
 
int kissat_options_get (const char *name)
 

Variables

const optkissat_options_begin = table
 
const optkissat_options_end = table + size_table
 

Macro Definition Documentation

◆ OPTION

#define OPTION ( N,
V,
L,
H,
D )
Value:
{#N, (int) (V), D},

◆ size_table

#define size_table   (sizeof table / sizeof *table)

Definition at line 31 of file kptions.c.

Function Documentation

◆ kissat_init_options()

void kissat_init_options ( void )

Definition at line 178 of file kptions.c.

178{ check_table_sorted (); }
Here is the caller graph for this function:

◆ kissat_options_get()

int kissat_options_get ( const char * name)

Definition at line 180 of file kptions.c.

180 {
181 const opt *const o = kissat_options_has (name);
182 return o ? o->value : 0;
183}
const opt * kissat_options_has(const char *name)
Definition kptions.c:47
char * name
Definition main.h:24
Definition options.h:228
const int value
Definition options.h:235
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kissat_options_has()

const opt * kissat_options_has ( const char * name)

Definition at line 47 of file kptions.c.

47 {
48 size_t l = 0, m, r = size_table;
49 int tmp;
50 opt const *o;
51 KISSAT_assert (l < r);
52 while (l + 1 < r) {
53 m = l + (r - l) / 2;
54 tmp = strcmp (name, (o = table + m)->name);
55 if (tmp < 0)
56 r = m;
57 else if (tmp > 0)
58 l = m;
59 else
60 return o;
61 }
62 o = table + l;
63 tmp = strcmp (o->name, name);
64 return tmp ? 0 : o;
65}
#define KISSAT_assert(ignore)
Definition global.h:13
#define size_table
Definition kptions.c:31
const char * name
Definition options.h:229
int strcmp()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kissat_parse_option_name()

const char * kissat_parse_option_name ( const char * arg,
const char * name )

Definition at line 161 of file kptions.c.

161 {
162 if (arg[0] != '-' || arg[1] != '-')
163 return 0;
164 char const *p = arg + 2, *q = name;
165 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-')
166 return strcmp (p + 3, name) ? 0 : "0";
167 while (*p && *p == *q)
168 p++, q++;
169 if (*q)
170 return 0;
171 if (*p != '=')
172 return 0;
173 return p + 1;
174}
Cube * p
Definition exorList.c:222
Here is the call graph for this function:

◆ kissat_parse_option_value()

bool kissat_parse_option_value ( const char * val_str,
int * res_ptr )

Definition at line 67 of file kptions.c.

67 {
68 if (!strcmp (val_str, "true")) {
69 *res_ptr = 1;
70 return true;
71 }
72 if (!strcmp (val_str, "false")) {
73 *res_ptr = 0;
74 return true;
75 }
76 int sign = 1;
77 char const *p = val_str;
78 int ch = *p++;
79 if (ch == '-') {
80 sign = -1;
81 ch = *p++;
82 }
83 if (!isdigit (ch)) // at least one digit
84 return false;
85 const unsigned max = -(unsigned) INT_MIN;
86 unsigned res = ch - '0';
87 while (isdigit ((ch = *p++))) {
88 if (max / 10 < res)
89 return false;
90 res *= 10;
91 const unsigned digit = ch - '0';
92 if (max - digit < res)
93 return false;
94 res += digit;
95 if (!res)
96 return false; // invalid '00'
97 }
98 if (ch == 'e') // parse '13e5' etc.
99 {
100 if (!isdigit ((ch = *p++))) // at least one digit
101 return false;
102 if (res) {
103 if (*p) // exactly one digit
104 return false;
105 const unsigned digit = ch - '0';
106 for (unsigned i = 0; i < digit; i++) {
107 if (max / 10 < res)
108 return false;
109 res *= 10;
110 }
111 } else // parse '0^123123123' etc.
112 {
113 while (isdigit (ch = *p++)) // arbitrary many digits
114 ;
115 if (ch)
116 return false;
117 }
118 } else if (ch == '^') // parse '2^11' etc.
119 {
120 const unsigned base = res;
121 if (!isdigit ((ch = *p++))) // at least one digit
122 return false;
123 unsigned exp = ch - '0';
124 if (base < 2) // parse '0^123123123' etc.
125 {
126 while (isdigit (ch = *p++)) // arbitrary many digits
127 ;
128 if (ch)
129 return false;
130 } else if (isdigit (ch = *p++)) // parse '2^30' etc.
131 {
132 if (*p) // at most two digits
133 return false;
134 exp *= 10;
135 const unsigned digit = ch - '0';
136 exp += digit;
137 if (!exp) // '2^00' invalid
138 return false;
139 } else if (ch)
140 return false;
141 if (exp)
142 for (unsigned i = 1; i < exp; i++) {
143 if (max / base < res)
144 return false;
145 res *= base;
146 }
147 else if (base)
148 res = 1; // parse '3^0'
149 else
150 return false; // '0^0' invalid
151 } else if (ch)
152 return false;
153 KISSAT_assert (res <= max);
154 if (sign > 0 && res == max)
155 return false;
156 res *= sign;
157 *res_ptr = res;
158 return true;
159}
bool sign(Lit p)
Definition SolverTypes.h:63
Here is the call graph for this function:

Variable Documentation

◆ kissat_options_begin

const opt* kissat_options_begin = table

Definition at line 33 of file kptions.c.

◆ kissat_options_end

const opt* kissat_options_end = table + size_table

Definition at line 34 of file kptions.c.