summaryrefslogtreecommitdiff
path: root/src/systemc/core/object.cc
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-09-28 17:12:46 -0700
committerGabe Black <gabeblack@google.com>2018-10-16 00:40:21 +0000
commit163eb3c56b115e649c72fceff89c8370b6e7306f (patch)
treee66057d1e2107b72aad9e256e4620c287d6cbe37 /src/systemc/core/object.cc
parent3fe6ebb325f3630af32d9210a7121eb5710bf42f (diff)
downloadgem5-163eb3c56b115e649c72fceff89c8370b6e7306f.tar.xz
systemc: Centralize how object parents are chosen.
There's a lot of repeated code for this. Also, the sc_vector type needs to be able to artificially inject a parent for the objects it creates. Change-Id: I76f9b551632cd2cd70e26741b215290b35c382e9 Reviewed-on: https://gem5-review.googlesource.com/c/13194 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/systemc/core/object.cc')
-rw-r--r--src/systemc/core/object.cc37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/systemc/core/object.cc b/src/systemc/core/object.cc
index ee6a08893..91e3cb36a 100644
--- a/src/systemc/core/object.cc
+++ b/src/systemc/core/object.cc
@@ -30,6 +30,7 @@
#include "systemc/core/object.hh"
#include <algorithm>
+#include <stack>
#include "base/logging.hh"
#include "systemc/core/event.hh"
@@ -91,9 +92,7 @@ Object::Object(sc_core::sc_object *_sc_obj, const char *obj_name) :
if (_basename == "")
_basename = ::sc_core::sc_gen_unique_name("object");
- Module *p = currentModule();
- if (!p)
- p = callbackModule();
+ parent = pickParentObj();
Module *n = newModule();
if (n) {
@@ -101,15 +100,6 @@ Object::Object(sc_core::sc_object *_sc_obj, const char *obj_name) :
n->finish(this);
}
- if (p) {
- // We're "within" a parent module, ie we're being created while its
- // constructor or end_of_elaboration callback is running.
- parent = p->obj()->_sc_obj;
- } else if (scheduler.current()) {
- // Our parent is the currently running process.
- parent = scheduler.current();
- }
-
std::string original_name = _basename;
_basename = sc_gem5::pickUniqueName(parent, original_name);
@@ -308,4 +298,27 @@ findObject(const char *name, const Objects &objects)
return it == allObjects.end() ? nullptr : *it;
}
+namespace
+{
+
+std::stack<sc_core::sc_object *> objParentStack;
+
+} // anonymous namespace
+
+sc_core::sc_object *
+pickParentObj()
+{
+ if (!objParentStack.empty())
+ return objParentStack.top();
+
+ Process *p = scheduler.current();
+ if (p)
+ return p;
+
+ return nullptr;
+}
+
+void pushParentObj(sc_core::sc_object *obj) { objParentStack.push(obj); }
+void popParentObj() { objParentStack.pop(); }
+
} // namespace sc_gem5