From cfe48360f933329f10baa0baa1c750493180d891 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Tue, 28 Aug 2018 21:23:29 -0700 Subject: 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 Maintainer: Gabe Black --- src/systemc/core/event.cc | 2 ++ src/systemc/core/object.cc | 43 +++++++++++++++++++++++++++++++++++++++---- src/systemc/core/object.hh | 4 ++++ 3 files changed, 45 insertions(+), 4 deletions(-) (limited to 'src') 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 #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; -- cgit v1.2.3