ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
format.c File Reference
#include "format.h"
#include <assert.h>
#include <inttypes.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for format.c:

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START char * kissat_next_format_string (kormat *format)
 
const char * kissat_format_count (kormat *format, uint64_t w)
 
const char * kissat_format_value (kormat *format, bool boolean, int value)
 
const char * kissat_format_bytes (kormat *format, uint64_t bytes)
 
const char * kissat_format_time (kormat *format, double seconds)
 
const char * kissat_format_signs (kormat *format, unsigned size, word signs)
 
const char * kissat_format_ordinal (kormat *format, uint64_t ordinal)
 

Function Documentation

◆ kissat_format_bytes()

const char * kissat_format_bytes ( kormat * format,
uint64_t bytes )

Definition at line 59 of file format.c.

59 {
60 char *res = kissat_next_format_string (format);
61 if (bytes < (1u << 10))
62 sprintf (res, "%" PRIu64 " bytes", bytes);
63 else if (bytes < (1u << 20))
64 sprintf (res, "%" PRIu64 " bytes (%" PRIu64 " KB)", bytes,
65 (bytes + (1 << 9)) >> 10);
66 else if (bytes < (1u << 30))
67 sprintf (res, "%" PRIu64 " bytes (%" PRIu64 " MB)", bytes,
68 (bytes + (1u << 19)) >> 20);
69 else
70 sprintf (res, "%" PRIu64 " bytes (%" PRIu64 " GB)", bytes,
71 (bytes + (1u << 29)) >> 30);
72 return res;
73}
ABC_NAMESPACE_IMPL_START char * kissat_next_format_string(kormat *format)
Definition format.c:12
char * sprintf()
Here is the call graph for this function:

◆ kissat_format_count()

const char * kissat_format_count ( kormat * format,
uint64_t w )

Definition at line 35 of file format.c.

35 {
36 char *res = kissat_next_format_string (format);
37 format_count (res, w);
38 return res;
39}
Here is the call graph for this function:

◆ kissat_format_ordinal()

const char * kissat_format_ordinal ( kormat * format,
uint64_t ordinal )

Definition at line 123 of file format.c.

123 {
124 char const *suffix;
125 unsigned mod100 = ordinal % 100;
126 if (10 <= mod100 && mod100 <= 19)
127 suffix = "th";
128 else {
129 switch (mod100 % 10) {
130 case 1:
131 suffix = "st";
132 break;
133 case 2:
134 suffix = "nd";
135 break;
136 case 3:
137 suffix = "rd";
138 break;
139 default:
140 suffix = "th";
141 break;
142 }
143 }
144 char *res = kissat_next_format_string (format);
145 sprintf (res, "%" PRIu64 "%s", ordinal, suffix);
146 return res;
147}
Here is the call graph for this function:

◆ kissat_format_signs()

const char * kissat_format_signs ( kormat * format,
unsigned size,
word signs )

Definition at line 111 of file format.c.

112 {
113 char *res = kissat_next_format_string (format);
115 char *p = res;
116 word bit = 1;
117 for (unsigned i = 0; i < size; i++, bit <<= 1)
118 *p++ = (bit & signs) ? '1' : '0';
119 *p = 0;
120 return res;
121}
Cube * p
Definition exorList.c:222
#define FORMAT_STRING_SIZE
Definition format.h:13
#define KISSAT_assert(ignore)
Definition global.h:13
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
unsigned long long size
Definition giaNewBdd.h:39
Here is the call graph for this function:

◆ kissat_format_time()

const char * kissat_format_time ( kormat * format,
double seconds )

Definition at line 75 of file format.c.

75 {
76 if (!seconds)
77 return "0s";
78 char *res = kissat_next_format_string (format);
79 uint64_t rounded = round (seconds);
80 uint64_t minutes = rounded / 60;
81 rounded %= 60;
82 uint64_t hours = minutes / 60;
83 minutes %= 60;
84 uint64_t days = hours / 24;
85 hours %= 24;
86 char *tmp = res;
87 if (days) {
88 sprintf (res, "%" PRIu64 "d", days);
89 tmp += strlen (res);
90 }
91 if (hours) {
92 if (tmp != res)
93 *tmp++ = ' ';
94 sprintf (tmp, "%" PRIu64 "h", hours);
95 tmp += strlen (tmp);
96 }
97 if (minutes) {
98 if (tmp != res)
99 *tmp++ = ' ';
100 sprintf (tmp, "%" PRIu64 "m", minutes);
101 tmp += strlen (tmp);
102 }
103 if (rounded) {
104 if (tmp != res)
105 *tmp++ = ' ';
106 sprintf (tmp, "%" PRIu64 "s", rounded);
107 }
108 return res;
109}
int strlen()
Here is the call graph for this function:

◆ kissat_format_value()

const char * kissat_format_value ( kormat * format,
bool boolean,
int value )

Definition at line 41 of file format.c.

41 {
42 if (boolean && value)
43 return "true";
44 if (boolean && !value)
45 return "false";
46 if (value == INT_MAX)
47 return "INT_MAX";
48 if (value == INT_MIN)
49 return "INT_MIN";
50 char *res = kissat_next_format_string (format);
51 if (value < 0) {
52 *res = '-';
53 format_count (res + 1, ABS (value));
54 } else
55 format_count (res, value);
56 return res;
57}
ABC_NAMESPACE_IMPL_START typedef signed char value
#define ABS(a)
Definition util_old.h:250
Here is the call graph for this function:

◆ kissat_next_format_string()

ABC_NAMESPACE_IMPL_START char * kissat_next_format_string ( kormat * format)

Definition at line 12 of file format.c.

12 {
14 char *res = format->str[format->pos++];
15 if (format->pos == NUM_FORMAT_STRINGS)
16 format->pos = 0;
17 return res;
18}
#define NUM_FORMAT_STRINGS
Definition format.h:12
unsigned pos
Definition format.h:18
char str[NUM_FORMAT_STRINGS][FORMAT_STRING_SIZE]
Definition format.h:19
Here is the caller graph for this function: