2018-06-05 23:15:35 +08:00
|
|
|
/*
|
|
|
|
* nextpnr -- Next Generation Place and Route
|
|
|
|
*
|
2021-06-09 20:09:08 +08:00
|
|
|
* Copyright (C) 2018 Claire Xenia Wolf <claire@yosyshq.com>
|
2018-06-05 23:15:35 +08: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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LOG_H
|
|
|
|
#define LOG_H
|
|
|
|
|
2018-06-19 21:17:10 +08:00
|
|
|
#include <functional>
|
2018-06-07 05:17:44 +08:00
|
|
|
#include <ostream>
|
2018-06-08 03:38:24 +08:00
|
|
|
#include <set>
|
2018-06-05 23:15:35 +08:00
|
|
|
#include <stdarg.h>
|
2018-06-08 03:38:24 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2021-06-02 18:36:56 +08:00
|
|
|
#include "hashlib.h"
|
2021-03-13 05:09:44 +08:00
|
|
|
#include "nextpnr_namespaces.h"
|
2018-06-05 23:15:35 +08:00
|
|
|
|
2018-06-12 20:24:59 +08:00
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
|
2018-06-19 21:17:10 +08:00
|
|
|
typedef std::function<void(std::string)> log_write_type;
|
|
|
|
|
2018-06-08 03:38:24 +08:00
|
|
|
struct log_cmd_error_exception
|
|
|
|
{
|
|
|
|
};
|
2018-06-05 23:15:35 +08:00
|
|
|
|
2018-06-21 23:44:18 +08:00
|
|
|
struct log_execution_error_exception
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2018-11-22 01:08:45 +08:00
|
|
|
enum class LogLevel
|
|
|
|
{
|
2018-12-06 02:58:38 +08:00
|
|
|
LOG_MSG,
|
|
|
|
INFO_MSG,
|
|
|
|
WARNING_MSG,
|
|
|
|
ERROR_MSG,
|
|
|
|
ALWAYS_MSG
|
2018-11-22 01:08:45 +08:00
|
|
|
};
|
|
|
|
|
2021-06-02 18:36:56 +08:00
|
|
|
struct loglevel_hash_ops
|
|
|
|
{
|
|
|
|
static inline bool cmp(LogLevel a, LogLevel b) { return a == b; }
|
|
|
|
static inline unsigned int hash(LogLevel a) { return unsigned(a); }
|
|
|
|
};
|
|
|
|
|
2018-11-22 01:08:45 +08:00
|
|
|
extern std::vector<std::pair<std::ostream *, LogLevel>> log_streams;
|
2018-06-19 21:17:10 +08:00
|
|
|
extern log_write_type log_write_function;
|
2018-06-05 23:15:35 +08:00
|
|
|
|
2018-06-08 03:38:24 +08:00
|
|
|
extern std::string log_last_error;
|
|
|
|
extern void (*log_error_atexit)();
|
2018-11-26 17:22:42 +08:00
|
|
|
extern bool had_nonfatal_error;
|
2021-06-02 18:36:56 +08:00
|
|
|
extern dict<LogLevel, int, loglevel_hash_ops> message_count_by_level;
|
2018-06-05 23:15:35 +08:00
|
|
|
|
2018-08-18 20:13:27 +08:00
|
|
|
std::string stringf(const char *fmt, ...);
|
|
|
|
std::string vstringf(const char *fmt, va_list ap);
|
|
|
|
|
2018-07-03 14:52:19 +08:00
|
|
|
void log(const char *format, ...) NPNR_ATTRIBUTE(format(printf, 1, 2));
|
2018-08-09 19:35:18 +08:00
|
|
|
void log_always(const char *format, ...) NPNR_ATTRIBUTE(format(printf, 1, 2));
|
2018-07-03 14:52:19 +08:00
|
|
|
void log_info(const char *format, ...) NPNR_ATTRIBUTE(format(printf, 1, 2));
|
|
|
|
void log_warning(const char *format, ...) NPNR_ATTRIBUTE(format(printf, 1, 2));
|
|
|
|
NPNR_NORETURN void log_error(const char *format, ...) NPNR_ATTRIBUTE(format(printf, 1, 2), noreturn);
|
2018-11-26 17:22:42 +08:00
|
|
|
void log_nonfatal_error(const char *format, ...) NPNR_ATTRIBUTE(format(printf, 1, 2));
|
2018-06-21 20:09:50 +08:00
|
|
|
void log_break();
|
2018-06-05 23:15:35 +08:00
|
|
|
void log_flush();
|
|
|
|
|
2018-06-23 21:28:09 +08:00
|
|
|
static inline void log_assert_worker(bool cond, const char *expr, const char *file, int line)
|
2018-06-08 03:38:24 +08:00
|
|
|
{
|
|
|
|
if (!cond)
|
|
|
|
log_error("Assert `%s' failed in %s:%d.\n", expr, file, line);
|
2018-06-05 23:15:35 +08:00
|
|
|
}
|
2018-06-23 21:28:09 +08:00
|
|
|
#define log_assert(_assert_expr_) \
|
2018-07-23 20:03:23 +08:00
|
|
|
NEXTPNR_NAMESPACE_PREFIX log_assert_worker(_assert_expr_, #_assert_expr_, __FILE__, __LINE__)
|
2018-06-05 23:15:35 +08:00
|
|
|
|
2018-06-08 03:38:24 +08:00
|
|
|
#define log_abort() log_error("Abort in %s:%d.\n", __FILE__, __LINE__)
|
2018-06-05 23:15:35 +08:00
|
|
|
|
2018-06-12 20:24:59 +08:00
|
|
|
NEXTPNR_NAMESPACE_END
|
|
|
|
|
2018-06-05 23:15:35 +08:00
|
|
|
#endif
|