+ # See ParamValue.cxx_predecls for description.
+ def cxx_predecls(cls, code):
+ code('#include "params/$cls.hh"')
+
+ # See ParamValue.swig_predecls for description.
+ def swig_predecls(cls, code):
+ code('%import "python/m5/internal/param_$cls.i"')
+
+ # Hook for exporting additional C++ methods to Python via SWIG.
+ # Default is none, override using @classmethod in class definition.
+ def export_methods(cls, code):
+ pass
+
+ # Generate the code needed as a prerequisite for the C++ methods
+ # exported via export_methods() to be compiled in the _wrap.cc
+ # file. Typically generates one or more #include statements. If
+ # any methods are exported, typically at least the C++ header
+ # declaring the relevant SimObject class must be included.
+ def export_method_cxx_predecls(cls, code):
+ pass
+
+ # Generate the code needed as a prerequisite for the C++ methods
+ # exported via export_methods() to be processed by SWIG.
+ # Typically generates one or more %include or %import statements.
+ # If any methods are exported, typically at least the C++ header
+ # declaring the relevant SimObject class must be included.
+ def export_method_swig_predecls(cls, code):
+ pass
+
+ # Generate the declaration for this object for wrapping with SWIG.
+ # Generates code that goes into a SWIG .i file. Called from
+ # src/SConscript.
+ def swig_decl(cls, code):
+ class_path = cls.cxx_class.split('::')
+ classname = class_path[-1]
+ namespaces = class_path[:-1]
+
+ # The 'local' attribute restricts us to the params declared in
+ # the object itself, not including inherited params (which
+ # will also be inherited from the base class's param struct
+ # here).
+ params = cls._params.local.values()
+ ports = cls._ports.local
+
+ code('%module(package="m5.internal") param_$cls')
+ code()
+ code('%{')
+ code('#include "sim/sim_object.hh"')
+ 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('''\
+/**
+ * This is a workaround for bug in swig. Prior to gcc 4.6.1 the STL
+ * headers like vector, string, etc. used to automatically pull in
+ * the cstddef header but starting with gcc 4.6.1 they no longer do.
+ * This leads to swig generated a file that does not compile so we
+ * explicitly include cstddef. Additionally, including version 2.0.4,
+ * swig uses ptrdiff_t without the std:: namespace prefix which is
+ * required with gcc 4.6.1. We explicitly provide access to it.
+ */
+#include <cstddef>
+using std::ptrdiff_t;
+''')
+ code('%}')
+ code()
+
+ for param in params:
+ param.swig_predecls(code)
+ cls.export_method_swig_predecls(code)
+
+ code()
+ if cls._base:
+ code('%import "python/m5/internal/param_${{cls._base}}.i"')
+ code()
+
+ for ns in namespaces:
+ code('namespace $ns {')
+
+ if namespaces:
+ code('// avoid name conflicts')
+ sep_string = '_COLONS_'
+ flat_name = sep_string.join(class_path)
+ code('%rename($flat_name) $classname;')
+
+ code()
+ code('// stop swig from creating/wrapping default ctor/dtor')
+ code('%nodefault $classname;')
+ code('class $classname')
+ if cls._base:
+ bases = [ cls._base.cxx_class ] + cls.cxx_bases