From: Gabe Black Date: Tue, 7 Aug 2018 08:23:01 +0000 (-0700) Subject: systemc: Implement sc_gen_unique_name. X-Git-Tag: v19.0.0.0~1784 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c18695fa7d8d1740792a5520742370794c203469;p=gem5.git systemc: Implement sc_gen_unique_name. The Accellera implementation statically allocates the buffer it uses to build the unique names and only allocates the name generator if it's going to be used for a particular module. I assume that's to avoid allocating a large buffer if it's not going to be used. In this implementation, I use an std::string which manages its own memory and so shouldn't need to be selectively allocated. I also use a string stream to construct the name instead of sprintf. Change-Id: If92c68586a85b5d27c067a75a6e9ebbf00d8c785 Reviewed-on: https://gem5-review.googlesource.com/12066 Reviewed-by: Gabe Black Maintainer: Gabe Black --- diff --git a/src/systemc/core/module.hh b/src/systemc/core/module.hh index 696d8c570..8aebff251 100644 --- a/src/systemc/core/module.hh +++ b/src/systemc/core/module.hh @@ -31,7 +31,10 @@ #define __SYSTEMC_CORE_MODULE_HH__ #include +#include #include +#include +#include #include "systemc/core/object.hh" #include "systemc/ext/core/sc_module.hh" @@ -39,6 +42,23 @@ namespace sc_gem5 { +class UniqueNameGen +{ + private: + std::map counts; + std::string buf; + + public: + const char * + gen(std::string seed) + { + std::ostringstream os; + os << seed << "_" << counts[seed]++; + buf = os.str(); + return buf.c_str(); + } +}; + class Module { private: @@ -46,6 +66,8 @@ class Module sc_core::sc_module *_sc_mod; Object *_obj; + UniqueNameGen nameGen; + public: Module(const char *name); @@ -77,6 +99,8 @@ class Module } void pop(); + + const char *uniqueName(const char *seed) { return nameGen.gen(seed); } }; Module *currentModule(); diff --git a/src/systemc/core/sc_module.cc b/src/systemc/core/sc_module.cc index bd0b2e147..1434f69f2 100644 --- a/src/systemc/core/sc_module.cc +++ b/src/systemc/core/sc_module.cc @@ -64,6 +64,8 @@ newCThreadProcess(const char *name, ProcessFuncWrapper *func) return p; } +UniqueNameGen nameGen; + } // namespace sc_gem5 namespace sc_core @@ -643,10 +645,11 @@ at_negedge(const sc_signal_in_if &) } const char * -sc_gen_unique_name(const char *) +sc_gen_unique_name(const char *seed) { - warn("%s not implemented.\n", __PRETTY_FUNCTION__); - return ""; + ::sc_gem5::Module *mod = ::sc_gem5::currentModule(); + return mod ? mod->uniqueName(seed) : + ::sc_gem5::nameGen.gen(seed); } bool