2013-01-05 04:13:26 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-01-05 04:13:26 -06:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-01-05 04:13:26 -06:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-07-30 07:10:15 -05:00
|
|
|
#include "kernel/yosys.h"
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
#ifndef LOG_H
|
|
|
|
#define LOG_H
|
|
|
|
|
2013-11-22 07:08:10 -06:00
|
|
|
#include <time.h>
|
2020-03-13 11:19:54 -05:00
|
|
|
|
|
|
|
// In GCC 4.8 std::regex is not working correctlty, in order to make features
|
|
|
|
// using regular expressions to work replacement regex library is used
|
2020-03-13 11:23:27 -05:00
|
|
|
#if defined(__GNUC__) && !defined( __clang__) && ( __GNUC__ == 4 && __GNUC_MINOR__ <= 8)
|
2020-03-13 08:58:35 -05:00
|
|
|
#include <boost/xpressive/xpressive.hpp>
|
2020-03-13 11:19:54 -05:00
|
|
|
#define YS_REGEX_TYPE boost::xpressive::sregex
|
2020-03-25 17:37:54 -05:00
|
|
|
#define YS_REGEX_MATCH_TYPE boost::xpressive::smatch
|
2020-03-13 11:19:54 -05:00
|
|
|
#define YS_REGEX_NS boost::xpressive
|
|
|
|
#define YS_REGEX_COMPILE(param) boost::xpressive::sregex::compile(param, \
|
2020-03-13 08:58:35 -05:00
|
|
|
boost::xpressive::regex_constants::nosubs | \
|
|
|
|
boost::xpressive::regex_constants::optimize)
|
2020-03-25 17:37:54 -05:00
|
|
|
#define YS_REGEX_COMPILE_WITH_SUBS(param) boost::xpressive::sregex::compile(param, \
|
|
|
|
boost::xpressive::regex_constants::optimize)
|
2020-03-13 08:58:35 -05:00
|
|
|
# else
|
|
|
|
#include <regex>
|
2020-03-13 11:19:54 -05:00
|
|
|
#define YS_REGEX_TYPE std::regex
|
2020-03-25 17:37:54 -05:00
|
|
|
#define YS_REGEX_MATCH_TYPE std::smatch
|
2020-03-13 11:19:54 -05:00
|
|
|
#define YS_REGEX_NS std
|
|
|
|
#define YS_REGEX_COMPILE(param) std::regex(param, \
|
2020-03-13 08:58:35 -05:00
|
|
|
std::regex_constants::nosubs | \
|
|
|
|
std::regex_constants::optimize | \
|
|
|
|
std::regex_constants::egrep)
|
2020-03-25 17:37:54 -05:00
|
|
|
#define YS_REGEX_COMPILE_WITH_SUBS(param) std::regex(param, \
|
|
|
|
std::regex_constants::optimize | \
|
|
|
|
std::regex_constants::egrep)
|
2020-03-13 08:58:35 -05:00
|
|
|
#endif
|
2014-10-09 03:51:24 -05:00
|
|
|
|
kernel: Trap in `log_error()` when a debugger is attached.
The workflow of debugging fatal pass errors in Yosys is flawed in
three ways:
1. Running Yosys under a debugger is sufficient for the debugger
to catch some fatal errors (segfaults, aborts, STL exceptions)
but not others (`log_error()`, `log_cmd_error()`). This is
neither obvious nor easy to remember.
2. To catch Yosys-specific fatal errors, it is necessary to set
a breakpoint at `logv_error_with_prefix()`, or at least,
`logv_error()`. This is neither obvious nor easy to remember,
and GDB's autocomplete takes many seconds to suggest function
names due to the large amount of symbols in Yosys.
3. If a breakpoint is not set and Yosys encounters with such
a fatal error, the process terminates. When debugging a crash
that takes a long time to reproduce (or a nondeterministic crash)
this can waste a significant amount of time.
To solve this problem, add a macro `YS_DEBUGTRAP` that acts as a hard
breakpoint (if available), and a macro `YS_DEBUGTRAP_IF_DEBUGGING`
that acts as a hard breakpoint only if debugger is present.
Then, use `YS_DEBUGTRAP_IF_DEBUGGING` in `logv_error_with_prefix()`
to obviate the need for a breakpoint on nearly every platform.
Co-Authored-By: Alberto Gonzalez <boqwxp@airmail.cc>
2020-04-24 14:37:47 -05:00
|
|
|
#if defined(_WIN32)
|
|
|
|
# include <intrin.h>
|
|
|
|
#else
|
2014-10-14 18:05:08 -05:00
|
|
|
# include <sys/time.h>
|
|
|
|
# include <sys/resource.h>
|
2020-06-13 17:37:04 -05:00
|
|
|
# if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
|
|
|
# include <signal.h>
|
|
|
|
# endif
|
2014-10-09 03:51:24 -05:00
|
|
|
#endif
|
2014-07-28 04:08:55 -05:00
|
|
|
|
2015-08-24 15:52:27 -05:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
// At least this is not in MSVC++ 2013.
|
|
|
|
# define __PRETTY_FUNCTION__ __FUNCTION__
|
|
|
|
#endif
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
// from libs/sha1/sha1.h
|
|
|
|
class SHA1;
|
|
|
|
|
2014-07-31 06:19:47 -05:00
|
|
|
YOSYS_NAMESPACE_BEGIN
|
|
|
|
|
2014-07-24 12:36:20 -05:00
|
|
|
#define S__LINE__sub2(x) #x
|
|
|
|
#define S__LINE__sub1(x) S__LINE__sub2(x)
|
|
|
|
#define S__LINE__ S__LINE__sub1(__LINE__)
|
|
|
|
|
kernel: Trap in `log_error()` when a debugger is attached.
The workflow of debugging fatal pass errors in Yosys is flawed in
three ways:
1. Running Yosys under a debugger is sufficient for the debugger
to catch some fatal errors (segfaults, aborts, STL exceptions)
but not others (`log_error()`, `log_cmd_error()`). This is
neither obvious nor easy to remember.
2. To catch Yosys-specific fatal errors, it is necessary to set
a breakpoint at `logv_error_with_prefix()`, or at least,
`logv_error()`. This is neither obvious nor easy to remember,
and GDB's autocomplete takes many seconds to suggest function
names due to the large amount of symbols in Yosys.
3. If a breakpoint is not set and Yosys encounters with such
a fatal error, the process terminates. When debugging a crash
that takes a long time to reproduce (or a nondeterministic crash)
this can waste a significant amount of time.
To solve this problem, add a macro `YS_DEBUGTRAP` that acts as a hard
breakpoint (if available), and a macro `YS_DEBUGTRAP_IF_DEBUGGING`
that acts as a hard breakpoint only if debugger is present.
Then, use `YS_DEBUGTRAP_IF_DEBUGGING` in `logv_error_with_prefix()`
to obviate the need for a breakpoint on nearly every platform.
Co-Authored-By: Alberto Gonzalez <boqwxp@airmail.cc>
2020-04-24 14:37:47 -05:00
|
|
|
// YS_DEBUGTRAP is a macro that is functionally equivalent to a breakpoint
|
|
|
|
// if the platform provides such functionality, and does nothing otherwise.
|
|
|
|
// If no debugger is attached, it starts a just-in-time debugger if available,
|
|
|
|
// and crashes the process otherwise.
|
|
|
|
#if defined(_WIN32)
|
|
|
|
# define YS_DEBUGTRAP __debugbreak()
|
|
|
|
#else
|
|
|
|
# ifndef __has_builtin
|
|
|
|
// __has_builtin is a GCC/Clang extension; on a different compiler (or old enough GCC/Clang)
|
|
|
|
// that does not have it, using __has_builtin(...) is a syntax error.
|
|
|
|
# define __has_builtin(x) 0
|
|
|
|
# endif
|
|
|
|
# if __has_builtin(__builtin_debugtrap)
|
|
|
|
# define YS_DEBUGTRAP __builtin_debugtrap()
|
2020-05-13 07:09:08 -05:00
|
|
|
# elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
kernel: Trap in `log_error()` when a debugger is attached.
The workflow of debugging fatal pass errors in Yosys is flawed in
three ways:
1. Running Yosys under a debugger is sufficient for the debugger
to catch some fatal errors (segfaults, aborts, STL exceptions)
but not others (`log_error()`, `log_cmd_error()`). This is
neither obvious nor easy to remember.
2. To catch Yosys-specific fatal errors, it is necessary to set
a breakpoint at `logv_error_with_prefix()`, or at least,
`logv_error()`. This is neither obvious nor easy to remember,
and GDB's autocomplete takes many seconds to suggest function
names due to the large amount of symbols in Yosys.
3. If a breakpoint is not set and Yosys encounters with such
a fatal error, the process terminates. When debugging a crash
that takes a long time to reproduce (or a nondeterministic crash)
this can waste a significant amount of time.
To solve this problem, add a macro `YS_DEBUGTRAP` that acts as a hard
breakpoint (if available), and a macro `YS_DEBUGTRAP_IF_DEBUGGING`
that acts as a hard breakpoint only if debugger is present.
Then, use `YS_DEBUGTRAP_IF_DEBUGGING` in `logv_error_with_prefix()`
to obviate the need for a breakpoint on nearly every platform.
Co-Authored-By: Alberto Gonzalez <boqwxp@airmail.cc>
2020-04-24 14:37:47 -05:00
|
|
|
# define YS_DEBUGTRAP raise(SIGTRAP)
|
|
|
|
# else
|
|
|
|
# define YS_DEBUGTRAP do {} while(0)
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// YS_DEBUGTRAP_IF_DEBUGGING is a macro that is functionally equivalent to a breakpoint
|
|
|
|
// if a debugger is attached, and does nothing otherwise.
|
|
|
|
#if defined(_WIN32)
|
|
|
|
# define YS_DEBUGTRAP_IF_DEBUGGING do { if (IsDebuggerPresent()) DebugBreak(); } while(0)
|
2020-05-13 08:17:00 -05:00
|
|
|
# elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
kernel: Trap in `log_error()` when a debugger is attached.
The workflow of debugging fatal pass errors in Yosys is flawed in
three ways:
1. Running Yosys under a debugger is sufficient for the debugger
to catch some fatal errors (segfaults, aborts, STL exceptions)
but not others (`log_error()`, `log_cmd_error()`). This is
neither obvious nor easy to remember.
2. To catch Yosys-specific fatal errors, it is necessary to set
a breakpoint at `logv_error_with_prefix()`, or at least,
`logv_error()`. This is neither obvious nor easy to remember,
and GDB's autocomplete takes many seconds to suggest function
names due to the large amount of symbols in Yosys.
3. If a breakpoint is not set and Yosys encounters with such
a fatal error, the process terminates. When debugging a crash
that takes a long time to reproduce (or a nondeterministic crash)
this can waste a significant amount of time.
To solve this problem, add a macro `YS_DEBUGTRAP` that acts as a hard
breakpoint (if available), and a macro `YS_DEBUGTRAP_IF_DEBUGGING`
that acts as a hard breakpoint only if debugger is present.
Then, use `YS_DEBUGTRAP_IF_DEBUGGING` in `logv_error_with_prefix()`
to obviate the need for a breakpoint on nearly every platform.
Co-Authored-By: Alberto Gonzalez <boqwxp@airmail.cc>
2020-04-24 14:37:47 -05:00
|
|
|
// There is no reliable (or portable) *nix equivalent of IsDebuggerPresent(). However,
|
|
|
|
// debuggers will stop when SIGTRAP is raised, even if the action is set to ignore.
|
|
|
|
# define YS_DEBUGTRAP_IF_DEBUGGING do { \
|
2020-05-13 08:17:00 -05:00
|
|
|
auto old = signal(SIGTRAP, SIG_IGN); raise(SIGTRAP); signal(SIGTRAP, old); \
|
kernel: Trap in `log_error()` when a debugger is attached.
The workflow of debugging fatal pass errors in Yosys is flawed in
three ways:
1. Running Yosys under a debugger is sufficient for the debugger
to catch some fatal errors (segfaults, aborts, STL exceptions)
but not others (`log_error()`, `log_cmd_error()`). This is
neither obvious nor easy to remember.
2. To catch Yosys-specific fatal errors, it is necessary to set
a breakpoint at `logv_error_with_prefix()`, or at least,
`logv_error()`. This is neither obvious nor easy to remember,
and GDB's autocomplete takes many seconds to suggest function
names due to the large amount of symbols in Yosys.
3. If a breakpoint is not set and Yosys encounters with such
a fatal error, the process terminates. When debugging a crash
that takes a long time to reproduce (or a nondeterministic crash)
this can waste a significant amount of time.
To solve this problem, add a macro `YS_DEBUGTRAP` that acts as a hard
breakpoint (if available), and a macro `YS_DEBUGTRAP_IF_DEBUGGING`
that acts as a hard breakpoint only if debugger is present.
Then, use `YS_DEBUGTRAP_IF_DEBUGGING` in `logv_error_with_prefix()`
to obviate the need for a breakpoint on nearly every platform.
Co-Authored-By: Alberto Gonzalez <boqwxp@airmail.cc>
2020-04-24 14:37:47 -05:00
|
|
|
} while(0)
|
|
|
|
#else
|
|
|
|
# define YS_DEBUGTRAP_IF_DEBUGGING do {} while(0)
|
|
|
|
#endif
|
|
|
|
|
2014-11-07 05:48:15 -06:00
|
|
|
struct log_cmd_error_exception { };
|
2014-07-27 05:04:12 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
extern std::vector<FILE*> log_files;
|
2014-08-23 08:14:58 -05:00
|
|
|
extern std::vector<std::ostream*> log_streams;
|
2016-04-21 16:28:37 -05:00
|
|
|
extern std::map<std::string, std::set<std::string>> log_hdump;
|
2020-03-13 11:19:54 -05:00
|
|
|
extern std::vector<YS_REGEX_TYPE> log_warn_regexes, log_nowarn_regexes, log_werror_regexes;
|
2020-01-28 10:51:50 -06:00
|
|
|
extern std::set<std::string> log_warnings, log_experimentals, log_experimentals_ignored;
|
2018-03-04 15:35:59 -06:00
|
|
|
extern int log_warnings_count;
|
2020-02-22 03:52:46 -06:00
|
|
|
extern int log_warnings_count_noexpect;
|
2020-02-17 08:36:06 -06:00
|
|
|
extern bool log_expect_no_warnings;
|
2016-04-24 10:12:34 -05:00
|
|
|
extern bool log_hdump_all;
|
2013-01-05 04:13:26 -06:00
|
|
|
extern FILE *log_errfile;
|
2014-09-27 09:17:53 -05:00
|
|
|
extern SHA1 *log_hasher;
|
2014-08-01 12:43:28 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
extern bool log_time;
|
2015-01-03 15:10:33 -06:00
|
|
|
extern bool log_error_stderr;
|
2013-01-05 04:13:26 -06:00
|
|
|
extern bool log_cmd_error_throw;
|
2014-11-09 04:02:20 -06:00
|
|
|
extern bool log_quiet_warnings;
|
2013-11-17 06:26:31 -06:00
|
|
|
extern int log_verbose_level;
|
2015-02-19 06:36:54 -06:00
|
|
|
extern string log_last_error;
|
2017-06-19 21:41:58 -05:00
|
|
|
extern void (*log_error_atexit)();
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2019-04-22 10:25:52 -05:00
|
|
|
extern int log_make_debug;
|
|
|
|
extern int log_force_debug;
|
|
|
|
extern int log_debug_suppressed;
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
void logv(const char *format, va_list ap);
|
2016-04-21 16:28:37 -05:00
|
|
|
void logv_header(RTLIL::Design *design, const char *format, va_list ap);
|
2014-11-09 03:44:23 -06:00
|
|
|
void logv_warning(const char *format, va_list ap);
|
2017-07-27 05:17:04 -05:00
|
|
|
void logv_warning_noprefix(const char *format, va_list ap);
|
2020-06-18 20:05:59 -05:00
|
|
|
[[noreturn]] void logv_error(const char *format, va_list ap);
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-11-09 03:55:04 -06:00
|
|
|
void log(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2));
|
2016-04-21 16:28:37 -05:00
|
|
|
void log_header(RTLIL::Design *design, const char *format, ...) YS_ATTRIBUTE(format(printf, 2, 3));
|
2014-11-09 03:55:04 -06:00
|
|
|
void log_warning(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2));
|
2020-01-27 11:27:47 -06:00
|
|
|
void log_experimental(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2));
|
2018-07-19 11:40:20 -05:00
|
|
|
|
|
|
|
// Log with filename to report a problem in a source file.
|
|
|
|
void log_file_warning(const std::string &filename, int lineno, const char *format, ...) YS_ATTRIBUTE(format(printf, 3, 4));
|
2019-05-02 19:10:43 -05:00
|
|
|
void log_file_info(const std::string &filename, int lineno, const char *format, ...) YS_ATTRIBUTE(format(printf, 3, 4));
|
2018-07-19 11:40:20 -05:00
|
|
|
|
2017-07-27 05:17:04 -05:00
|
|
|
void log_warning_noprefix(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2));
|
2020-06-18 20:05:59 -05:00
|
|
|
[[noreturn]] void log_error(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2));
|
2020-06-19 04:46:06 -05:00
|
|
|
[[noreturn]] void log_file_error(const string &filename, int lineno, const char *format, ...) YS_ATTRIBUTE(format(printf, 3, 4));
|
2020-06-18 20:05:59 -05:00
|
|
|
[[noreturn]] void log_cmd_error(const char *format, ...) YS_ATTRIBUTE(format(printf, 1, 2));
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2019-04-22 10:25:52 -05:00
|
|
|
#ifndef NDEBUG
|
|
|
|
static inline bool ys_debug(int n = 0) { if (log_force_debug) return true; log_debug_suppressed += n; return false; }
|
|
|
|
# define log_debug(...) do { if (ys_debug(1)) log(__VA_ARGS__); } while (0)
|
|
|
|
#else
|
2019-08-11 16:25:46 -05:00
|
|
|
static inline bool ys_debug(int = 0) { return false; }
|
2019-04-22 10:25:52 -05:00
|
|
|
# define log_debug(_fmt, ...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline void log_suppressed() {
|
|
|
|
if (log_debug_suppressed && !log_make_debug) {
|
|
|
|
log("<suppressed ~%d debug messages>\n", log_debug_suppressed);
|
|
|
|
log_debug_suppressed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct LogMakeDebugHdl {
|
|
|
|
bool status = false;
|
|
|
|
LogMakeDebugHdl(bool start_on = false) {
|
|
|
|
if (start_on)
|
|
|
|
on();
|
|
|
|
}
|
|
|
|
~LogMakeDebugHdl() {
|
|
|
|
off();
|
|
|
|
}
|
|
|
|
void on() {
|
|
|
|
if (status) return;
|
|
|
|
status=true;
|
|
|
|
log_make_debug++;
|
|
|
|
}
|
|
|
|
void off_silent() {
|
|
|
|
if (!status) return;
|
|
|
|
status=false;
|
|
|
|
log_make_debug--;
|
|
|
|
}
|
|
|
|
void off() {
|
|
|
|
off_silent();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-16 08:34:00 -05:00
|
|
|
void log_spacer();
|
2013-01-05 04:13:26 -06:00
|
|
|
void log_push();
|
|
|
|
void log_pop();
|
|
|
|
|
2014-12-29 06:33:33 -06:00
|
|
|
void log_backtrace(const char *prefix, int levels);
|
2013-01-05 04:13:26 -06:00
|
|
|
void log_reset_stack();
|
|
|
|
void log_flush();
|
|
|
|
|
2020-02-14 05:21:16 -06:00
|
|
|
struct LogExpectedItem
|
|
|
|
{
|
2020-05-14 17:52:07 -05:00
|
|
|
LogExpectedItem(const YS_REGEX_TYPE &pat, int expected) :
|
|
|
|
pattern(pat), expected_count(expected), current_count(0) {}
|
|
|
|
LogExpectedItem() : expected_count(0), current_count(0) {}
|
2020-02-14 05:21:16 -06:00
|
|
|
|
2020-05-14 17:52:07 -05:00
|
|
|
YS_REGEX_TYPE pattern;
|
2020-02-14 05:21:16 -06:00
|
|
|
int expected_count;
|
|
|
|
int current_count;
|
|
|
|
};
|
|
|
|
|
2020-05-14 17:52:07 -05:00
|
|
|
extern dict<std::string, LogExpectedItem> log_expect_log, log_expect_warning, log_expect_error;
|
2020-02-14 05:21:16 -06:00
|
|
|
void log_check_expected();
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
const char *log_signal(const RTLIL::SigSpec &sig, bool autoint = true);
|
2016-08-09 12:56:10 -05:00
|
|
|
const char *log_const(const RTLIL::Const &value, bool autoint = true);
|
2014-08-01 17:45:25 -05:00
|
|
|
const char *log_id(RTLIL::IdString id);
|
2014-07-18 03:26:01 -05:00
|
|
|
|
2019-01-13 10:00:58 -06:00
|
|
|
template<typename T> static inline const char *log_id(T *obj, const char *nullstr = nullptr) {
|
|
|
|
if (nullstr && obj == nullptr)
|
|
|
|
return nullstr;
|
2014-07-19 13:53:29 -05:00
|
|
|
return log_id(obj->name);
|
2014-07-18 03:26:01 -05:00
|
|
|
}
|
|
|
|
|
2016-07-27 08:40:17 -05:00
|
|
|
void log_module(RTLIL::Module *module, std::string indent = "");
|
2014-07-20 03:35:47 -05:00
|
|
|
void log_cell(RTLIL::Cell *cell, std::string indent = "");
|
2017-02-11 04:08:12 -06:00
|
|
|
void log_wire(RTLIL::Wire *wire, std::string indent = "");
|
2014-07-20 03:35:47 -05:00
|
|
|
|
2015-01-24 04:49:34 -06:00
|
|
|
#ifndef NDEBUG
|
2014-10-15 13:36:32 -05:00
|
|
|
static inline void log_assert_worker(bool cond, const char *expr, const char *file, int line) {
|
|
|
|
if (!cond) log_error("Assert `%s' failed in %s:%d.\n", expr, file, line);
|
|
|
|
}
|
2015-01-24 04:49:34 -06:00
|
|
|
# define log_assert(_assert_expr_) YOSYS_NAMESPACE_PREFIX log_assert_worker(_assert_expr_, #_assert_expr_, __FILE__, __LINE__)
|
|
|
|
#else
|
2020-06-17 14:30:53 -05:00
|
|
|
# define log_assert(_assert_expr_) do { if (0) { (void)(_assert_expr_); } } while(0)
|
2015-01-24 04:49:34 -06:00
|
|
|
#endif
|
2014-10-15 13:36:32 -05:00
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
#define log_abort() YOSYS_NAMESPACE_PREFIX log_error("Abort in %s:%d.\n", __FILE__, __LINE__)
|
|
|
|
#define log_ping() YOSYS_NAMESPACE_PREFIX log("-- %s:%d %s --\n", __FILE__, __LINE__, __PRETTY_FUNCTION__)
|
2013-05-24 05:32:06 -05:00
|
|
|
|
2014-07-24 08:05:05 -05:00
|
|
|
|
|
|
|
// ---------------------------------------------------
|
|
|
|
// This is the magic behind the code coverage counters
|
|
|
|
// ---------------------------------------------------
|
|
|
|
|
2018-05-05 06:02:44 -05:00
|
|
|
#if defined(YOSYS_ENABLE_COVER) && (defined(__linux__) || defined(__FreeBSD__))
|
2014-07-24 08:06:45 -05:00
|
|
|
|
|
|
|
#define cover(_id) do { \
|
2015-01-09 10:32:53 -06:00
|
|
|
static CoverData __d __attribute__((section("yosys_cover_list"), aligned(1), used)) = { __FILE__, __FUNCTION__, _id, __LINE__, 0 }; \
|
2014-07-24 08:06:45 -05:00
|
|
|
__d.counter++; \
|
|
|
|
} while (0)
|
|
|
|
|
2014-07-24 08:05:05 -05:00
|
|
|
struct CoverData {
|
|
|
|
const char *file, *func, *id;
|
|
|
|
int line, counter;
|
2014-11-09 03:55:04 -06:00
|
|
|
} YS_ATTRIBUTE(packed);
|
2014-07-24 08:05:05 -05:00
|
|
|
|
|
|
|
// this two symbols are created by the linker for the "yosys_cover_list" ELF section
|
|
|
|
extern "C" struct CoverData __start_yosys_cover_list[];
|
|
|
|
extern "C" struct CoverData __stop_yosys_cover_list[];
|
|
|
|
|
2014-12-26 14:35:22 -06:00
|
|
|
extern dict<std::string, std::pair<std::string, int>> extra_coverage_data;
|
2014-07-24 12:36:20 -05:00
|
|
|
|
2014-07-28 04:08:55 -05:00
|
|
|
void cover_extra(std::string parent, std::string id, bool increment = true);
|
2014-12-26 14:35:22 -06:00
|
|
|
dict<std::string, std::pair<std::string, int>> get_coverage_data();
|
2014-07-24 08:06:45 -05:00
|
|
|
|
2014-07-24 12:36:20 -05:00
|
|
|
#define cover_list(_id, ...) do { cover(_id); \
|
|
|
|
std::string r = cover_list_worker(_id, __VA_ARGS__); \
|
|
|
|
log_assert(r.empty()); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static inline std::string cover_list_worker(std::string, std::string last) {
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename... T>
|
|
|
|
std::string cover_list_worker(std::string prefix, std::string first, T... rest) {
|
|
|
|
std::string selected = cover_list_worker(prefix, rest...);
|
|
|
|
cover_extra(prefix, prefix + "." + first, first == selected);
|
|
|
|
return first == selected ? "" : selected;
|
|
|
|
}
|
|
|
|
|
2014-07-23 20:48:38 -05:00
|
|
|
#else
|
2014-07-24 12:36:20 -05:00
|
|
|
# define cover(...) do { } while (0)
|
|
|
|
# define cover_list(...) do { } while (0)
|
2014-07-23 20:48:38 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
// everything below this line are utilities for troubleshooting
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
2013-11-22 07:08:10 -06:00
|
|
|
// simple timer for performance measurements
|
2015-08-14 03:56:05 -05:00
|
|
|
// toggle the '#if 1' to get a baseline for the performance penalty added by the measurement
|
2013-11-22 07:08:10 -06:00
|
|
|
struct PerformanceTimer
|
|
|
|
{
|
|
|
|
#if 1
|
|
|
|
int64_t total_ns;
|
|
|
|
|
|
|
|
PerformanceTimer() {
|
|
|
|
total_ns = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int64_t query() {
|
2018-03-06 11:43:42 -06:00
|
|
|
# ifdef _WIN32
|
2016-05-07 03:53:18 -05:00
|
|
|
return 0;
|
|
|
|
# elif defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0)
|
2013-11-22 07:08:10 -06:00
|
|
|
struct timespec ts;
|
|
|
|
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
|
|
|
|
return int64_t(ts.tv_sec)*1000000000 + ts.tv_nsec;
|
2016-05-07 03:53:18 -05:00
|
|
|
# elif defined(RUSAGE_SELF)
|
2014-03-11 08:24:24 -05:00
|
|
|
struct rusage rusage;
|
|
|
|
int64_t t;
|
|
|
|
if (getrusage(RUSAGE_SELF, &rusage) == -1) {
|
|
|
|
log_cmd_error("getrusage failed!\n");
|
|
|
|
log_abort();
|
|
|
|
}
|
|
|
|
t = 1000000000ULL * (int64_t) rusage.ru_utime.tv_sec + (int64_t) rusage.ru_utime.tv_usec * 1000ULL;
|
|
|
|
t += 1000000000ULL * (int64_t) rusage.ru_stime.tv_sec + (int64_t) rusage.ru_stime.tv_usec * 1000ULL;
|
|
|
|
return t;
|
2016-05-07 03:53:18 -05:00
|
|
|
# else
|
2018-12-07 13:14:07 -06:00
|
|
|
# error "Don't know how to measure per-process CPU time. Need alternative method (times()/clocks()/gettimeofday()?)."
|
2016-05-07 03:53:18 -05:00
|
|
|
# endif
|
2013-11-22 07:08:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
total_ns = 0;
|
|
|
|
}
|
|
|
|
|
2014-07-27 08:14:02 -05:00
|
|
|
void begin() {
|
|
|
|
total_ns -= query();
|
2013-11-22 07:08:10 -06:00
|
|
|
}
|
|
|
|
|
2014-07-27 08:14:02 -05:00
|
|
|
void end() {
|
|
|
|
total_ns += query();
|
2013-11-22 07:08:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
float sec() const {
|
2014-10-16 23:02:38 -05:00
|
|
|
return total_ns * 1e-9f;
|
2013-11-22 07:08:10 -06:00
|
|
|
}
|
|
|
|
#else
|
2014-08-01 11:42:10 -05:00
|
|
|
static int64_t query() { return 0; }
|
2013-11-22 07:08:10 -06:00
|
|
|
void reset() { }
|
2014-07-27 08:14:02 -05:00
|
|
|
void begin() { }
|
|
|
|
void end() { }
|
2013-11-22 07:08:10 -06:00
|
|
|
float sec() const { return 0; }
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2013-12-20 05:11:58 -06:00
|
|
|
// simple API for quickly dumping values when debugging
|
|
|
|
|
2014-01-17 16:14:17 -06:00
|
|
|
static inline void log_dump_val_worker(short v) { log("%d", v); }
|
|
|
|
static inline void log_dump_val_worker(unsigned short v) { log("%u", v); }
|
2013-12-20 05:11:58 -06:00
|
|
|
static inline void log_dump_val_worker(int v) { log("%d", v); }
|
2014-01-17 16:14:17 -06:00
|
|
|
static inline void log_dump_val_worker(unsigned int v) { log("%u", v); }
|
2013-12-20 05:11:58 -06:00
|
|
|
static inline void log_dump_val_worker(long int v) { log("%ld", v); }
|
2014-01-17 16:14:17 -06:00
|
|
|
static inline void log_dump_val_worker(unsigned long int v) { log("%lu", v); }
|
2014-10-09 10:00:54 -05:00
|
|
|
#ifndef _WIN32
|
2013-12-20 05:11:58 -06:00
|
|
|
static inline void log_dump_val_worker(long long int v) { log("%lld", v); }
|
2014-01-17 16:14:17 -06:00
|
|
|
static inline void log_dump_val_worker(unsigned long long int v) { log("%lld", v); }
|
2014-10-09 03:51:24 -05:00
|
|
|
#endif
|
2013-12-20 05:11:58 -06:00
|
|
|
static inline void log_dump_val_worker(char c) { log(c >= 32 && c < 127 ? "'%c'" : "'\\x%02x'", c); }
|
2014-01-17 16:14:17 -06:00
|
|
|
static inline void log_dump_val_worker(unsigned char c) { log(c >= 32 && c < 127 ? "'%c'" : "'\\x%02x'", c); }
|
2013-12-20 05:11:58 -06:00
|
|
|
static inline void log_dump_val_worker(bool v) { log("%s", v ? "true" : "false"); }
|
|
|
|
static inline void log_dump_val_worker(double v) { log("%f", v); }
|
2014-07-30 08:58:21 -05:00
|
|
|
static inline void log_dump_val_worker(char *v) { log("%s", v); }
|
2013-12-20 05:11:58 -06:00
|
|
|
static inline void log_dump_val_worker(const char *v) { log("%s", v); }
|
|
|
|
static inline void log_dump_val_worker(std::string v) { log("%s", v.c_str()); }
|
2014-07-27 08:14:02 -05:00
|
|
|
static inline void log_dump_val_worker(PerformanceTimer p) { log("%f seconds", p.sec()); }
|
2015-01-24 05:16:46 -06:00
|
|
|
static inline void log_dump_args_worker(const char *p YS_ATTRIBUTE(unused)) { log_assert(*p == 0); }
|
2015-06-08 07:49:02 -05:00
|
|
|
void log_dump_val_worker(RTLIL::IdString v);
|
2014-07-28 04:08:55 -05:00
|
|
|
void log_dump_val_worker(RTLIL::SigSpec v);
|
2019-10-02 19:49:07 -05:00
|
|
|
void log_dump_val_worker(RTLIL::State v);
|
2013-12-20 05:11:58 -06:00
|
|
|
|
2016-03-31 02:57:44 -05:00
|
|
|
template<typename K, typename T, typename OPS>
|
|
|
|
static inline void log_dump_val_worker(dict<K, T, OPS> &v) {
|
|
|
|
log("{");
|
|
|
|
bool first = true;
|
|
|
|
for (auto &it : v) {
|
|
|
|
log(first ? " " : ", ");
|
|
|
|
log_dump_val_worker(it.first);
|
|
|
|
log(": ");
|
|
|
|
log_dump_val_worker(it.second);
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
log(" }");
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename K, typename OPS>
|
|
|
|
static inline void log_dump_val_worker(pool<K, OPS> &v) {
|
|
|
|
log("{");
|
|
|
|
bool first = true;
|
|
|
|
for (auto &it : v) {
|
|
|
|
log(first ? " " : ", ");
|
|
|
|
log_dump_val_worker(it);
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
log(" }");
|
|
|
|
}
|
|
|
|
|
2014-03-14 10:39:50 -05:00
|
|
|
template<typename T>
|
|
|
|
static inline void log_dump_val_worker(T *ptr) { log("%p", ptr); }
|
|
|
|
|
2014-07-24 12:36:20 -05:00
|
|
|
template<typename T, typename ... Args>
|
2013-12-20 05:11:58 -06:00
|
|
|
void log_dump_args_worker(const char *p, T first, Args ... args)
|
|
|
|
{
|
|
|
|
int next_p_state = 0;
|
|
|
|
const char *next_p = p;
|
|
|
|
while (*next_p && (next_p_state != 0 || *next_p != ',')) {
|
|
|
|
if (*next_p == '"')
|
|
|
|
do {
|
|
|
|
next_p++;
|
|
|
|
while (*next_p == '\\' && *(next_p + 1))
|
|
|
|
next_p += 2;
|
|
|
|
} while (*next_p && *next_p != '"');
|
|
|
|
if (*next_p == '\'') {
|
|
|
|
next_p++;
|
|
|
|
if (*next_p == '\\')
|
|
|
|
next_p++;
|
|
|
|
if (*next_p)
|
|
|
|
next_p++;
|
|
|
|
}
|
|
|
|
if (*next_p == '(' || *next_p == '[' || *next_p == '{')
|
|
|
|
next_p_state++;
|
|
|
|
if ((*next_p == ')' || *next_p == ']' || *next_p == '}') && next_p_state > 0)
|
|
|
|
next_p_state--;
|
|
|
|
next_p++;
|
|
|
|
}
|
|
|
|
log("\n\t%.*s => ", int(next_p - p), p);
|
|
|
|
if (*next_p == ',')
|
|
|
|
next_p++;
|
|
|
|
while (*next_p == ' ' || *next_p == '\t' || *next_p == '\r' || *next_p == '\n')
|
|
|
|
next_p++;
|
|
|
|
log_dump_val_worker(first);
|
|
|
|
log_dump_args_worker(next_p, args ...);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define log_dump(...) 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)
|
|
|
|
|
2014-07-31 06:19:47 -05:00
|
|
|
YOSYS_NAMESPACE_END
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
#endif
|