yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
log.cc File Reference
#include "kernel/yosys.h"
#include "libs/sha1/sha1.h"
#include "backends/ilang/ilang_backend.h"
#include <sys/time.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <vector>
#include <list>
+ Include dependency graph for log.cc:

Go to the source code of this file.

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)
 
void logv_error (const char *format, va_list ap)
 
void log (const char *format,...)
 
void log_header (const char *format,...)
 
void log_warning (const char *format,...)
 
void log_error (const char *format,...)
 
void log_cmd_error (const char *format,...)
 
void log_spacer ()
 
void log_push ()
 
void log_pop ()
 
void log_reset_stack ()
 
void log_flush ()
 
void log_dump_val_worker (RTLIL::SigSpec v)
 
const char * log_signal (const RTLIL::SigSpec &sig, bool autoint)
 
const char * log_id (RTLIL::IdString str)
 
void log_cell (RTLIL::Cell *cell, std::string indent)
 

Variables

YOSYS_NAMESPACE_BEGIN
std::vector< FILE * > 
log_files
 
std::vector< std::ostream * > log_streams
 
FILE * log_errfile = NULL
 
SHA1log_hasher = NULL
 
bool log_time = false
 
bool log_cmd_error_throw = false
 
bool log_quiet_warnings = false
 
int log_verbose_level
 
std::vector< int > header_count
 
std::set< RTLIL::IdStringlog_id_cache
 
std::list< std::string > string_buf
 
int string_buf_size = 0
 
static struct timeval initial_tv = { 0, 0 }
 
static bool next_print_log = false
 
static int log_newline_count = 0
 

Function Documentation

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

Definition at line 180 of file log.cc.

181 {
182  va_list ap;
183  va_start(ap, format);
184  logv(format, ap);
185  va_end(ap);
186 }
void logv(const char *format, va_list ap)
Definition: log.cc:76

+ 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:

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

Definition at line 211 of file log.cc.

212 {
213  va_list ap;
214  va_start(ap, format);
215 
216  if (log_cmd_error_throw) {
217  log("ERROR: ");
218  logv(format, ap);
219  log_flush();
220  throw log_cmd_error_exception();
221  }
222 
223  logv_error(format, ap);
224 }
void log_flush()
Definition: log.cc:256
bool log_cmd_error_throw
Definition: log.cc:43
void log(const char *format,...)
Definition: log.cc:180
void logv_error(const char *format, va_list ap)
Definition: log.cc:169
void logv(const char *format, va_list ap)
Definition: log.cc:76

+ 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:

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

Definition at line 204 of file log.cc.

205 {
206  va_list ap;
207  va_start(ap, format);
208  logv_error(format, ap);
209 }
void logv_error(const char *format, va_list ap)
Definition: log.cc:169

+ Here is the call 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 log_header ( const char *  format,
  ... 
)

Definition at line 188 of file log.cc.

189 {
190  va_list ap;
191  va_start(ap, format);
192  logv_header(format, ap);
193  va_end(ap);
194 }
void logv_header(const char *format, va_list ap)
Definition: log.cc:133

+ Here is the call graph for this function:

const char* log_id ( RTLIL::IdString  str)

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 }
const char * c_str() const
Definition: rtlil.h:178
std::set< RTLIL::IdString > log_id_cache
Definition: log.cc:48

+ 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 
)

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 log_warning ( const char *  format,
  ... 
)

Definition at line 196 of file log.cc.

197 {
198  va_list ap;
199  va_start(ap, format);
200  logv_warning(format, ap);
201  va_end(ap);
202 }
void logv_warning(const char *format, va_list ap)
Definition: log.cc:156

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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:

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

std::vector<int> header_count

Definition at line 47 of file log.cc.

struct timeval initial_tv = { 0, 0 }
static

Definition at line 52 of file log.cc.

bool log_cmd_error_throw = false

Definition at line 43 of file log.cc.

FILE* log_errfile = NULL

Definition at line 39 of file log.cc.

YOSYS_NAMESPACE_BEGIN std::vector<FILE*> log_files

Definition at line 37 of file log.cc.

SHA1* log_hasher = NULL

Definition at line 40 of file log.cc.

std::set<RTLIL::IdString> log_id_cache

Definition at line 48 of file log.cc.

int log_newline_count = 0
static

Definition at line 54 of file log.cc.

bool log_quiet_warnings = false

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 = false

Definition at line 42 of file log.cc.

int log_verbose_level

Definition at line 45 of file log.cc.

bool next_print_log = false
static

Definition at line 53 of file log.cc.

std::list<std::string> string_buf

Definition at line 49 of file log.cc.

int string_buf_size = 0

Definition at line 50 of file log.cc.