mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-12 20:18:20 +00:00
Added cover_list() API
This commit is contained in:
parent
45b4154b37
commit
10d2402e2f
|
@ -29,6 +29,9 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
|
// declared extern in log.h
|
||||||
|
std::map<std::string, std::pair<std::string, int>> extra_coverage_data;
|
||||||
|
|
||||||
std::vector<FILE*> log_files;
|
std::vector<FILE*> log_files;
|
||||||
FILE *log_errfile = NULL;
|
FILE *log_errfile = NULL;
|
||||||
bool log_time = false;
|
bool log_time = false;
|
||||||
|
|
45
kernel/log.h
45
kernel/log.h
|
@ -30,6 +30,10 @@
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#define S__LINE__sub2(x) #x
|
||||||
|
#define S__LINE__sub1(x) S__LINE__sub2(x)
|
||||||
|
#define S__LINE__ S__LINE__sub1(__LINE__)
|
||||||
|
|
||||||
extern std::vector<FILE*> log_files;
|
extern std::vector<FILE*> log_files;
|
||||||
extern FILE *log_errfile;
|
extern FILE *log_errfile;
|
||||||
extern bool log_time;
|
extern bool log_time;
|
||||||
|
@ -87,6 +91,19 @@ struct CoverData {
|
||||||
extern "C" struct CoverData __start_yosys_cover_list[];
|
extern "C" struct CoverData __start_yosys_cover_list[];
|
||||||
extern "C" struct CoverData __stop_yosys_cover_list[];
|
extern "C" struct CoverData __stop_yosys_cover_list[];
|
||||||
|
|
||||||
|
extern std::map<std::string, std::pair<std::string, int>> extra_coverage_data;
|
||||||
|
|
||||||
|
static inline void cover_extra(std::string parent, std::string id, bool increment = true) {
|
||||||
|
if (extra_coverage_data.count(id) == 0) {
|
||||||
|
for (CoverData *p = __start_yosys_cover_list; p != __stop_yosys_cover_list; p++)
|
||||||
|
if (p->id == parent)
|
||||||
|
extra_coverage_data[id].first = stringf("%s:%d:%s", p->file, p->line, p->func);
|
||||||
|
log_assert(extra_coverage_data.count(id));
|
||||||
|
}
|
||||||
|
if (increment)
|
||||||
|
extra_coverage_data[id].second++;
|
||||||
|
}
|
||||||
|
|
||||||
static inline std::map<std::string, std::pair<std::string, int>> get_coverage_data()
|
static inline std::map<std::string, std::pair<std::string, int>> get_coverage_data()
|
||||||
{
|
{
|
||||||
std::map<std::string, std::pair<std::string, int>> coverage_data;
|
std::map<std::string, std::pair<std::string, int>> coverage_data;
|
||||||
|
@ -97,6 +114,13 @@ static inline std::map<std::string, std::pair<std::string, int>> get_coverage_da
|
||||||
coverage_data[key].second += it.second->call_counter;
|
coverage_data[key].second += it.second->call_counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto &it : extra_coverage_data) {
|
||||||
|
if (coverage_data.count(it.first))
|
||||||
|
log("WARNING: found duplicate coverage id \"%s\".\n", it.first.c_str());
|
||||||
|
coverage_data[it.first].first = it.second.first;
|
||||||
|
coverage_data[it.first].second += it.second.second;
|
||||||
|
}
|
||||||
|
|
||||||
for (CoverData *p = __start_yosys_cover_list; p != __stop_yosys_cover_list; p++) {
|
for (CoverData *p = __start_yosys_cover_list; p != __stop_yosys_cover_list; p++) {
|
||||||
if (coverage_data.count(p->id))
|
if (coverage_data.count(p->id))
|
||||||
log("WARNING: found duplicate coverage id \"%s\".\n", p->id);
|
log("WARNING: found duplicate coverage id \"%s\".\n", p->id);
|
||||||
|
@ -111,8 +135,25 @@ static inline std::map<std::string, std::pair<std::string, int>> get_coverage_da
|
||||||
return coverage_data;
|
return coverage_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
# define cover(_id) do { } while (0)
|
# define cover(...) do { } while (0)
|
||||||
|
# define cover_list(...) do { } while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -196,7 +237,7 @@ static inline void log_dump_args_worker(const char *p) { log_assert(*p == 0); }
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static inline void log_dump_val_worker(T *ptr) { log("%p", ptr); }
|
static inline void log_dump_val_worker(T *ptr) { log("%p", ptr); }
|
||||||
|
|
||||||
template <typename T, typename ... Args>
|
template<typename T, typename ... Args>
|
||||||
void log_dump_args_worker(const char *p, T first, Args ... args)
|
void log_dump_args_worker(const char *p, T first, Args ... args)
|
||||||
{
|
{
|
||||||
int next_p_state = 0;
|
int next_p_state = 0;
|
||||||
|
|
Loading…
Reference in a new issue