Gabe Black has submitted this change and it was merged. (
https://gem5-review.googlesource.com/c/public/gem5/+/12066 )
Change subject: systemc: Implement sc_gen_unique_name.
......................................................................
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 <gabebl...@google.com>
Maintainer: Gabe Black <gabebl...@google.com>
---
M src/systemc/core/module.hh
M src/systemc/core/sc_module.cc
2 files changed, 30 insertions(+), 3 deletions(-)
Approvals:
Gabe Black: Looks good to me, approved; Looks good to me, approved
diff --git a/src/systemc/core/module.hh b/src/systemc/core/module.hh
index 696d8c5..8aebff2 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 @@
sc_core::sc_module *_sc_mod;
Object *_obj;
+ UniqueNameGen nameGen;
+
public:
Module(const char *name);
@@ -77,6 +99,8 @@
}
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 bd0b2e1..1434f69 100644
--- a/src/systemc/core/sc_module.cc
+++ b/src/systemc/core/sc_module.cc
@@ -64,6 +64,8 @@
return p;
}
+UniqueNameGen nameGen;
+
} // namespace sc_gem5
namespace sc_core
@@ -643,10 +645,11 @@
}
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
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12066
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: If92c68586a85b5d27c067a75a6e9ebbf00d8c785
Gerrit-Change-Number: 12066
Gerrit-PatchSet: 9
Gerrit-Owner: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: Matthias Jung <jun...@eit.uni-kl.de>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev