scons,python: revert Always generate default create() methods.
This reverts commit 7bb690c1ee.
Change-Id: If1b44162b24409fb44daec0159852fa44937184d
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/46819
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Bobby R. Bruce
parent
8c48ba9207
commit
e1aaf8218e
@@ -368,7 +368,7 @@ def createCxxConfigDirectoryEntryFile(code, name, simobj, is_header):
|
||||
|
||||
if not is_header:
|
||||
code('{')
|
||||
if getattr(simobj, 'abstract', False):
|
||||
if hasattr(simobj, 'abstract') and simobj.abstract:
|
||||
code(' return NULL;')
|
||||
else:
|
||||
code(' return this->create();')
|
||||
@@ -700,80 +700,6 @@ class MetaSimObject(type):
|
||||
def pybind_predecls(cls, code):
|
||||
code('#include "${{cls.cxx_header}}"')
|
||||
|
||||
def cxx_param_def(cls, code):
|
||||
code('''
|
||||
#include <type_traits>
|
||||
|
||||
#include "base/compiler.hh"
|
||||
|
||||
#include "${{cls.cxx_header}}"
|
||||
#include "params/${cls}.hh"
|
||||
|
||||
''')
|
||||
code()
|
||||
code('namespace')
|
||||
code('{')
|
||||
code()
|
||||
# If we can't define a default create() method for this params struct
|
||||
# because the SimObject doesn't have the right constructor, use
|
||||
# template magic to make it so we're actually defining a create method
|
||||
# for this class instead.
|
||||
code('class Dummy${cls}ParamsClass')
|
||||
code('{')
|
||||
code(' public:')
|
||||
code(' ${{cls.cxx_class}} *create() const;')
|
||||
code('};')
|
||||
code()
|
||||
code('template <class CxxClass, class Enable=void>')
|
||||
code('class Dummy${cls}Shunt;')
|
||||
code()
|
||||
# This version directs to the real Params struct and the default
|
||||
# behavior of create if there's an appropriate constructor.
|
||||
code('template <class CxxClass>')
|
||||
code('class Dummy${cls}Shunt<CxxClass, std::enable_if_t<')
|
||||
code(' std::is_constructible<CxxClass,')
|
||||
code(' const ${cls}Params &>::value>>')
|
||||
code('{')
|
||||
code(' public:')
|
||||
code(' using Params = ${cls}Params;')
|
||||
code(' static ${{cls.cxx_class}} *')
|
||||
code(' create(const Params &p)')
|
||||
code(' {')
|
||||
code(' return new CxxClass(p);')
|
||||
code(' }')
|
||||
code('};')
|
||||
code()
|
||||
# This version diverts to the DummyParamsClass and a dummy
|
||||
# implementation of create if the appropriate constructor does not
|
||||
# exist.
|
||||
code('template <class CxxClass>')
|
||||
code('class Dummy${cls}Shunt<CxxClass, std::enable_if_t<')
|
||||
code(' !std::is_constructible<CxxClass,')
|
||||
code(' const ${cls}Params &>::value>>')
|
||||
code('{')
|
||||
code(' public:')
|
||||
code(' using Params = Dummy${cls}ParamsClass;')
|
||||
code(' static ${{cls.cxx_class}} *')
|
||||
code(' create(const Params &p)')
|
||||
code(' {')
|
||||
code(' return nullptr;')
|
||||
code(' }')
|
||||
code('};')
|
||||
code()
|
||||
code('} // anonymous namespace')
|
||||
code()
|
||||
# An implementation of either the real Params struct's create
|
||||
# method, or the Dummy one. Either an implementation is
|
||||
# mandantory since this was shunted off to the dummy class, or
|
||||
# one is optional which will override this weak version.
|
||||
code('GEM5_VAR_USED ${{cls.cxx_class}} *')
|
||||
code('Dummy${cls}Shunt<${{cls.cxx_class}}>::Params::create() const')
|
||||
code('{')
|
||||
code(' return Dummy${cls}Shunt<${{cls.cxx_class}}>::')
|
||||
code(' create(*this);')
|
||||
code('}')
|
||||
|
||||
|
||||
def pybind_decl(cls, code):
|
||||
py_class_name = cls.pybind_class
|
||||
|
||||
@@ -787,6 +713,9 @@ class MetaSimObject(type):
|
||||
code('''#include "pybind11/pybind11.h"
|
||||
#include "pybind11/stl.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "base/compiler.hh"
|
||||
#include "params/$cls.hh"
|
||||
#include "python/pybind11/core.hh"
|
||||
#include "sim/init.hh"
|
||||
@@ -868,6 +797,72 @@ module_init(py::module_ &m_internal)
|
||||
code()
|
||||
code('static EmbeddedPyBind embed_obj("${0}", module_init, "${1}");',
|
||||
cls, cls._base.type if cls._base else "")
|
||||
if not hasattr(cls, 'abstract') or not cls.abstract:
|
||||
if 'type' in cls.__dict__:
|
||||
code()
|
||||
code('namespace')
|
||||
code('{')
|
||||
code()
|
||||
# If we can't define a default create() method for this params
|
||||
# struct because the SimObject doesn't have the right
|
||||
# constructor, use template magic to make it so we're actually
|
||||
# defining a create method for this class instead.
|
||||
code('class Dummy${cls}ParamsClass')
|
||||
code('{')
|
||||
code(' public:')
|
||||
code(' ${{cls.cxx_class}} *create() const;')
|
||||
code('};')
|
||||
code()
|
||||
code('template <class CxxClass, class Enable=void>')
|
||||
code('class Dummy${cls}Shunt;')
|
||||
code()
|
||||
# This version directs to the real Params struct and the
|
||||
# default behavior of create if there's an appropriate
|
||||
# constructor.
|
||||
code('template <class CxxClass>')
|
||||
code('class Dummy${cls}Shunt<CxxClass, std::enable_if_t<')
|
||||
code(' std::is_constructible<CxxClass,')
|
||||
code(' const ${cls}Params &>::value>>')
|
||||
code('{')
|
||||
code(' public:')
|
||||
code(' using Params = ${cls}Params;')
|
||||
code(' static ${{cls.cxx_class}} *')
|
||||
code(' create(const Params &p)')
|
||||
code(' {')
|
||||
code(' return new CxxClass(p);')
|
||||
code(' }')
|
||||
code('};')
|
||||
code()
|
||||
# This version diverts to the DummyParamsClass and a dummy
|
||||
# implementation of create if the appropriate constructor does
|
||||
# not exist.
|
||||
code('template <class CxxClass>')
|
||||
code('class Dummy${cls}Shunt<CxxClass, std::enable_if_t<')
|
||||
code(' !std::is_constructible<CxxClass,')
|
||||
code(' const ${cls}Params &>::value>>')
|
||||
code('{')
|
||||
code(' public:')
|
||||
code(' using Params = Dummy${cls}ParamsClass;')
|
||||
code(' static ${{cls.cxx_class}} *')
|
||||
code(' create(const Params &p)')
|
||||
code(' {')
|
||||
code(' return nullptr;')
|
||||
code(' }')
|
||||
code('};')
|
||||
code()
|
||||
code('} // anonymous namespace')
|
||||
code()
|
||||
# An implementation of either the real Params struct's create
|
||||
# method, or the Dummy one. Either an implementation is
|
||||
# mandantory since this was shunted off to the dummy class, or
|
||||
# one is optional which will override this weak version.
|
||||
code('GEM5_VAR_USED ${{cls.cxx_class}} *')
|
||||
code('Dummy${cls}Shunt<${{cls.cxx_class}}>::Params::create() '
|
||||
'const')
|
||||
code('{')
|
||||
code(' return Dummy${cls}Shunt<${{cls.cxx_class}}>::')
|
||||
code(' create(*this);')
|
||||
code('}')
|
||||
|
||||
_warned_about_nested_templates = False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user