summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-08-28 21:23:29 -0700
committerGabe Black <gabeblack@google.com>2018-10-03 00:13:28 +0000
commitcfe48360f933329f10baa0baa1c750493180d891 (patch)
treefc38b60bb91f0a64f68cb0edf4eee9462658bb6c /src
parentae373556b71e4d4c5c2022110e7a4b00c55666a9 (diff)
downloadgem5-cfe48360f933329f10baa0baa1c750493180d891.tar.xz
systemc: Ensure all objects and events have unique names.
Change-Id: I59b78048849953773b80bb2dac9b834762625331 Reviewed-on: https://gem5-review.googlesource.com/c/12439 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/systemc/core/event.cc2
-rw-r--r--src/systemc/core/object.cc43
-rw-r--r--src/systemc/core/object.hh4
3 files changed, 45 insertions, 4 deletions
diff --git a/src/systemc/core/event.cc b/src/systemc/core/event.cc
index 4f3d4f9c1..1b43d512d 100644
--- a/src/systemc/core/event.cc
+++ b/src/systemc/core/event.cc
@@ -61,6 +61,8 @@ Event::Event(sc_core::sc_event *_sc_event, const char *_basename_cstr) :
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 b97fd900a..0fc046ecc 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 @@ popObject(Objects *objects, const std::string &name)
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 @@ Object::Object(sc_core::sc_object *_sc_obj, const char *obj_name) :
// 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 @@ Object::delChildEvent(sc_core::sc_event *e)
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 cb759d890..6d9e8ecfd 100644
--- a/src/systemc/core/object.hh
+++ b/src/systemc/core/object.hh
@@ -90,6 +90,8 @@ class Object
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 @@ class Object
sc_core::sc_attr_cltn cltn;
};
+void pickUniqueName(::sc_core::sc_object *parent, std::string &name);
+
extern Objects topLevelObjects;
extern Objects allObjects;