From c7017f7f79899a3372678bea829fb92764f370e0 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Thu, 3 Jul 2025 23:47:25 +0000 Subject: [PATCH] Remove `log_str()` functions and convert their `log_signal()` users to return `std::string` This is a small but easy step towards removing the `log_id_cache`. See issue #5210. --- kernel/drivertools.cc | 30 +++++++++++++++--------------- kernel/drivertools.h | 11 ++++++----- kernel/functional.cc | 4 ++-- kernel/log.cc | 10 ---------- kernel/log.h | 2 -- 5 files changed, 23 insertions(+), 34 deletions(-) diff --git a/kernel/drivertools.cc b/kernel/drivertools.cc index b8905d68c..6290f4470 100644 --- a/kernel/drivertools.cc +++ b/kernel/drivertools.cc @@ -865,41 +865,41 @@ DriveSpec DriverMap::operator()(DriveSpec spec) return result; } -const char *log_signal(DriveChunkWire const &chunk) +std::string log_signal(DriveChunkWire const &chunk) { const char *id = log_id(chunk.wire->name); if (chunk.is_whole()) return id; if (chunk.width == 1) - return log_str(stringf("%s [%d]", id, chunk.offset)); - return log_str(stringf("%s [%d:%d]", id, chunk.offset + chunk.width - 1, chunk.offset)); + return stringf("%s [%d]", id, chunk.offset); + return stringf("%s [%d:%d]", id, chunk.offset + chunk.width - 1, chunk.offset); } -const char *log_signal(DriveChunkPort const &chunk) +std::string log_signal(DriveChunkPort const &chunk) { const char *cell_id = log_id(chunk.cell->name); const char *port_id = log_id(chunk.port); if (chunk.is_whole()) - return log_str(stringf("%s <%s>", cell_id, port_id)); + return stringf("%s <%s>", cell_id, port_id); if (chunk.width == 1) - return log_str(stringf("%s <%s> [%d]", cell_id, port_id, chunk.offset)); - return log_str(stringf("%s <%s> [%d:%d]", cell_id, port_id, chunk.offset + chunk.width - 1, chunk.offset)); + return stringf("%s <%s> [%d]", cell_id, port_id, chunk.offset); + return stringf("%s <%s> [%d:%d]", cell_id, port_id, chunk.offset + chunk.width - 1, chunk.offset); } -const char *log_signal(DriveChunkMarker const &chunk) +std::string log_signal(DriveChunkMarker const &chunk) { if (chunk.width == 1) - return log_str(stringf(" [%d]", chunk.marker, chunk.offset)); - return log_str(stringf(" [%d:%d]", chunk.marker, chunk.offset + chunk.width - 1, chunk.offset)); + return stringf(" [%d]", chunk.marker, chunk.offset); + return stringf(" [%d:%d]", chunk.marker, chunk.offset + chunk.width - 1, chunk.offset); } -const char *log_signal(DriveChunk const &chunk) +std::string log_signal(DriveChunk const &chunk) { switch (chunk.type()) { case DriveType::NONE: - return log_str(stringf("", chunk.size())); + return stringf("", chunk.size()); case DriveType::CONSTANT: return log_const(chunk.constant()); case DriveType::WIRE: @@ -917,14 +917,14 @@ const char *log_signal(DriveChunk const &chunk) str += log_signal(single); } str += ">"; - return log_str(str); + return str; } default: log_abort(); } } -const char *log_signal(DriveSpec const &spec) +std::string log_signal(DriveSpec const &spec) { auto &chunks = spec.chunks(); if (chunks.empty()) @@ -943,7 +943,7 @@ const char *log_signal(DriveSpec const &spec) } str += " }"; - return log_str(str); + return str; } YOSYS_NAMESPACE_END diff --git a/kernel/drivertools.h b/kernel/drivertools.h index d46217da5..ba7b2aa84 100644 --- a/kernel/drivertools.h +++ b/kernel/drivertools.h @@ -20,6 +20,7 @@ #ifndef DRIVERTOOLS_H #define DRIVERTOOLS_H +#include #include #include "kernel/rtlil.h" @@ -39,11 +40,11 @@ struct DriveChunk; struct DriveSpec; -const char *log_signal(DriveChunkWire const &chunk); -const char *log_signal(DriveChunkPort const &chunk); -const char *log_signal(DriveChunkMarker const &chunk); -const char *log_signal(DriveChunk const &chunk); -const char *log_signal(DriveSpec const &chunk); +std::string log_signal(DriveChunkWire const &chunk); +std::string log_signal(DriveChunkPort const &chunk); +std::string log_signal(DriveChunkMarker const &chunk); +std::string log_signal(DriveChunk const &chunk); +std::string log_signal(DriveSpec const &chunk); enum class DriveType : unsigned char { diff --git a/kernel/functional.cc b/kernel/functional.cc index 211527926..66dc2e1eb 100644 --- a/kernel/functional.cc +++ b/kernel/functional.cc @@ -638,7 +638,7 @@ private: } } } - void undriven(const char *name) { + void undriven(const std::string& name) { log_error("The design contains an undriven signal %s. This is not supported by the functional backend. " "Call setundef with appropriate options to avoid this error.\n", name); } @@ -646,7 +646,7 @@ private: void check_undriven(DriveSpec const& spec, std::string const& name) { for(auto const &chunk : spec.chunks()) if(chunk.is_none()) - undriven(name.c_str()); + undriven(name); } public: void process_queue() diff --git a/kernel/log.cc b/kernel/log.cc index 0dd56a04f..a03f16350 100644 --- a/kernel/log.cc +++ b/kernel/log.cc @@ -621,16 +621,6 @@ const char *log_id(const RTLIL::IdString &str) return log_id_cache.back(); } -const char *log_str(const char *str) -{ - log_id_cache.push_back(strdup(str)); - return log_id_cache.back(); -} - -const char *log_str(std::string const &str) { - return log_str(str.c_str()); -} - void log_module(RTLIL::Module *module, std::string indent) { std::stringstream buf; diff --git a/kernel/log.h b/kernel/log.h index 5143524bf..1f32e8185 100644 --- a/kernel/log.h +++ b/kernel/log.h @@ -256,8 +256,6 @@ void log_check_expected(); const char *log_signal(const RTLIL::SigSpec &sig, bool autoint = true); const char *log_const(const RTLIL::Const &value, bool autoint = true); const char *log_id(const RTLIL::IdString &id); -const char *log_str(const char *str); -const char *log_str(std::string const &str); template static inline const char *log_id(T *obj, const char *nullstr = nullptr) { if (nullstr && obj == nullptr)