ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cadical_logging.cpp
Go to the documentation of this file.
1#include "global.h"
2
3#ifdef LOGGING
4
5#include "internal.hpp"
6
8
9namespace CaDiCaL {
10
11void Logger::print_log_prefix (Internal *internal) {
12 internal->print_prefix ();
13 tout.magenta ();
14 fputs ("LOG ", stdout);
15 tout.magenta (true);
16 printf ("%d ", internal->level);
17 tout.normal ();
18}
19
20void Logger::log_empty_line (Internal *internal) {
21 internal->print_prefix ();
22 tout.magenta ();
23 const int len = internal->prefix.size (), max = 78 - len;
24 for (int i = 0; i < max; i++)
25 fputc ('-', stdout);
26 fputc ('\n', stdout);
27 tout.normal ();
28 fflush (stdout);
29}
30
31void Logger::log (Internal *internal, const char *fmt, ...) {
32 print_log_prefix (internal);
33 tout.magenta ();
34 va_list ap;
35 va_start (ap, fmt);
36 vprintf (fmt, ap);
37 va_end (ap);
38 fputc ('\n', stdout);
39 tout.normal ();
40 fflush (stdout);
41}
42
43// It is hard to factor out the common part between the two clause loggers,
44// since they are also used in slightly different contexts. Our attempt to
45// do so were not more readable than the current version. See the header
46// for an explanation of the difference between the following two functions.
47
48void Logger::log (Internal *internal, const Clause *c, const char *fmt,
49 ...) {
50 print_log_prefix (internal);
51 tout.magenta ();
52 va_list ap;
53 va_start (ap, fmt);
54 vprintf (fmt, ap);
55 va_end (ap);
56 if (c) {
57 if (c->redundant)
58 printf (" glue %d redundant", c->glue);
59 else
60 printf (" irredundant");
61 printf (" size %d clause[%" PRId64 "]", c->size, c->id);
62 if (c->moved)
63 printf (" ... (moved)");
64 else {
65 if (internal->opts.logsort) {
66 vector<int> s;
67 for (const auto &lit : *c)
68 s.push_back (lit);
69 sort (s.begin (), s.end (), clause_lit_less_than ());
70 for (const auto &lit : s)
71 printf (" %d", lit);
72 } else {
73 for (const auto &lit : *c) {
74 printf (" %s", loglit (internal, lit).c_str ());
75 }
76 }
77 }
78 } else if (internal->level)
79 printf (" decision");
80 else
81 printf (" unit");
82 fputc ('\n', stdout);
83 tout.normal ();
84 fflush (stdout);
85}
86
87void Logger::log (Internal *internal, const Gate *g, const char *fmt, ...) {
88 print_log_prefix (internal);
89 tout.magenta ();
90 va_list ap;
91 va_start (ap, fmt);
92 vprintf (fmt, ap);
93 va_end (ap);
94 if (g) {
95 printf ("%s%s%s gate[%" PRIu64 "] (arity: %ld) %s := %s",
96 g->degenerated_and_pos ? " deg+" : "",
97 g->degenerated_and_neg ? " deg-" : "",
98 g->garbage ? " garbage" : "", g->id, g->arity (),
99 loglit (internal, g->lhs).c_str (),
100 string_of_gate (g->tag).c_str ());
101 for (const auto &lit : g->rhs) {
102 printf (" %s", loglit (internal, lit).c_str ());
103 }
104 } else
105 printf (" null gate");
106 fputc ('\n', stdout);
107 tout.normal ();
108 fflush (stdout);
109}
110
111// Same as above, but for the global clause 'c' (which is not a reason).
112
113void Logger::log (Internal *internal, const vector<int> &c, const char *fmt,
114 ...) {
115 print_log_prefix (internal);
116 tout.magenta ();
117 va_list ap;
118 va_start (ap, fmt);
119 vprintf (fmt, ap);
120 va_end (ap);
121 if (internal->opts.logsort) {
122 vector<int> s;
123 for (const auto &lit : c)
124 s.push_back (lit);
125 sort (s.begin (), s.end (), clause_lit_less_than ());
126 for (const auto &lit : s)
127 printf (" %d", lit);
128 } else {
129 for (const auto &lit : c)
130 printf (" %d", lit);
131 }
132 fputc ('\n', stdout);
133 tout.normal ();
134 fflush (stdout);
135}
136
137// Now for 'restore_clause' to avoid copying (without logging).
138
139void Logger::log (Internal *internal,
140 const vector<int>::const_iterator &begin,
141 const vector<int>::const_iterator &end, const char *fmt,
142 ...) {
143 print_log_prefix (internal);
144 tout.magenta ();
145 va_list ap;
146 va_start (ap, fmt);
147 vprintf (fmt, ap);
148 va_end (ap);
149 if (internal->opts.logsort) {
150 vector<int> s;
151 for (auto p = begin; p != end; p++)
152 s.push_back (*p);
153 sort (s.begin (), s.end (), clause_lit_less_than ());
154 for (const auto &lit : s)
155 printf (" %d", lit);
156 } else {
157 for (auto p = begin; p != end; p++)
158 printf (" %d", *p);
159 }
160 fputc ('\n', stdout);
161 tout.normal ();
162 fflush (stdout);
163}
164
165// for LRAT proof chains
166
167void Logger::log (Internal *internal, const vector<int64_t> &c,
168 const char *fmt, ...) {
169 print_log_prefix (internal);
170 tout.magenta ();
171 va_list ap;
172 va_start (ap, fmt);
173 vprintf (fmt, ap);
174 va_end (ap);
175 for (const auto &id : c)
176 printf (" %" PRId64, id);
177 fputc ('\n', stdout);
178 tout.normal ();
179 fflush (stdout);
180}
181
182// for LRAT proof clauses
183
184void Logger::log (Internal *internal, const int *literals,
185 const unsigned size, const char *fmt, ...) {
186 print_log_prefix (internal);
187 tout.magenta ();
188 va_list ap;
189 va_start (ap, fmt);
190 vprintf (fmt, ap);
191 va_end (ap);
192 for (unsigned i = 0; i < size; i++) {
193 const int lit = literals[i];
194 printf (" %d", lit);
195 }
196 fputc ('\n', stdout);
197 tout.normal ();
198 fflush (stdout);
199}
200
201string Logger::loglit (Internal *internal, int lit) {
202 std::string v = std::to_string (lit);
203 if (lit && -internal->max_var <= lit && internal->max_var >= lit) {
204 const int va = internal->val (lit);
205 if (va) {
206 v = v + "@" + std::to_string (internal->var (lit).level);
207 if (!internal->var (lit).reason)
208 v = v + "+";
209 }
210 if (va > 0)
211 v += "=1";
212 else if (va < 0)
213 v += "=-1";
214 }
215 return v;
216}
217} // namespace CaDiCaL
218
220
221#endif
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Cube * p
Definition exorList.c:222
#define vprintf
Definition fretime.h:138
Terminal tout(stdout)
Definition terminal.hpp:97
std::string string_of_gate(Gate_Type t)
void sort(T *array, int size, LessThan lt)
Definition Sort.h:58
unsigned long long size
Definition giaNewBdd.h:39
int lit
Definition satVec.h:130