From: Gabe Black Date: Thu, 6 Sep 2018 01:46:05 +0000 (-0700) Subject: systemc: Report a warning if an event or object needs to be renamed. X-Git-Tag: v19.0.0.0~1640 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dee485ff6779ef81b8d26c68041ded4065fb1402;p=gem5.git systemc: Report a warning if an event or object needs to be renamed. Change-Id: I8085ba19fd7acd69d07a1e032f2fd18b6c5fed6f Reviewed-on: https://gem5-review.googlesource.com/c/12598 Reviewed-by: Gabe Black Maintainer: Gabe Black --- diff --git a/src/systemc/core/event.cc b/src/systemc/core/event.cc index 1b43d512d..e91df1528 100644 --- a/src/systemc/core/event.cc +++ b/src/systemc/core/event.cc @@ -61,7 +61,8 @@ Event::Event(sc_core::sc_event *_sc_event, const char *_basename_cstr) : else parent = nullptr; - pickUniqueName(parent, _basename); + std::string original_name = _basename; + _basename = pickUniqueName(parent, _basename); if (parent) { Object *obj = Object::getFromScObject(parent); @@ -70,10 +71,16 @@ Event::Event(sc_core::sc_event *_sc_event, const char *_basename_cstr) : topLevelEvents.emplace(topLevelEvents.end(), _sc_event); } - if (parent) - _name = std::string(parent->name()) + "." + _basename; - else - _name = _basename; + std::string path = parent ? (std::string(parent->name()) + ".") : ""; + + if (original_name != "" && _basename != original_name) { + std::string message = path + original_name + + ". Latter declaration will be renamed to " + + path + _basename; + SC_REPORT_WARNING("(W505) object already exists", message.c_str()); + } + + _name = path + _basename; allEvents.emplace(allEvents.end(), _sc_event); diff --git a/src/systemc/core/object.cc b/src/systemc/core/object.cc index 4e4a996db..ee6a08893 100644 --- a/src/systemc/core/object.cc +++ b/src/systemc/core/object.cc @@ -110,7 +110,8 @@ Object::Object(sc_core::sc_object *_sc_obj, const char *obj_name) : parent = scheduler.current(); } - sc_gem5::pickUniqueName(parent, _basename); + std::string original_name = _basename; + _basename = sc_gem5::pickUniqueName(parent, original_name); if (parent) addObject(&parent->_gem5_object->children, _sc_obj); @@ -119,12 +120,20 @@ Object::Object(sc_core::sc_object *_sc_obj, const char *obj_name) : addObject(&allObjects, _sc_obj); - _name = _basename; sc_core::sc_object *sc_p = parent; + std::string path = ""; while (sc_p) { - _name = std::string(sc_p->basename()) + std::string(".") + _name; + path = std::string(sc_p->basename()) + std::string(".") + path; sc_p = sc_p->get_parent_object(); } + + if (_basename != original_name) { + std::string message = path + original_name + + ". Latter declaration will be renamed to " + + path + _basename; + SC_REPORT_WARNING("(W505) object already exists", message.c_str()); + } + _name = path + _basename; } Object::Object(sc_core::sc_object *_sc_obj, const Object &arg) : @@ -259,25 +268,27 @@ Object::delChildEvent(sc_core::sc_event *e) events.pop_back(); } -void -Object::pickUniqueName(std::string &base) +std::string +Object::pickUniqueName(std::string base) { std::string seed = base; while (!nameIsUnique(&children, &events, base)) base = ::sc_core::sc_gen_unique_name(seed.c_str()); + + return base; } -void -pickUniqueName(::sc_core::sc_object *parent, std::string &base) +std::string +pickUniqueName(::sc_core::sc_object *parent, std::string base) { - if (parent) { - Object::getFromScObject(parent)->pickUniqueName(base); - return; - } + if (parent) + return Object::getFromScObject(parent)->pickUniqueName(base); std::string seed = base; while (!nameIsUnique(&topLevelObjects, &topLevelEvents, base)) base = ::sc_core::sc_gen_unique_name(seed.c_str()); + + return base; } diff --git a/src/systemc/core/object.hh b/src/systemc/core/object.hh index 6d9e8ecfd..adccde5b3 100644 --- a/src/systemc/core/object.hh +++ b/src/systemc/core/object.hh @@ -90,7 +90,7 @@ class Object EventsIt addChildEvent(sc_core::sc_event *e); void delChildEvent(sc_core::sc_event *e); - void pickUniqueName(std::string &name); + std::string pickUniqueName(std::string name); private: sc_core::sc_object *_sc_obj; @@ -105,7 +105,7 @@ class Object sc_core::sc_attr_cltn cltn; }; -void pickUniqueName(::sc_core::sc_object *parent, std::string &name); +std::string pickUniqueName(::sc_core::sc_object *parent, std::string name); extern Objects topLevelObjects; extern Objects allObjects;