-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlogging.c
77 lines (68 loc) · 2.17 KB
/
logging.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "logging.h"
#include "ring.h"
#include "ruler.h"
#include "utilities.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
bool ignore_values_and_levels_during_logging;
static char loglitbuf[8][64];
static unsigned loglitpos;
#define loglitsize (sizeof loglitbuf / sizeof *loglitbuf)
static char *next_loglitbuf (void) {
char *res = loglitbuf[loglitpos++];
if (loglitpos == loglitsize)
loglitpos = 0;
return res;
}
const char *loglit (struct ring *ring, unsigned unsigned_lit) {
char *res = next_loglitbuf ();
int signed_lit =
unmap_and_export_literal (ring->ruler->unmap, unsigned_lit);
sprintf (res, "%u(%d)", unsigned_lit, signed_lit);
if (!ignore_values_and_levels_during_logging) {
signed char *values = ring->values;
if (values) {
signed char value = values[unsigned_lit];
if (value) {
sprintf (res + strlen (res), "=%d", (int) value);
if (ring->variables) {
struct variable *v = VAR (unsigned_lit);
if (v->level != INVALID)
sprintf (res + strlen (res), "@%u", v->level);
}
}
}
}
assert (strlen (res) + 1 < sizeof *loglitbuf);
return res;
}
const char *logvar (struct ring *ring, unsigned idx) {
unsigned lit = LIT (idx);
const char *tmp = loglit (ring, lit);
char *res = next_loglitbuf ();
sprintf (res, "variable %u(%u) (literal %s)", idx, idx + 1, tmp);
return res;
}
const char *roglit (struct ruler *ruler, unsigned unsigned_lit) {
char *res = next_loglitbuf ();
int signed_lit = unmap_and_export_literal (ruler->unmap, unsigned_lit);
sprintf (res, "%u(%d)", unsigned_lit, signed_lit);
if (!ignore_values_and_levels_during_logging) {
signed char *values = (signed char *) ruler->values;
if (values) {
signed char value = values[unsigned_lit];
if (value)
sprintf (res + strlen (res), "=%d", (int) value);
}
}
assert (strlen (res) + 1 < sizeof *loglitbuf);
return res;
}
const char *rogvar (struct ruler *ruler, unsigned idx) {
unsigned lit = LIT (idx);
const char *tmp = roglit (ruler, lit);
char *res = next_loglitbuf ();
sprintf (res, "variable %u(%u) (literal %s)", idx, idx + 1, tmp);
return res;
}