Skip to content

Commit ec3f384

Browse files
committed
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.
1 parent 7b0c1fe commit ec3f384

File tree

6 files changed

+28
-39
lines changed

6 files changed

+28
-39
lines changed

kernel/drivertools.cc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -865,41 +865,41 @@ DriveSpec DriverMap::operator()(DriveSpec spec)
865865
return result;
866866
}
867867

868-
const char *log_signal(DriveChunkWire const &chunk)
868+
std::string log_signal(DriveChunkWire const &chunk)
869869
{
870870
const char *id = log_id(chunk.wire->name);
871871
if (chunk.is_whole())
872872
return id;
873873
if (chunk.width == 1)
874-
return log_str(stringf("%s [%d]", id, chunk.offset));
875-
return log_str(stringf("%s [%d:%d]", id, chunk.offset + chunk.width - 1, chunk.offset));
874+
return stringf("%s [%d]", id, chunk.offset);
875+
return stringf("%s [%d:%d]", id, chunk.offset + chunk.width - 1, chunk.offset);
876876
}
877877

878878

879-
const char *log_signal(DriveChunkPort const &chunk)
879+
std::string log_signal(DriveChunkPort const &chunk)
880880
{
881881
const char *cell_id = log_id(chunk.cell->name);
882882
const char *port_id = log_id(chunk.port);
883883
if (chunk.is_whole())
884-
return log_str(stringf("%s <%s>", cell_id, port_id));
884+
return stringf("%s <%s>", cell_id, port_id);
885885
if (chunk.width == 1)
886-
return log_str(stringf("%s <%s> [%d]", cell_id, port_id, chunk.offset));
887-
return log_str(stringf("%s <%s> [%d:%d]", cell_id, port_id, chunk.offset + chunk.width - 1, chunk.offset));
886+
return stringf("%s <%s> [%d]", cell_id, port_id, chunk.offset);
887+
return stringf("%s <%s> [%d:%d]", cell_id, port_id, chunk.offset + chunk.width - 1, chunk.offset);
888888
}
889889

890-
const char *log_signal(DriveChunkMarker const &chunk)
890+
std::string log_signal(DriveChunkMarker const &chunk)
891891
{
892892
if (chunk.width == 1)
893-
return log_str(stringf("<marker %d> [%d]", chunk.marker, chunk.offset));
894-
return log_str(stringf("<marker %d> [%d:%d]", chunk.marker, chunk.offset + chunk.width - 1, chunk.offset));
893+
return stringf("<marker %d> [%d]", chunk.marker, chunk.offset);
894+
return stringf("<marker %d> [%d:%d]", chunk.marker, chunk.offset + chunk.width - 1, chunk.offset);
895895
}
896896

897-
const char *log_signal(DriveChunk const &chunk)
897+
std::string log_signal(DriveChunk const &chunk)
898898
{
899899
switch (chunk.type())
900900
{
901901
case DriveType::NONE:
902-
return log_str(stringf("<none x%d>", chunk.size()));
902+
return stringf("<none x%d>", chunk.size());
903903
case DriveType::CONSTANT:
904904
return log_const(chunk.constant());
905905
case DriveType::WIRE:
@@ -917,14 +917,14 @@ const char *log_signal(DriveChunk const &chunk)
917917
str += log_signal(single);
918918
}
919919
str += ">";
920-
return log_str(str);
920+
return str;
921921
}
922922
default:
923923
log_abort();
924924
}
925925
}
926926

927-
const char *log_signal(DriveSpec const &spec)
927+
std::string log_signal(DriveSpec const &spec)
928928
{
929929
auto &chunks = spec.chunks();
930930
if (chunks.empty())
@@ -943,7 +943,7 @@ const char *log_signal(DriveSpec const &spec)
943943
}
944944
str += " }";
945945

946-
return log_str(str);
946+
return str;
947947
}
948948

949949
YOSYS_NAMESPACE_END

kernel/drivertools.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#ifndef DRIVERTOOLS_H
2121
#define DRIVERTOOLS_H
2222

23+
#include <string>
2324
#include <type_traits>
2425

2526
#include "kernel/rtlil.h"
@@ -39,11 +40,11 @@ struct DriveChunk;
3940

4041
struct DriveSpec;
4142

