yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
log.h File Reference
#include "kernel/yosys.h"
#include <time.h>
#include <sys/time.h>
#include <sys/resource.h>
+ Include dependency graph for log.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  log_cmd_error_exception
 
struct  PerformanceTimer
 

Macros

#define S__LINE__sub2(x)   #x
 
#define S__LINE__sub1(x)   S__LINE__sub2(x)
 
#define S__LINE__   S__LINE__sub1(__LINE__)
 
#define log_abort()   YOSYS_NAMESPACE_PREFIX log_error("Abort in %s:%d.\n", __FILE__, __LINE__)
 
#define log_assert(_assert_expr_)   YOSYS_NAMESPACE_PREFIX log_assert_worker(_assert_expr_, #_assert_expr_, __FILE__, __LINE__)
 
#define log_ping()   YOSYS_NAMESPACE_PREFIX log("-- %s:%d %s --\n", __FILE__, __LINE__, __PRETTY_FUNCTION__)
 
#define cover(...)   do { } while (0)
 
#define cover_list(...)   do { } while (0)
 
#define log_dump(...)
 

Functions

void logv (const char *format, va_list ap)
 
void logv_header (const char *format, va_list ap)
 
void logv_warning (const char *format, va_list ap)
 
YS_NORETURN void logv_error (const char *format, va_list ap) YS_ATTRIBUTE(noreturn)
 
