sim: Add a SimObject python field which overrides the default c++ base.
authorGabe Black <gabeblack@google.com>
Tue, 1 May 2018 23:35:54 +0000 (16:35 -0700)
committerGabe Black <gabeblack@google.com>
Fri, 15 Jun 2018 00:03:09 +0000 (00:03 +0000)
The base for the c++ version of python SimObject classes is normally
inferred from the c++ version of the python base. There are some
specific cases where that isn't desired. This change makes it possible
to override the default behavior.

Change-Id: I2438dad767e2f56823bad42b3e6c7714ce97ef79
Reviewed-on: https://gem5-review.googlesource.com/10662
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>

src/python/m5/SimObject.py

index e051a972bb33efcab39f9e19cb2693feaac46b70..0c9e738f623268229872ccee582f031f5b797837 100644 (file)
@@ -407,6 +407,7 @@ class MetaSimObject(type):
         'cxx_type' : str,
         'cxx_header' : str,
         'type' : str,
+        'cxx_base' : (str, type(None)),
         'cxx_extra_bases' : list,
         'cxx_exports' : list,
         'cxx_param_exports' : list,
@@ -734,8 +735,19 @@ module_init(py::module &m_internal)
         code()
         code.dedent()
 
-        bases = [ cls._base.cxx_class ] + cls.cxx_extra_bases if \
-                cls._base else cls.cxx_extra_bases
+        bases = []
+        if 'cxx_base' in cls._value_dict:
+            # If the c++ base class implied by python inheritance was
+            # overridden, use that value.
+            if cls.cxx_base:
+                bases.append(cls.cxx_base)
+        elif cls._base:
+            # If not and if there was a SimObject base, use its c++ class
+            # as this class' base.
+            bases.append(cls._base.cxx_class)
+        # Add in any extra bases that were requested.
+        bases.extend(cls.cxx_extra_bases)
+
         if bases:
             base_str = ", ".join(bases)
             code('py::class_<${{cls.cxx_class}}, ${base_str}, ' \