28 # include <sys/time.h>
29 # include <sys/resource.h>
37 #define S__LINE__sub2(x) #x
38 #define S__LINE__sub1(x) S__LINE__sub2(x)
39 #define S__LINE__ S__LINE__sub1(__LINE__)
53 void logv(
const char *format, va_list ap);
71 const
char *
log_signal(const RTLIL::SigSpec &sig,
bool autoint = true);
72 const
char *
log_id(RTLIL::IdString
id);
74 template<typename T> static inline const
char *
log_id(T *obj) {
81 if (!cond)
log_error(
"Assert `%s' failed in %s:%d.\n", expr, file, line);
84 #define log_abort() YOSYS_NAMESPACE_PREFIX log_error("Abort in %s:%d.\n", __FILE__, __LINE__)
85 #define log_assert(_assert_expr_) YOSYS_NAMESPACE_PREFIX log_assert_worker(_assert_expr_, #_assert_expr_, __FILE__, __LINE__)
86 #define log_ping() YOSYS_NAMESPACE_PREFIX log("-- %s:%d %s --\n", __FILE__, __LINE__, __PRETTY_FUNCTION__)
93 #ifdef YOSYS_ENABLE_COVER
95 #define cover(_id) do { \
96 static CoverData __d YS_ATTRIBUTE(section("yosys_cover_list"), aligned(1), used) = { __FILE__, __FUNCTION__, _id, __LINE__, 0 }; \
101 const char *file, *func, *
id;
106 extern "C" struct CoverData __start_yosys_cover_list[];
107 extern "C" struct CoverData __stop_yosys_cover_list[];
109 extern std::map<std::string, std::pair<std::string, int>> extra_coverage_data;
111 void cover_extra(std::string parent, std::string
id,
bool increment =
true);
112 std::map<std::string, std::pair<std::string, int>> get_coverage_data();
114 #define cover_list(_id, ...) do { cover(_id); \
115 std::string r = cover_list_worker(_id, __VA_ARGS__); \
116 log_assert(r.empty()); \
119 static inline std::string cover_list_worker(std::string, std::string last) {
123 template<
typename... T>
124 std::string cover_list_worker(std::string prefix, std::string first, T... rest) {
125 std::string selected = cover_list_worker(prefix, rest...);
126 cover_extra(prefix, prefix +
"." + first, first == selected);
127 return first == selected ?
"" : selected;
131 # define cover(...) do { } while (0)
132 # define cover_list(...) do { } while (0)
152 #if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0)
154 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
155 return int64_t(ts.tv_sec)*1000000000 + ts.tv_nsec;
156 #elif defined(RUSAGE_SELF)
157 struct rusage rusage;
159 if (getrusage(RUSAGE_SELF, &rusage) == -1) {
163 t = 1000000000ULL * (int64_t) rusage.ru_utime.tv_sec + (int64_t) rusage.ru_utime.tv_usec * 1000ULL;
164 t += 1000000000ULL * (int64_t) rusage.ru_stime.tv_sec + (int64_t) rusage.ru_stime.tv_usec * 1000ULL;
169 #error Dont know how to measure per-process CPU time. Need alternative method (times()/clocks()/gettimeofday()?).
189 static int64_t
query() {
return 0; }
193 float sec()
const {
return 0; }
223 template<
typename T,
typename ... Args>
226 int next_p_state = 0;
227 const char *next_p = p;
228 while (*next_p && (next_p_state != 0 || *next_p !=
',')) {
232 while (*next_p ==
'\\' && *(next_p + 1))
234 }
while (*next_p && *next_p !=
'"');
235 if (*next_p ==
'\'') {
242 if (*next_p ==
'(' || *next_p ==
'[' || *next_p ==
'{')
244 if ((*next_p ==
')' || *next_p ==
']' || *next_p ==
'}') && next_p_state > 0)
248 log(
"\n\t%.*s => ",
int(next_p - p), p);
251 while (*next_p ==
' ' || *next_p ==
'\t' || *next_p ==
'\r' || *next_p ==
'\n')
257 #define log_dump(...) do { \
258 log("DEBUG DUMP IN %s AT %s:%d:", __PRETTY_FUNCTION__, __FILE__, __LINE__); \
259 log_dump_args_worker(#__VA_ARGS__, __VA_ARGS__); \
static void log_dump_val_worker(short v)
void logv_header(const char *format, va_list ap)
#define YOSYS_NAMESPACE_END
std::vector< std::ostream * > log_streams
void log_cell(RTLIL::Cell *cell, std::string indent="")
std::vector< FILE * > log_files
void log(const char *format,...) YS_ATTRIBUTE(format(printf
void void log_header(const char *format,...) YS_ATTRIBUTE(format(printf
YS_NORETURN void logv_error(const char *format, va_list ap) YS_ATTRIBUTE(noreturn)
void logv_warning(const char *format, va_list ap)
#define YS_ATTRIBUTE(...)
#define log_assert(_assert_expr_)
void void void YS_NORETURN void noreturn
static void log_assert_worker(bool cond, const char *expr, const char *file, int line)
#define YOSYS_NAMESPACE_BEGIN
static void log_dump_args_worker(const char *p)
const char * log_id(RTLIL::IdString id)
std::string id(RTLIL::IdString internal_id, bool may_rename=true)
YS_NORETURN void log_cmd_error(const char *format,...) YS_ATTRIBUTE(format(printf
const char * log_signal(const RTLIL::SigSpec &sig, bool autoint=true)
void void void YS_NORETURN void log_error(const char *format,...) YS_ATTRIBUTE(format(printf
void void void log_warning(const char *format,...) YS_ATTRIBUTE(format(printf
void logv(const char *format, va_list ap)