From a0da79981b51457f6962f05564c1a75fed3f64a8 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Fri, 21 Mar 2025 10:26:10 +1300 Subject: [PATCH] log_help: Better location tracking Assign root location in call to `PrettyHelp::get_current()`. Set default `source_file` to `"unknown"`, since that appears to be the default value rather than `nullptr`. --- kernel/log_help.cc | 13 +++++++------ kernel/log_help.h | 10 ++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/kernel/log_help.cc b/kernel/log_help.cc index 7c9b88f06..ada51be60 100644 --- a/kernel/log_help.cc +++ b/kernel/log_help.cc @@ -25,7 +25,7 @@ Json ContentListing::to_json() { Json::object object; object["type"] = type; if (body.length()) object["body"] = body; - if (source_file != nullptr) object["source_file"] = source_file; + if (strcmp(source_file, "unknown") != 0) object["source_file"] = source_file; if (source_line != 0) object["source_line"] = source_line; Json::array content_array; for (auto child : content) content_array.push_back(child->to_json()); @@ -84,12 +84,13 @@ PrettyHelp::~PrettyHelp() current_help = _prior; } -PrettyHelp *PrettyHelp::get_current() +PrettyHelp *PrettyHelp::get_current(source_location location) { - if (current_help != nullptr) - return current_help; - else - return new PrettyHelp(); + if (current_help == nullptr) + new PrettyHelp(); + current_help->_root_listing.source_file = location.file_name(); + current_help->_root_listing.source_line = location.line(); + return current_help; } void PrettyHelp::usage(const string &usage, diff --git a/kernel/log_help.h b/kernel/log_help.h index e4ddc52d6..fec888548 100644 --- a/kernel/log_help.h +++ b/kernel/log_help.h @@ -30,8 +30,8 @@ using std::experimental::source_location; struct source_location { // dummy placeholder int line() const { return 0; } int column() const { return 0; } - const char* file_name() const { return nullptr; } - const char* function_name() const { return nullptr; } + const char* file_name() const { return "unknown"; } + const char* function_name() const { return "unknown"; } static const source_location current(...) { return source_location(); } }; #endif @@ -41,7 +41,7 @@ YOSYS_NAMESPACE_BEGIN struct ContentListing { string type = "root"; string body = ""; - const char* source_file = nullptr; + const char* source_file = "unknown"; int source_line = 0; vector content = {}; ContentListing *parent = nullptr; @@ -94,7 +94,7 @@ public: PrettyHelp(Mode mode = LOG); ~PrettyHelp(); - static PrettyHelp *get_current(); + static PrettyHelp *get_current(source_location location = source_location::current()); bool has_content() { return _root_listing.content.size();} const vector get_content() { @@ -102,6 +102,8 @@ public: return content; } + const char* source_file() const { return _root_listing.source_file; } + void usage( const string &usage, const source_location location = source_location::current()