Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/12439
Change subject: systemc: Ensure all objects and events have unique names.
......................................................................
systemc: Ensure all objects and events have unique names.
Change-Id: I59b78048849953773b80bb2dac9b834762625331
---
M src/systemc/core/event.cc
M src/systemc/core/object.cc
M src/systemc/core/object.hh
3 files changed, 45 insertions(+), 4 deletions(-)
diff --git a/src/systemc/core/event.cc b/src/systemc/core/event.cc
index 4f3d4f9..1b43d51 100644
--- a/src/systemc/core/event.cc
+++ b/src/systemc/core/event.cc
@@ -61,6 +61,8 @@
else
parent = nullptr;
+ pickUniqueName(parent, _basename);
+
if (parent) {
Object *obj = Object::getFromScObject(parent);
obj->addChildEvent(_sc_event);
diff --git a/src/systemc/core/object.cc b/src/systemc/core/object.cc
index b97fd90..0fc046e 100644
--- a/src/systemc/core/object.cc
+++ b/src/systemc/core/object.cc
@@ -32,6 +32,7 @@
#include <algorithm>
#include "base/logging.hh"
+#include "systemc/core/event.hh"
#include "systemc/core/module.hh"
#include "systemc/core/scheduler.hh"
@@ -67,6 +68,18 @@
objects->pop_back();
}
+bool
+nameIsUnique(Objects *objects, Events *events, const std::string &name)
+{
+ for (auto obj: *objects)
+ if (!strcmp(obj->basename(), name.c_str()))
+ return false;
+ for (auto event: *events)
+ if (!strcmp(event->basename(), name.c_str()))
+ return false;
+ return true;
+}
+
} // anonymous namespace
Object::Object(sc_core::sc_object *_sc_obj) : Object(_sc_obj, "object") {}
@@ -95,12 +108,13 @@
// Our parent is the currently running process.
parent = scheduler.current();
}
- if (parent) {
+
+ sc_gem5::pickUniqueName(parent, _basename);
+
+ if (parent)
addObject(&parent->_gem5_object->children, _sc_obj);
- } else {
- // We're a top level object.
+ else
addObject(&topLevelObjects, _sc_obj);
- }
addObject(&allObjects, _sc_obj);
@@ -244,6 +258,27 @@
events.pop_back();
}
+void
+Object::pickUniqueName(std::string &base)
+{
+ std::string seed = base;
+ while (!nameIsUnique(&children, &events, base))
+ base = ::sc_core::sc_gen_unique_name(seed.c_str());
+}
+
+void
+pickUniqueName(::sc_core::sc_object *parent, std::string &base)
+{
+ if (parent) {
+ Object::getFromScObject(parent)->pickUniqueName(base);
+ return;
+ }
+
+ std::string seed = base;
+ while (!nameIsUnique(&topLevelObjects, &topLevelEvents, base))
+ base = ::sc_core::sc_gen_unique_name(seed.c_str());
+}
+
Objects topLevelObjects;
Objects allObjects;
diff --git a/src/systemc/core/object.hh b/src/systemc/core/object.hh
index cb759d8..6d9e8ec 100644
--- a/src/systemc/core/object.hh
+++ b/src/systemc/core/object.hh
@@ -90,6 +90,8 @@
EventsIt addChildEvent(sc_core::sc_event *e);
void delChildEvent(sc_core::sc_event *e);
+ void pickUniqueName(std::string &name);
+
private:
sc_core::sc_object *_sc_obj;
@@ -103,6 +105,8 @@
sc_core::sc_attr_cltn cltn;
};
+void pickUniqueName(::sc_core::sc_object *parent, std::string &name);
+
extern Objects topLevelObjects;
extern Objects allObjects;
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12439
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: I59b78048849953773b80bb2dac9b834762625331
Gerrit-Change-Number: 12439
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev