#include <algorithm>
#include "base/logging.hh"
+#include "systemc/core/event.hh"
#include "systemc/core/module.hh"
#include "systemc/core/scheduler.hh"
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") {}
// 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);
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;
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;
sc_core::sc_attr_cltn cltn;
};
+void pickUniqueName(::sc_core::sc_object *parent, std::string &name);
+
extern Objects topLevelObjects;
extern Objects allObjects;