summaryrefslogtreecommitdiff
path: root/src/python/m5/SimObject.py
diff options
context:
space:
mode:
authorAndreas Sandberg <Andreas.Sandberg@arm.com>2012-11-02 11:32:01 -0500
committerAndreas Sandberg <Andreas.Sandberg@arm.com>2012-11-02 11:32:01 -0500
commitc0ab52799ca4ebd0a51363cfedd0658e6d79b842 (patch)
treeafdf65e4593c64bbc1d5b511aacbaf0fa4b558ad /src/python/m5/SimObject.py
parent044a6525876efc61838dffa89ac52425d510b754 (diff)
downloadgem5-c0ab52799ca4ebd0a51363cfedd0658e6d79b842.tar.xz
sim: Include object header files in SWIG interfaces
When casting objects in the generated SWIG interfaces, SWIG uses classical C-style casts ( (Foo *)bar; ). In some cases, this can degenerate into the equivalent of a reinterpret_cast (mainly if only a forward declaration of the type is available). This usually works for most compilers, but it is known to break if multiple inheritance is used anywhere in the object hierarchy. This patch introduces the cxx_header attribute to Python SimObject definitions, which should be used to specify a header to include in the SWIG interface. The header should include the declaration of the wrapped object. We currently don't enforce header the use of the header attribute, but a warning will be generated for objects that do not use it.
Diffstat (limited to 'src/python/m5/SimObject.py')
-rw-r--r--src/python/m5/SimObject.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py
index b63aa22d5..c01db2a80 100644
--- a/src/python/m5/SimObject.py
+++ b/src/python/m5/SimObject.py
@@ -105,6 +105,9 @@ allClasses = {}
# dict to look up SimObjects based on path
instanceDict = {}
+# Did any of the SimObjects lack a header file?
+noCxxHeader = False
+
def public_value(key, value):
return key.startswith('_') or \
isinstance(value, (FunctionType, MethodType, ModuleType,
@@ -119,6 +122,7 @@ class MetaSimObject(type):
init_keywords = { 'abstract' : bool,
'cxx_class' : str,
'cxx_type' : str,
+ 'cxx_header' : str,
'type' : str }
# Attributes that can be set any time
keywords = { 'check' : FunctionType }
@@ -203,6 +207,12 @@ class MetaSimObject(type):
cls._value_dict['cxx_type'] = '%s *' % cls._value_dict['cxx_class']
+ if 'cxx_header' not in cls._value_dict:
+ global noCxxHeader
+ noCxxHeader = True
+ print >> sys.stderr, \
+ "warning: No header file specified for SimObject: %s" % name
+
# Export methods are automatically inherited via C++, so we
# don't want the method declarations to get inherited on the
# python side (and thus end up getting repeated in the wrapped
@@ -407,6 +417,7 @@ class MetaSimObject(type):
code('#include "params/$cls.hh"')
for param in params:
param.cxx_predecls(code)
+ code('#include "${{cls.cxx_header}}"')
cls.export_method_cxx_predecls(code)
code('''\
/**
@@ -568,15 +579,7 @@ class SimObject(object):
__metaclass__ = MetaSimObject
type = 'SimObject'
abstract = True
-
- @classmethod
- def export_method_cxx_predecls(cls, code):
- code('''
-#include <Python.h>
-
-#include "sim/serialize.hh"
-#include "sim/sim_object.hh"
-''')
+ cxx_header = "sim/sim_object.hh"
@classmethod
def export_method_swig_predecls(cls, code):
@@ -1099,10 +1102,11 @@ baseClasses = allClasses.copy()
baseInstances = instanceDict.copy()
def clear():
- global allClasses, instanceDict
+ global allClasses, instanceDict, noCxxHeader
allClasses = baseClasses.copy()
instanceDict = baseInstances.copy()
+ noCxxHeader = False
# __all__ defines the list of symbols that get exported when
# 'from config import *' is invoked. Try to keep this reasonably