void log (const char *format,...) YS_ATTRIBUTE(format(printf
 
void void log_header (const char *format,...) YS_ATTRIBUTE(format(printf
 
void void void log_warning (const char *format,...) YS_ATTRIBUTE(format(printf
 
void void void YS_NORETURN void log_error (const char *format,...) YS_ATTRIBUTE(format(printf
 
YS_NORETURN void log_cmd_error (const char *format,...) YS_ATTRIBUTE(format(printf
 
void log_spacer ()
 
void log_push ()
 
void log_pop ()
 
void log_reset_stack ()
 
void log_flush ()
 
const char * log_signal (const RTLIL::SigSpec &sig, bool autoint=true)
 
const char * log_id (RTLIL::IdString id)
 
template<typename T >
static const char * log_id (T *obj)
 
void log_cell (RTLIL::Cell *cell, std::string indent="")
 
static void log_assert_worker (bool cond, const char *expr, const char *file, int line)
 
static void log_dump_val_worker (short v)
 
static void log_dump_val_worker (unsigned short v)
 
static void log_dump_val_worker (int v)
 
static void log_dump_val_worker (unsigned int v)
 
static void log_dump_val_worker (long int v)
 
static void log_dump_val_worker (unsigned long int v)
 
static void log_dump_val_worker (long long int v)
 
static void log_dump_val_worker (unsigned long long int v)
 
static void log_dump_val_worker (char c)
 
static void log_dump_val_worker (unsigned char c)
 
static void log_dump_val_worker (bool v)
 
static void log_dump_val_worker (double v)
 
static void log_dump_val_worker (char *v)
 
static void log_dump_val_worker (const char *v)
 
static void log_dump_val_worker (std::string v)
 
static void log_dump_val_worker (PerformanceTimer p)
 
static void log_dump_args_worker (const char *p)
 
void log_dump_val_worker (RTLIL::SigSpec v)
 
template<typename T >
static void log_dump_val_worker (T *ptr)
 
template<typename T , typename... Args>
void log_dump_args_worker (const char *p, T first, Args...args)
 

Variables

std::vector< FILE * > log_files
 
std::vector< std::ostream * > log_streams
 
FILE * log_errfile
 
SHA1log_hasher
 
bool log_time
 
bool log_cmd_error_throw
 
bool log_quiet_warnings
 
int log_verbose_level
 
void void void YS_NORETURN void noreturn
 

Macro Definition Documentation

#define cover (   ...)    do { } while (0)

Definition at line 131 of file log.h.

#define cover_list (   ...)    do { } while (0)

Definition at line 132 of file log.h.

#define log_abort ( )    YOSYS_NAMESPACE_PREFIX log_error("Abort in %s:%d.\n", __FILE__, __LINE__)

Definition at line 84 of file log.h.

#define log_assert (   _assert_expr_)    YOSYS_NAMESPACE_PREFIX log_assert_worker(_assert_expr_, #_assert_expr_, __FILE__, __LINE__)

Definition at line 85 of file log.h.

#define log_dump (   ...)
Value:
do { \
log("DEBUG DUMP IN %s AT %s:%d:", __PRETTY_FUNCTION__, __FILE__, __LINE__); \
log_dump_args_worker(#__VA_ARGS__, __VA_ARGS__); \
log("\n"); \
} while (0)
void log(const char *format,...) YS_ATTRIBUTE(format(printf
static void log_dump_args_worker(const char *p)
Definition: log.h:217

Definition at line 257 of file log.h.

#define log_ping ( )    YOSYS_NAMESPACE_PREFIX log("-- %s:%d %s --\n", __FILE__, __LINE__, __PRETTY_FUNCTION__)

Definition at line 86 of file log.h.

#define S__LINE__   S__LINE__sub1(__LINE__)

Definition at line 39 of file log.h.

#define S__LINE__sub1 (   x)    S__LINE__sub2(x)

Definition at line 38 of file log.h.

#define S__LINE__sub2 (   x)    #x

Definition at line 37 of file log.h.

Function Documentation

void log ( const char *  format,
  ... 
)

+ Here is the caller graph for this function:

static void log_assert_worker ( bool  cond,
const char *  expr,
const char *  file,
int  line 
)
inlinestatic

Definition at line 80 of file log.h.

80  {
81  if (!cond) log_error("Assert `%s' failed in %s:%d.\n", expr, file, line);
82 }
void void void YS_NORETURN void log_error(const char *format,...) YS_ATTRIBUTE(format(printf

+ Here is the call graph for this function:

void log_cell ( RTLIL::Cell cell,
std::string  indent = "" 
)

Definition at line 292 of file log.cc.

293 {
294  std::stringstream buf;
295  ILANG_BACKEND::dump_cell(buf, indent, cell);
296  log("%s", buf.str().c_str());
297 }
void dump_cell(std::ostream &f, std::string indent, const RTLIL::Cell *cell)
void log(const char *format,...)
Definition: log.cc:180

+ Here is the call graph for this function:

YS_NORETURN void log_cmd_error ( const char *  format,
  ... 
)

+ Here is the caller graph for this function:

static void log_dump_args_worker ( const char *  p)
inlinestatic

Definition at line 217 of file log.h.

217 { log_assert(*p == 0); }
#define log_assert(_assert_expr_)
Definition: log.h:85

+ Here is the caller graph for this function:

template<typename T , typename... Args>
void log_dump_args_worker ( const char *  p,
first,
Args...  args 
)

Definition at line 224 of file log.h.

225 {
226  int next_p_state = 0;
227  const char *next_p = p;
228  while (*next_p && (next_p_state != 0 || *next_p != ',')) {
229  if (*next_p == '"')
230  do {
231  next_p++;
232  while (*next_p == '\\' && *(next_p + 1))
233  next_p += 2;
234  } while (*next_p && *next_p != '"');
235  if (*next_p == '\'') {
236  next_p++;
237  if (*next_p == '\\')
238  next_p++;
239  if (*next_p)
240  next_p++;
241  }
242  if (*next_p == '(' || *next_p == '[' || *next_p == '{')
243  next_p_state++;
244  if ((*next_p == ')' || *next_p == ']' || *next_p == '}') && next_p_state > 0)
245  next_p_state--;
246  next_p++;
247  }
248  log("\n\t%.*s => ", int(next_p - p), p);
249  if (*next_p == ',')
250  next_p++;
251  while (*next_p == ' ' || *next_p == '\t' || *next_p == '\r' || *next_p == '\n')
252  next_p++;
253  log_dump_val_worker(first);
254  log_dump_args_worker(next_p, args ...);
255 }
static void log_dump_val_worker(short v)
Definition: log.h:199
void log(const char *format,...) YS_ATTRIBUTE(format(printf
static void log_dump_args_worker(const char *p)
Definition: log.h:217

+ Here is the call graph for this function:

static void log_dump_val_worker ( short  v)
inlinestatic

Definition at line 199 of file log.h.

199 { log("%d", v); }
void log(const char *format,...) YS_ATTRIBUTE(format(printf

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void log_dump_val_worker ( unsigned short  v)
inlinestatic

Definition at line 200 of file log.h.

200 { log("%u", v); }
void log(const char *format,...) YS_ATTRIBUTE(format(printf

+ Here is the call graph for this function:

static void log_dump_val_worker ( int  v)
inlinestatic

Definition at line 201 of file log.h.

201 { log("%d", v); }
void log(const char *format,...) YS_ATTRIBUTE(format(printf

+ Here is the call graph for this function:

static void log_dump_val_worker ( unsigned int  v)
inlinestatic

Definition at line 202 of file log.h.

202 { log("%u", v); }
void log(const char *format,...) YS_ATTRIBUTE(format(printf

+ Here is the call graph for this function:

static void log_dump_val_worker ( long int  v)
inlinestatic

Definition at line 203 of file log.h.

203 { log("%ld", v); }
void log(const char *format,...) YS_ATTRIBUTE(format(printf

+ Here is the call graph for this function:

static void log_dump_val_worker ( unsigned long int  v)
inlinestatic

Definition at line 204 of file log.h.

204 { log("%lu", v); }
void log(const char *format,...) YS_ATTRIBUTE(format(printf

+ Here is the call graph for this function:

static void log_dump_val_worker ( long long int  v)
inlinestatic

Definition at line 206 of file log.h.

206 { log("%lld", v); }
void log(const char *format,...) YS_ATTRIBUTE(format(printf

+ Here is the call graph for this function:

static void log_dump_val_worker ( unsigned long long int  v)
inlinestatic

Definition at line 207 of file log.h.

207 { log("%lld", v); }
void log(const char *format,...) YS_ATTRIBUTE(format(printf

+ Here is the call graph for this function:

static void log_dump_val_worker ( char  c)
inlinestatic

Definition at line 209 of file log.h.

209 { log(c >= 32 && c < 127 ? "'%c'" : "'\\x%02x'", c); }
void log(const char *format,...) YS_ATTRIBUTE(format(printf

+ Here is the call graph for this function:

static void log_dump_val_worker ( unsigned char  c)
inlinestatic

Definition at line 210 of file log.h.

210 { log(c >= 32 && c < 127 ? "'%c'" : "'\\x%02x'", c); }
void log(const char *format,...) YS_ATTRIBUTE(format(printf

+ Here is the call graph for this function:

static void log_dump_val_worker ( bool  v)
inlinestatic

Definition at line 211 of file log.h.

211 { log("%s", v ? "true" : "false"); }
void log(const char *format,...) YS_ATTRIBUTE(format(printf

+ Here is the call graph for this function:

static void log_dump_val_worker ( double  v)
inlinestatic

Definition at line 212 of file log.h.

212 { log("%f", v); }
void log(const char *format,...) YS_ATTRIBUTE(format(printf

+ Here is the call graph for this function:

static void log_dump_val_worker ( char *  v)
inlinestatic

Definition at line 213 of file log.h.

213 { log("%s", v); }
void log(const char *format,...) YS_ATTRIBUTE(format(printf

+ Here is the call graph for this function:

static void log_dump_val_worker ( const char *  v)
inlinestatic

Definition at line 214 of file log.h.

214 { log("%s", v); }
void log(const char *format,...) YS_ATTRIBUTE(format(printf

+ Here is the call graph for this function:

static void log_dump_val_worker ( std::string  v)
inlinestatic

Definition at line 215 of file log.h.

215 { log("%s", v.c_str()); }
void log(const char *format,...) YS_ATTRIBUTE(format(printf

+ Here is the call graph for this function:

static void log_dump_val_worker ( PerformanceTimer  p)
inlinestatic

Definition at line 216 of file log.h.

216 { log("%f seconds", p.sec()); }
void log(const char *format,...) YS_ATTRIBUTE(format(printf
float sec() const
Definition: log.h:185

+ Here is the call graph for this function:

void log_dump_val_worker ( RTLIL::SigSpec  v)

Definition at line 265 of file log.cc.

265  {
266  log("%s", log_signal(v));
267 }
const char * log_signal(const RTLIL::SigSpec &sig, bool autoint)
Definition: log.cc:269
void log(const char *format,...)
Definition: log.cc:180

+ Here is the call graph for this function:

template<typename T >
static void log_dump_val_worker ( T *  ptr)
inlinestatic

Definition at line 221 of file log.h.

221 { log("%p", ptr); }
void log(const char *format,...) YS_ATTRIBUTE(format(printf

+ Here is the call graph for this function:

void void void YS_NORETURN void log_error ( const char *  format,
  ... 
)

+ Here is the caller graph for this function:

void log_flush ( )

Definition at line 256 of file log.cc.

257 {
258  for (auto f : log_files)
259  fflush(f);
260 
261  for (auto f : log_streams)
262  f->flush();
263 }
std::vector< std::ostream * > log_streams
Definition: log.cc:38
YOSYS_NAMESPACE_BEGIN std::vector< FILE * > log_files
Definition: log.cc:37

+ Here is the caller graph for this function:

void void log_header ( const char *  format,
  ... 
)
const char* log_id ( RTLIL::IdString  id)

Definition at line 283 of file log.cc.

284 {
285  log_id_cache.insert(str);
286  const char *p = str.c_str();
287  if (p[0] == '\\' && p[1] != '$' && p[1] != 0)
288  return p+1;
289  return p;
290 }
std::set< RTLIL::IdString > log_id_cache
Definition: log.cc:48

+ Here is the call graph for this function:

template<typename T >
static const char* log_id ( T *  obj)
inlinestatic

Definition at line 74 of file log.h.

74  {
75  return log_id(obj->name);
76 }
const char * log_id(RTLIL::IdString id)
Definition: log.cc:283

+ Here is the call graph for this function:

void log_pop ( )

Definition at line 237 of file log.cc.

238 {
239  header_count.pop_back();
240  log_id_cache.clear();
241  string_buf.clear();
242  string_buf_size = 0;
243  log_flush();
244 }
std::set< RTLIL::IdString > log_id_cache
Definition: log.cc:48
std::list< std::string > string_buf
Definition: log.cc:49
int string_buf_size
Definition: log.cc:50
void log_flush()
Definition: log.cc:256
std::vector< int > header_count
Definition: log.cc:47

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void log_push ( )

Definition at line 232 of file log.cc.

233 {
234  header_count.push_back(0);
235 }
std::vector< int > header_count
Definition: log.cc:47

+ Here is the caller graph for this function:

void log_reset_stack ( )

Definition at line 246 of file log.cc.

247 {
248  while (header_count.size() > 1)
249  header_count.pop_back();
250  log_id_cache.clear();
251  string_buf.clear();
252  string_buf_size = 0;
253  log_flush();
254 }
std::set< RTLIL::IdString > log_id_cache
Definition: log.cc:48
std::list< std::string > string_buf
Definition: log.cc:49
int string_buf_size
Definition: log.cc:50
void log_flush()
Definition: log.cc:256
std::vector< int > header_count
Definition: log.cc:47

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const char* log_signal ( const RTLIL::SigSpec sig,
bool  autoint = true 
)

Definition at line 269 of file log.cc.

270 {
271  std::stringstream buf;
272  ILANG_BACKEND::dump_sigspec(buf, sig, autoint);
273 
274  if (string_buf_size < 100)
275  string_buf_size++;
276  else
277  string_buf.pop_front();
278  string_buf.push_back(buf.str());
279 
280  return string_buf.back().c_str();
281 }
std::list< std::string > string_buf
Definition: log.cc:49
int string_buf_size
Definition: log.cc:50
void dump_sigspec(std::ostream &f, const RTLIL::SigSpec &sig, bool autoint=true)

+ Here is the call graph for this function:

void log_spacer ( )

Definition at line 226 of file log.cc.

227 {
228  while (log_newline_count < 2)
229  log("\n");
230 }
static int log_newline_count
Definition: log.cc:54
void log(const char *format,...)
Definition: log.cc:180

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void void void log_warning ( const char *  format,
  ... 
)
void logv ( const char *  format,
va_list  ap 
)

Definition at line 76 of file log.cc.

77 {
78  while (format[0] == '\n' && format[1] != 0) {
79  log("\n");
80  format++;
81  }
82 
83  std::string str = vstringf(format, ap);
84 
85  if (str.empty())
86  return;
87 
88  size_t nnl_pos = str.find_last_not_of('\n');
89  if (nnl_pos == std::string::npos)
90  log_newline_count += GetSize(str);
91  else
92  log_newline_count = GetSize(str) - nnl_pos - 1;
93 
94  if (log_hasher)
95  log_hasher->update(str);
96 
97  if (log_time)
98  {
99  std::string time_str;
100 
101  if (next_print_log || initial_tv.tv_sec == 0) {
102  next_print_log = false;
103  struct timeval tv;
104  gettimeofday(&tv, NULL);
105  if (initial_tv.tv_sec == 0)
106  initial_tv = tv;
107  if (tv.tv_usec < initial_tv.tv_usec) {
108  tv.tv_sec--;
109  tv.tv_usec += 1000000;
110  }
111  tv.tv_sec -= initial_tv.tv_sec;
112  tv.tv_usec -= initial_tv.tv_usec;
113  time_str += stringf("[%05d.%06d] ", int(tv.tv_sec), int(tv.tv_usec));
114  }
115 
116  if (format[0] && format[strlen(format)-1] == '\n')
117  next_print_log = true;
118 
119  for (auto f : log_files)
120  fputs(time_str.c_str(), f);
121 
122  for (auto f : log_streams)
123  *f << time_str;
124  }
125 
126  for (auto f : log_files)
127  fputs(str.c_str(), f);
128 
129  for (auto f : log_streams)
130  *f << str;
131 }
std::string stringf(const char *fmt,...)
Definition: yosys.cc:58
bool log_time
Definition: log.cc:42
static struct timeval initial_tv
Definition: log.cc:52
std::vector< std::ostream * > log_streams
Definition: log.cc:38
static int log_newline_count
Definition: log.cc:54
SHA1 * log_hasher
Definition: log.cc:40
YOSYS_NAMESPACE_BEGIN std::vector< FILE * > log_files
Definition: log.cc:37
std::string vstringf(const char *fmt, va_list ap)
Definition: yosys.cc:70
int GetSize(RTLIL::Wire *wire)
Definition: yosys.cc:334
#define NULL
void log(const char *format,...)
Definition: log.cc:180
void update(const std::string &s)
Definition: sha1.cpp:42
static bool next_print_log
Definition: log.cc:53

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

YS_NORETURN void logv_error ( const char *  format,
va_list  ap 
)

Definition at line 169 of file log.cc.

170 {
171  if (log_errfile != NULL)
172  log_files.push_back(log_errfile);
173 
174  log("ERROR: ");
175  logv(format, ap);
176  log_flush();
177  exit(1);
178 }
FILE * log_errfile
Definition: log.cc:39
YOSYS_NAMESPACE_BEGIN std::vector< FILE * > log_files
Definition: log.cc:37
void log_flush()
Definition: log.cc:256
#define NULL
void log(const char *format,...)
Definition: log.cc:180
void logv(const char *format, va_list ap)
Definition: log.cc:76

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void logv_header ( const char *  format,
va_list  ap 
)

Definition at line 133 of file log.cc.

134 {
135  bool pop_errfile = false;
136 
137  log_spacer();
138  if (header_count.size() > 0)
139  header_count.back()++;
140 
141  if (int(header_count.size()) <= log_verbose_level && log_errfile != NULL) {
142  log_files.push_back(log_errfile);
143  pop_errfile = true;
144  }
145 
146  for (int c : header_count)
147  log("%d.", c);
148  log(" ");
149  logv(format, ap);
150  log_flush();
151 
152  if (pop_errfile)
153  log_files.pop_back();
154 }
FILE * log_errfile
Definition: log.cc:39
YOSYS_NAMESPACE_BEGIN std::vector< FILE * > log_files
Definition: log.cc:37
void log_flush()
Definition: log.cc:256
int log_verbose_level
Definition: log.cc:45
std::vector< int > header_count
Definition: log.cc:47
#define NULL
void log(const char *format,...)
Definition: log.cc:180
void logv(const char *format, va_list ap)
Definition: log.cc:76
void log_spacer()
Definition: log.cc:226

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void logv_warning ( const char *  format,
va_list  ap 
)

Definition at line 156 of file log.cc.

157 {
159  log_files.push_back(log_errfile);
160 
161  log("Warning: ");
162  logv(format, ap);
163  log_flush();
164 
166  log_files.pop_back();
167 }
FILE * log_errfile
Definition: log.cc:39
YOSYS_NAMESPACE_BEGIN std::vector< FILE * > log_files
Definition: log.cc:37
void log_flush()
Definition: log.cc:256
#define NULL
void log(const char *format,...)
Definition: log.cc:180
void logv(const char *format, va_list ap)
Definition: log.cc:76
bool log_quiet_warnings
Definition: log.cc:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

bool log_cmd_error_throw

Definition at line 43 of file log.cc.

FILE* log_errfile

Definition at line 39 of file log.cc.

std::vector<FILE*> log_files

Definition at line 37 of file log.cc.

SHA1* log_hasher

Definition at line 40 of file log.cc.

bool log_quiet_warnings

Definition at line 44 of file log.cc.

std::vector<std::ostream*> log_streams

Definition at line 38 of file log.cc.

bool log_time

Definition at line 42 of file log.cc.

int log_verbose_level

Definition at line 45 of file log.cc.

YS_NORETURN void noreturn

Definition at line 61 of file log.h.