Jason Lowe-Power has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/46819 )
Change subject: scons,python: revert Always generate default create()
methods.
......................................................................
scons,python: revert Always generate default create() methods.
This reverts commit 7bb690c1ee70b1c82b23eeb68dcda3dc6e5c97f7.
Change-Id: If1b44162b24409fb44daec0159852fa44937184d
---
M src/SConscript
M src/python/m5/SimObject.py
2 files changed, 72 insertions(+), 94 deletions(-)
diff --git a/src/SConscript b/src/SConscript
index cc51b9f..d8e8249 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -976,7 +976,7 @@
# Create all of the SimObject param headers and enum headers
#
-def createSimObjectParamDecl(target, source, env):
+def createSimObjectParamStruct(target, source, env):
assert len(target) == 1 and len(source) == 1
name = source[0].get_text_contents()
@@ -986,16 +986,6 @@
obj.cxx_param_decl(code)
code.write(target[0].abspath)
-def createSimObjectParamDef(target, source, env):
- assert len(target) == 1 and len(source) == 1
-
- name = source[0].get_text_contents()
- obj = sim_objects[name]
-
- code = code_formatter()
- obj.cxx_param_def(code)
- code.write(target[0].abspath)
-
def createSimObjectCxxConfig(is_header):
def body(target, source, env):
assert len(target) == 1 and len(source) == 1
@@ -1056,16 +1046,9 @@
hh_file = File('params/%s.hh' % name)
params_hh_files.append(hh_file)
env.Command(hh_file, Value(name),
- MakeAction(createSimObjectParamDecl,
Transform("SOPARMHH")))
+ MakeAction(createSimObjectParamStruct, Transform("SO
PARAM")))
env.Depends(hh_file, depends + extra_deps)
- if not getattr(simobj, 'abstract', False) and hasattr(simobj, 'type'):
- cc_file = File('params/%s.cc' % name)
- env.Command(cc_file, Value(name),
- MakeAction(createSimObjectParamDef,
Transform("SOPARMCC")))
- env.Depends(cc_file, depends + extra_deps)
- Source(cc_file)
-
# C++ parameter description files
if GetOption('with_cxx_config'):
for name,simobj in sorted(sim_objects.items()):
diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py
index bb17a38..88abc43 100644
--- a/src/python/m5/SimObject.py
+++ b/src/python/m5/SimObject.py
@@ -368,7 +368,7 @@
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 @@
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 @@
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 @@
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
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/46819
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: If1b44162b24409fb44daec0159852fa44937184d
Gerrit-Change-Number: 46819
Gerrit-PatchSet: 1
Gerrit-Owner: Jason Lowe-Power <power...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s