ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cadical_message.cpp
Go to the documentation of this file.
1#include "global.h"
2
3#include "internal.hpp"
4
6
7namespace CaDiCaL {
8
9/*------------------------------------------------------------------------*/
10#ifndef CADICAL_QUIET
11/*------------------------------------------------------------------------*/
12
13void Internal::print_prefix () { fputs (prefix.c_str (), stdout); }
14
15void Internal::vmessage (const char *fmt, va_list &ap) {
16#ifdef LOGGING
17 if (!opts.log)
18#endif
19 if (opts.quiet)
20 return;
21 print_prefix ();
22 vprintf (fmt, ap);
23 fputc ('\n', stdout);
24 fflush (stdout);
25}
26
27void Internal::message (const char *fmt, ...) {
28 va_list ap;
29 va_start (ap, fmt);
30 vmessage (fmt, ap);
31 va_end (ap);
32}
33
34void Internal::message () {
35#ifdef LOGGING
36 if (!opts.log)
37#endif
38 if (opts.quiet)
39 return;
40 print_prefix ();
41 fputc ('\n', stdout);
42 fflush (stdout);
43}
44
45/*------------------------------------------------------------------------*/
46
47void Internal::vverbose (int level, const char *fmt, va_list &ap) {
48#ifdef LOGGING
49 if (!opts.log)
50#endif
51 if (opts.quiet || level > opts.verbose)
52 return;
53 print_prefix ();
54 vprintf (fmt, ap);
55 fputc ('\n', stdout);
56 fflush (stdout);
57}
58
59void Internal::verbose (int level, const char *fmt, ...) {
60 va_list ap;
61 va_start (ap, fmt);
62 vverbose (level, fmt, ap);
63 va_end (ap);
64}
65
66void Internal::verbose (int level) {
67#ifdef LOGGING
68 if (!opts.log)
69#endif
70 if (opts.quiet || level > opts.verbose)
71 return;
72 print_prefix ();
73 fputc ('\n', stdout);
74 fflush (stdout);
75}
76
77/*------------------------------------------------------------------------*/
78
79void Internal::section (const char *title) {
80#ifdef LOGGING
81 if (!opts.log)
82#endif
83 if (opts.quiet)
84 return;
85 if (stats.sections++)
86 MSG ();
87 print_prefix ();
88 tout.blue ();
89 fputs ("--- [ ", stdout);
90 tout.blue (true);
91 fputs (title, stdout);
92 tout.blue ();
93 fputs (" ] ", stdout);
94 for (int i = strlen (title) + strlen (prefix.c_str ()) + 9; i < 78; i++)
95 fputc ('-', stdout);
96 tout.normal ();
97 fputc ('\n', stdout);
98 MSG ();
99}
100
101/*------------------------------------------------------------------------*/
102
103void Internal::phase (const char *phase, const char *fmt, ...) {
104#ifdef LOGGING
105 if (!opts.log)
106#endif
107 if (opts.quiet || (!force_phase_messages && opts.verbose < 2))
108 return;
109 print_prefix ();
110 printf ("[%s] ", phase);
111 va_list ap;
112 va_start (ap, fmt);
113 vprintf (fmt, ap);
114 va_end (ap);
115 fputc ('\n', stdout);
116 fflush (stdout);
117}
118
119void Internal::phase (const char *phase, int64_t count, const char *fmt,
120 ...) {
121#ifdef LOGGING
122 if (!opts.log)
123#endif
124 if (opts.quiet || (!force_phase_messages && opts.verbose < 2))
125 return;
126 print_prefix ();
127 printf ("[%s-%" PRId64 "] ", phase, count);
128 va_list ap;
129 va_start (ap, fmt);
130 vprintf (fmt, ap);
131 va_end (ap);
132 fputc ('\n', stdout);
133 fflush (stdout);
134}
135
136/*------------------------------------------------------------------------*/
137#endif // ifndef CADICAL_QUIET
138/*------------------------------------------------------------------------*/
139
140void Internal::warning (const char *fmt, ...) {
141 fflush (stdout);
142 terr.bold ();
143 fputs ("cadical: ", stderr);
144 terr.red (1);
145 fputs ("warning:", stderr);
146 terr.normal ();
147 fputc (' ', stderr);
148 va_list ap;
149 va_start (ap, fmt);
150 vfprintf (stderr, fmt, ap);
151 va_end (ap);
152 fputc ('\n', stderr);
153 fflush (stderr);
154}
155
156/*------------------------------------------------------------------------*/
157
159 fflush (stdout);
160 terr.bold ();
161 fputs ("cadical: ", stderr);
162 terr.red (1);
163 fputs ("error:", stderr);
164 terr.normal ();
165 fputc (' ', stderr);
166}
167
169 fputc ('\n', stderr);
170 fflush (stderr);
171 // TODO add possibility to use call back instead.
172 exit (1);
173}
174
175void Internal::verror (const char *fmt, va_list &ap) {
177 vfprintf (stderr, fmt, ap);
179}
180
181void Internal::error (const char *fmt, ...) {
182 va_list ap;
183 va_start (ap, fmt);
184 verror (fmt, ap);
185 va_end (ap); // unreachable
186}
187
188/*------------------------------------------------------------------------*/
189
191 fflush (stdout);
192 terr.bold ();
193 fputs ("cadical: ", stderr);
194 terr.red (1);
195 fputs ("fatal error:", stderr);
196 terr.normal ();
197 fputc (' ', stderr);
198}
199
201 fputc ('\n', stderr);
202 fflush (stderr);
203 abort ();
204}
205
206void fatal (const char *fmt, ...) {
208 va_list ap;
209 va_start (ap, fmt);
210 vfprintf (stderr, fmt, ap);
211 va_end (ap);
213 abort ();
214}
215
216} // namespace CaDiCaL
217
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void blue(bool bright=false)
Definition terminal.hpp:58
void fatal()
#define vprintf
Definition fretime.h:138
#define MSG(...)
Definition message.hpp:49
void fatal_message_start()
void fatal_message_end()
Terminal terr(stderr)
Definition terminal.hpp:98
Terminal tout(stdout)
Definition terminal.hpp:97
void void error_message_start()
void error(const char *,...) CADICAL_ATTRIBUTE_FORMAT(2
void phase(int lit)
void verror(const char *, va_list &)
void warning(const char *,...) CADICAL_ATTRIBUTE_FORMAT(2
VOID_HACK abort()
int strlen()
VOID_HACK exit()