42-
const char *log_signal(DriveChunkWire const &chunk);
43-
const char *log_signal(DriveChunkPort const &chunk);
44-
const char *log_signal(DriveChunkMarker const &chunk);
45-
const char *log_signal(DriveChunk const &chunk);
46-
const char *log_signal(DriveSpec const &chunk);
43+
std::string log_signal(DriveChunkWire const &chunk);
44+
std::string log_signal(DriveChunkPort const &chunk);
45+
std::string log_signal(DriveChunkMarker const &chunk);
46+
std::string log_signal(DriveChunk const &chunk);
47+
std::string log_signal(DriveSpec const &chunk);
4748

4849
enum class DriveType : unsigned char
4950
{

kernel/functional.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -635,15 +635,15 @@ class FunctionalIRConstruction {
635635
}
636636
}
637637
}
638-
void undriven(const char *name) {
638+
void undriven(const std::string& name) {
639639
log_error("The design contains an undriven signal %s. This is not supported by the functional backend. "
640-
"Call setundef with appropriate options to avoid this error.\n", name);
640+
"Call setundef with appropriate options to avoid this error.\n", name.c_str());
641641
}
642642
// we perform this check separately to give better error messages that include the wire or port name
643643
void check_undriven(DriveSpec const& spec, std::string const& name) {
644644
for(auto const &chunk : spec.chunks())
645645
if(chunk.is_none())
646-
undriven(name.c_str());
646+
undriven(name);
647647
}
648648
public:
649649
void process_queue()
@@ -706,11 +706,11 @@ class FunctionalIRConstruction {
706706
factory.update_pending(pending, node);
707707
} else if (chunk.is_multiple()) {
708708
log_error("Signal %s has multiple drivers. This is not supported by the functional backend. "
709-
"If tristate drivers are used, call tristate -formal to avoid this error.\n", log_signal(chunk));
709+
"If tristate drivers are used, call tristate -formal to avoid this error.\n", log_signal(chunk).c_str());
710710
} else if (chunk.is_none()) {
711711
undriven(log_signal(chunk));
712712
} else {
713-
log_error("unhandled drivespec: %s\n", log_signal(chunk));
713+
log_error("unhandled drivespec: %s\n", log_signal(chunk).c_str());
714714
log_abort();
715715
}
716716
} else {

kernel/log.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -675,16 +675,6 @@ const char *log_id(const RTLIL::IdString &str)
675675
return p+1;
676676
}
677677

678-
const char *log_str(const char *str)
679-
{
680-
log_id_cache.push_back(strdup(str));
681-
return log_id_cache.back();
682-
}
683-
684-
const char *log_str(std::string const &str) {
685-
return log_str(str.c_str());
686-
}
687-
688678
void log_module(RTLIL::Module *module, std::string indent)
689679
{
690680
std::stringstream buf;

kernel/log.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@ void log_check_expected();
206206
const char *log_signal(const RTLIL::SigSpec &sig, bool autoint = true);
207207
const char *log_const(const RTLIL::Const &value, bool autoint = true);
208208
const char *log_id(const RTLIL::IdString &id);
209-
const char *log_str(const char *str);
210-
const char *log_str(std::string const &str);
211209

212210
template<typename T> static inline const char *log_id(T *obj, const char *nullstr = nullptr) {
213211
if (nullstr && obj == nullptr)

passes/cmds/example_dt.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ struct ExampleDtPass : public Pass
173173
node.set_function(ID($$undriven));
174174

175175
} else {
176-
log_error("unhandled drivespec: %s\n", log_signal(chunk));
176+
log_error("unhandled drivespec: %s\n", log_signal(chunk).c_str());
177177
log_abort();
178178
}
179179
} else {
@@ -243,7 +243,7 @@ struct ExampleDtPass : public Pass
243243
log(")\n");
244244
if (ref.has_sparse_attr())
245245
log("// wire %s\n", log_id(ref.sparse_attr()));
246-
log("// was #%d %s\n", ref.attr(), log_signal(queue[ref.attr()]));
246+
log("// was #%d %s\n", ref.attr(), log_signal(queue[ref.attr()]).c_str());
247247
}
248248

249249
for (auto const &key : compute_graph.keys())

0 commit comments

Comments
 (0)