summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-08-07 01:23:01 -0700
committerGabe Black <gabeblack@google.com>2018-09-20 01:39:04 +0000
commitc18695fa7d8d1740792a5520742370794c203469 (patch)
tree6d88d9cc275b1dcd20dc0ecc712db5b9d672fc07
parente07c2d3c6e2f44dd448d1eceae4967abdf05768c (diff)
downloadgem5-c18695fa7d8d1740792a5520742370794c203469.tar.xz
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 <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
-rw-r--r--src/systemc/core/module.hh24
-rw-r--r--src/systemc/core/sc_module.cc9
2 files changed, 30 insertions, 3 deletions
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 <cassert>
+#include <map>
#include <set>
+#include <sstream>
+#include <string>
#include "systemc/core/object.hh"
#include "systemc/ext/core/sc_module.hh"
@@ -39,6 +42,23 @@
namespace sc_gem5
{
+class UniqueNameGen
+{
+ private:
+ std::map<std::string, int> 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<sc_dt::sc_logic> &)
}
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