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>
#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"
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:
sc_core::sc_module *_sc_mod;
Object *_obj;
+ UniqueNameGen nameGen;
+
public:
Module(const char *name);
}
void pop();
+
+ const char *uniqueName(const char *seed) { return nameGen.gen(seed); }
};
Module *currentModule();
return p;
}
+UniqueNameGen nameGen;
+
} // namespace sc_gem5
namespace sc_core
}
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