From 1a2acd8765ab986351f06452d2c0d38cd6f36f9c Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Sat, 18 Jan 2025 12:59:07 +1300 Subject: [PATCH] Move source_location to register.h Revert `PrettyHelp::get_current()` for no args since we can use `Pass::location` instead. --- kernel/log_help.cc | 4 +--- kernel/log_help.h | 17 +---------------- kernel/register.cc | 11 ++++++----- kernel/register.h | 26 ++++++++++++++++++++++---- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/kernel/log_help.cc b/kernel/log_help.cc index ada51be60..82967b0b6 100644 --- a/kernel/log_help.cc +++ b/kernel/log_help.cc @@ -84,12 +84,10 @@ PrettyHelp::~PrettyHelp() current_help = _prior; } -PrettyHelp *PrettyHelp::get_current(source_location location) +PrettyHelp *PrettyHelp::get_current() { 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; } diff --git a/kernel/log_help.h b/kernel/log_help.h index fec888548..b460bce62 100644 --- a/kernel/log_help.h +++ b/kernel/log_help.h @@ -23,19 +23,6 @@ #include "kernel/yosys_common.h" #include "kernel/json.h" -#ifdef YOSYS_ENABLE_SOURCE_LOCATION -#include -using std::experimental::source_location; -#else -struct source_location { // dummy placeholder - int line() const { return 0; } - int column() const { return 0; } - const char* file_name() const { return "unknown"; } - const char* function_name() const { return "unknown"; } - static const source_location current(...) { return source_location(); } -}; -#endif - YOSYS_NAMESPACE_BEGIN struct ContentListing { @@ -94,7 +81,7 @@ public: PrettyHelp(Mode mode = LOG); ~PrettyHelp(); - static PrettyHelp *get_current(source_location location = source_location::current()); + static PrettyHelp *get_current(); bool has_content() { return _root_listing.content.size();} const vector get_content() { @@ -102,8 +89,6 @@ 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() diff --git a/kernel/register.cc b/kernel/register.cc index 6d2d5a19d..e4d968249 100644 --- a/kernel/register.cc +++ b/kernel/register.cc @@ -100,7 +100,8 @@ std::map backend_register; std::vector Frontend::next_args; -Pass::Pass(std::string name, std::string short_help) : pass_name(name), short_help(short_help) +Pass::Pass(std::string name, std::string short_help, source_location location) : + pass_name(name), short_help(short_help), location(location) { next_queued_pass = first_queued_pass; first_queued_pass = this; @@ -447,8 +448,8 @@ void ScriptPass::help_script() script(); } -Frontend::Frontend(std::string name, std::string short_help) : - Pass(name.rfind("=", 0) == 0 ? name.substr(1) : "read_" + name, short_help), +Frontend::Frontend(std::string name, std::string short_help, source_location location) : + Pass(name.rfind("=", 0) == 0 ? name.substr(1) : "read_" + name, short_help, location), frontend_name(name.rfind("=", 0) == 0 ? name.substr(1) : name) { } @@ -631,8 +632,8 @@ void Frontend::frontend_call(RTLIL::Design *design, std::istream *f, std::string } } -Backend::Backend(std::string name, std::string short_help) : - Pass(name.rfind("=", 0) == 0 ? name.substr(1) : "write_" + name, short_help), +Backend::Backend(std::string name, std::string short_help, source_location location) : + Pass(name.rfind("=", 0) == 0 ? name.substr(1) : "write_" + name, short_help, location), backend_name(name.rfind("=", 0) == 0 ? name.substr(1) : name) { } diff --git a/kernel/register.h b/kernel/register.h index 6e7b74d5c..9830b1d13 100644 --- a/kernel/register.h +++ b/kernel/register.h @@ -23,12 +23,27 @@ #include "kernel/yosys_common.h" #include "kernel/yosys.h" +#ifdef YOSYS_ENABLE_SOURCE_LOCATION +#include +using std::experimental::source_location; +#else +struct source_location { // dummy placeholder + int line() const { return 0; } + int column() const { return 0; } + const char* file_name() const { return "unknown"; } + const char* function_name() const { return "unknown"; } + static const source_location current(...) { return source_location(); } +}; +#endif + YOSYS_NAMESPACE_BEGIN struct Pass { std::string pass_name, short_help; - Pass(std::string name, std::string short_help = "** document me **"); + source_location location; + Pass(std::string name, std::string short_help = "** document me **", + source_location location = source_location::current()); virtual ~Pass(); virtual void help(); @@ -81,7 +96,8 @@ struct ScriptPass : Pass RTLIL::Design *active_design; std::string active_run_from, active_run_to; - ScriptPass(std::string name, std::string short_help = "** document me **") : Pass(name, short_help) { } + ScriptPass(std::string name, std::string short_help = "** document me **", source_location location = source_location::current()) : + Pass(name, short_help, location) { } virtual void script() = 0; @@ -99,7 +115,8 @@ struct Frontend : Pass static std::string last_here_document; std::string frontend_name; - Frontend(std::string name, std::string short_help = "** document me **"); + Frontend(std::string name, std::string short_help = "** document me **", + source_location location = source_location::current()); void run_register() override; ~Frontend() override; void execute(std::vector args, RTLIL::Design *design) override final; @@ -115,7 +132,8 @@ struct Frontend : Pass struct Backend : Pass { std::string backend_name; - Backend(std::string name, std::string short_help = "** document me **"); + Backend(std::string name, std::string short_help = "** document me **", + source_location location = source_location::current()); void run_register() override; ~Backend() override; void execute(std::vector args, RTLIL::Design *design) override final;