summaryrefslogtreecommitdiff
path: root/src/python/m5
diff options
context:
space:
mode:
Diffstat (limited to 'src/python/m5')
-rw-r--r--src/python/m5/SimObject.py5
-rw-r--r--src/python/m5/params.py13
2 files changed, 18 insertions, 0 deletions
diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py
index 8aa7260e7..14499759c 100644
--- a/src/python/m5/SimObject.py
+++ b/src/python/m5/SimObject.py
@@ -784,6 +784,11 @@ class SimObject(object):
self._parent = parent
self._name = name
+ # Return parent object of this SimObject, not implemented by SimObjectVector
+ # because the elements in a SimObjectVector may not share the same parent
+ def get_parent(self):
+ return self._parent
+
# Also implemented by SimObjectVector
def get_name(self):
return self._name
diff --git a/src/python/m5/params.py b/src/python/m5/params.py
index 981bb0d37..ff645bb37 100644
--- a/src/python/m5/params.py
+++ b/src/python/m5/params.py
@@ -247,6 +247,19 @@ class SimObjectVector(VectorParamValue):
a.append(v.get_config_as_dict())
return a
+ # If we are replacing an item in the vector, make sure to set the
+ # parent reference of the new SimObject to be the same as the parent
+ # of the SimObject being replaced. Useful to have if we created
+ # a SimObjectVector of temporary objects that will be modified later in
+ # configuration scripts.
+ def __setitem__(self, key, value):
+ val = self[key]
+ if value.has_parent():
+ warn("SimObject %s already has a parent" % value.get_name() +\
+ " that is being overwritten by a SimObjectVector")
+ value.set_parent(val.get_parent(), val._name)
+ super(SimObjectVector, self).__setitem__(key, value)
+
class VectorParamDesc(ParamDesc):
# Convert assigned value to appropriate type. If the RHS is not a
# list or tuple, it generates a single-element list.