Skip to content

Commit 383c16b

Browse files
authored
Merge pull request #380 from MyskYko/kissat
support debug mode
2 parents cab003b + 8fb9fc5 commit 383c16b

File tree

7 files changed

+64
-22
lines changed

7 files changed

+64
-22
lines changed

src/sat/kissat/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4.0.2

src/sat/kissat/check.c

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#undef LOGPREFIX
1717
#define LOGPREFIX "CHECK"
1818

19+
ABC_NAMESPACE_IMPL_START
20+
1921
void kissat_check_satisfying_assignment (kissat *solver) {
2022
LOG ("checking satisfying assignment");
2123
const int *const begin = BEGIN_STACK (solver->original);
@@ -51,16 +53,20 @@ void kissat_check_satisfying_assignment (kissat *solver) {
5153
LOG ("assignment satisfies all %zu original clauses", count);
5254
}
5355

56+
ABC_NAMESPACE_IMPL_END
57+
5458
#include "allocate.h"
5559
#include "inline.h"
5660
#include "sort.h"
5761

62+
ABC_NAMESPACE_IMPL_START
63+
5864
typedef struct hash hash;
5965
typedef struct bucket bucket;
6066

6167
// clang-format off
6268

63-
typedef STACK (bucket*) buckets;
69+
typedef STACK (bucket*) buckets_;
6470

6571
// clang-format on
6672

@@ -82,7 +88,7 @@ struct checker {
8288

8389
bucket **table;
8490

85-
buckets *watches;
91+
buckets_ *watches;
8692
bool *marks;
8793
bool *large;
8894
bool *used;
@@ -151,7 +157,7 @@ static void init_nonces (kissat *solver, checker *checker) {
151157

152158
void kissat_init_checker (kissat *solver) {
153159
LOG ("initializing internal proof checker");
154-
checker *checker = kissat_calloc (solver, 1, sizeof (struct checker));
160+
checker *checker = (struct checker*)kissat_calloc (solver, 1, sizeof (struct checker));
155161
solver->checker = checker;
156162
init_nonces (solver, checker);
157163
}
@@ -172,7 +178,7 @@ static void release_watches (kissat *solver, checker *checker) {
172178
for (unsigned i = 0; i < lits; i++)
173179
RELEASE_STACK (checker->watches[i]);
174180
kissat_dealloc (solver, checker->watches, 2 * checker->size,
175-
sizeof (buckets));
181+
sizeof (buckets_));
176182
}
177183

178184
void kissat_release_checker (kissat *solver) {
@@ -191,8 +197,12 @@ void kissat_release_checker (kissat *solver) {
191197

192198
#ifndef KISSAT_QUIET
193199

200+
ABC_NAMESPACE_IMPL_END
201+
194202
#include <inttypes.h>
195203

204+
ABC_NAMESPACE_IMPL_START
205+
196206
#define PERCENT_ADDED(NAME) kissat_percent (checker->NAME, checker->added)
197207
#define PERCENT_CHECKED(NAME) \
198208
kissat_percent (checker->NAME, checker->checked)
@@ -249,7 +259,7 @@ static void resize_hash (kissat *solver, checker *checker) {
249259
const unsigned old_hashed = checker->hashed;
250260
KISSAT_assert (old_hashed < MAX_SIZE);
251261
const unsigned new_hashed = old_hashed ? 2 * old_hashed : 1;
252-
bucket **table = kissat_calloc (solver, new_hashed, sizeof (bucket *));
262+
bucket **table = (bucket**) kissat_calloc (solver, new_hashed, sizeof (bucket *));
253263
bucket **old_table = checker->table;
254264
for (unsigned i = 0; i < old_hashed; i++) {
255265
for (bucket *bucket = old_table[i], *next; bucket; bucket = next) {
@@ -303,22 +313,22 @@ static void checker_assign (kissat *solver, checker *checker, unsigned lit,
303313
PUSH_STACK (checker->trail, lit);
304314
}
305315

306-
static buckets *checker_watches (checker *checker, unsigned lit) {
316+
static buckets_ *checker_watches (checker *checker, unsigned lit) {
307317
KISSAT_assert (VALID_CHECKER_LIT (lit));
308318
return checker->watches + lit;
309319
}
310320

311321
static void watch_checker_literal (kissat *solver, checker *checker,
312322
bucket *bucket, unsigned lit) {
313323
LOGLINE3 ("checker watches %u in", lit);
314-
buckets *buckets = checker_watches (checker, lit);
324+
buckets_ *buckets = checker_watches (checker, lit);
315325
PUSH_STACK (*buckets, bucket);
316326
}
317327

318328
static void unwatch_checker_literal (kissat *solver, checker *checker,
319329
bucket *bucket, unsigned lit) {
320330
LOGLINE3 ("checker unwatches %u in", lit);
321-
buckets *buckets = checker_watches (checker, lit);
331+
buckets_ *buckets = checker_watches (checker, lit);
322332
REMOVE_STACK (struct bucket *, *buckets, bucket);
323333
#ifndef LOGGING
324334
(void) solver;
@@ -535,15 +545,15 @@ static void resize_checker (kissat *solver, checker *checker,
535545
LOG3 ("resizing checker form %u to %u", size, new_size);
536546
const unsigned size2 = 2 * size;
537547
const unsigned new_size2 = 2 * new_size;
538-
checker->marks = kissat_realloc (solver, checker->marks, size2,
548+
checker->marks = (bool*)kissat_realloc (solver, checker->marks, size2,
539549
new_size2 * sizeof (bool));
540-
checker->used = kissat_realloc (solver, checker->used, size2,
550+
checker->used = (bool*)kissat_realloc (solver, checker->used, size2,
541551
new_size2 * sizeof (bool));
542-
checker->large = kissat_realloc (solver, checker->large, size2,
552+
checker->large = (bool*)kissat_realloc (solver, checker->large, size2,
543553
new_size2 * sizeof (bool));
544554
checker->values =
545-
kissat_realloc (solver, checker->values, size2, new_size2);
546-
checker->watches = kissat_realloc (
555+
(signed char *)kissat_realloc (solver, checker->values, size2, new_size2);
556+
checker->watches = (buckets_*)kissat_realloc (
547557
solver, checker->watches, size2 * sizeof *checker->watches,
548558
new_size2 * sizeof *checker->watches);
549559
checker->size = new_size;
@@ -685,7 +695,7 @@ static bool checker_propagate (kissat *solver, checker *checker) {
685695
KISSAT_assert (values[lit] > 0);
686696
KISSAT_assert (values[not_lit] < 0);
687697
propagated++;
688-
buckets *buckets = checker_watches (checker, not_lit);
698+
buckets_ *buckets = checker_watches (checker, not_lit);
689699
bucket **begin_of_lines = BEGIN_STACK (*buckets), **q = begin_of_lines;
690700
bucket *const *end_of_lines = END_STACK (*buckets), *const *p = q;
691701
while (p != end_of_lines) {
@@ -793,7 +803,7 @@ static bool checker_blocked_literal (kissat *solver, checker *checker,
793803
const unsigned not_lit = lit ^ 1;
794804
if (checker->large[not_lit])
795805
return false;
796-
buckets *buckets = checker_watches (checker, not_lit);
806+
buckets_ *buckets = checker_watches (checker, not_lit);
797807
bucket *const *const begin_of_lines = BEGIN_STACK (*buckets);
798808
bucket *const *const end_of_lines = END_STACK (*buckets);
799809
bucket *const *p = begin_of_lines;
@@ -1030,6 +1040,11 @@ void dump_checker (kissat *solver) {
10301040
dump_line (bucket);
10311041
}
10321042

1043+
ABC_NAMESPACE_IMPL_END
1044+
10331045
#else
1046+
ABC_NAMESPACE_IMPL_START
10341047
int kissat_check_dummy_to_avoid_warning;
1048+
ABC_NAMESPACE_IMPL_END
10351049
#endif
1050+

src/sat/kissat/definition.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static void traverse_one_sided_core_lemma (void *state, bool learned,
5757
const unsigned *lits) {
5858
if (!learned)
5959
return;
60-
lemma_extractor *extractor = state;
60+
lemma_extractor *extractor = (lemma_extractor*)state;
6161
kissat *solver = extractor->solver;
6262
const unsigned unit = extractor->unit;
6363
unsigneds *added = &solver->added;

src/sat/kissat/dump.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include <inttypes.h>
88

9+
ABC_NAMESPACE_IMPL_START
10+
911
static void dump_literal (kissat *solver, unsigned ilit) {
1012
const int elit = kissat_export_literal (solver, ilit);
1113
printf ("%u(%d)", ilit, elit);
@@ -279,17 +281,21 @@ int kissat_dump (kissat *solver) {
279281
else
280282
dump_queue (solver);
281283
dump_values (solver);
282-
printf ("binary = %" PRIu64 "\n", solver->statistics.clauses_binary);
284+
printf ("binary = %" PRIu64 "\n", solver->statistics_.clauses_binary);
283285
printf ("irredundant = %" PRIu64 "\n",
284-
solver->statistics.clauses_irredundant);
286+
solver->statistics_.clauses_irredundant);
285287
printf ("redundant = %" PRIu64 "\n",
286-
solver->statistics.clauses_redundant);
288+
solver->statistics_.clauses_redundant);
287289
dump_binaries (solver);
288290
dump_clauses (solver);
289291
dump_extend (solver);
290292
return 0;
291293
}
292294

295+
ABC_NAMESPACE_IMPL_END
296+
293297
#else
298+
ABC_NAMESPACE_IMPL_START
294299
int kissat_dump_dummy_to_avoid_warning;
300+
ABC_NAMESPACE_IMPL_END
295301
#endif

src/sat/kissat/global.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
#ifndef ABC_SAT_KISSAT_GLOBAL_H_
22
#define ABC_SAT_KISSAT_GLOBAL_H_
33

4-
#define KISSAT_COMPACT
4+
// comment out next line to enable kissat debug mode
55
#define KISSAT_NDEBUG
6+
7+
#define KISSAT_COMPACT
68
#define KISSAT_NOPTIONS
79
#define KISSAT_NPROOFS
810
#define KISSAT_QUIET
911

12+
#ifdef KISSAT_NDEBUG
1013
#define KISSAT_assert(ignore) ((void)0)
14+
#else
15+
#define KISSAT_assert(cond) assert(cond)
16+
#endif
1117

1218
#include "misc/util/abc_global.h"
1319

src/sat/kissat/kimits.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static void init_enabled (kissat *solver) {
9999
} while (0)
100100

101101
void kissat_init_limits (kissat *solver) {
102-
KISSAT_assert (solver->statistics.searches == 1);
102+
KISSAT_assert (solver->statistics_.searches == 1);
103103

104104
init_enabled (solver);
105105

src/sat/kissat/statistics.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <stdio.h>
1616
#include <string.h>
1717

18+
ABC_NAMESPACE_IMPL_START
19+
1820
void kissat_print_glue_usage (kissat *solver) {
1921
const int64_t stable = solver->statistics.clauses_used_stable;
2022
const int64_t focused = solver->statistics.clauses_used_focused;
@@ -346,8 +348,16 @@ kissat_statistics_print (kissat * solver, bool verbose)
346348

347349
// clang-format on
348350

351+
ABC_NAMESPACE_IMPL_END
352+
349353
#elif defined(KISSAT_NDEBUG)
354+
355+
ABC_NAMESPACE_IMPL_START
356+
350357
int kissat_statistics_dummy_to_avoid_warning;
358+
359+
ABC_NAMESPACE_IMPL_END
360+
351361
#endif
352362

353363
/*------------------------------------------------------------------------*/
@@ -356,6 +366,8 @@ int kissat_statistics_dummy_to_avoid_warning;
356366

357367
#include "inlinevector.h"
358368

369+
ABC_NAMESPACE_IMPL_START
370+
359371
void kissat_check_statistics (kissat *solver) {
360372
if (solver->inconsistent)
361373
return;
@@ -402,7 +414,7 @@ void kissat_check_statistics (kissat *solver) {
402414
KISSAT_assert (!(binary & 1));
403415
binary /= 2;
404416

405-
statistics *statistics = &solver->statistics;
417+
statistics *statistics = &solver->statistics_;
406418
KISSAT_assert (statistics->clauses_binary == binary);
407419
KISSAT_assert (statistics->clauses_redundant == redundant);
408420
KISSAT_assert (statistics->clauses_irredundant == irredundant);
@@ -413,4 +425,6 @@ void kissat_check_statistics (kissat *solver) {
413425
#endif
414426
}
415427

428+
ABC_NAMESPACE_IMPL_END
429+
416430
#endif

0 commit comments

Comments
 (0)