From 356b4dc476adfe2b33ed0a88a98705b7855aa596 Mon Sep 17 00:00:00 2001 From: Jason Lowe-Power Date: Fri, 11 Jun 2021 09:55:03 -0700 Subject: [PATCH] scons,python: revert Always generate default create() methods. This reverts commit 7bb690c1ee70b1c82b23eeb68dcda3dc6e5c97f7. Change-Id: If1b44162b24409fb44daec0159852fa44937184d Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/46879 Maintainer: Bobby R. Bruce Tested-by: kokoro Reviewed-by: Bobby R. Bruce --- src/SConscript | 21 +----- src/python/m5/SimObject.py | 145 ++++++++++++++++++------------------- 2 files changed, 72 insertions(+), 94 deletions(-) diff --git a/src/SConscript b/src/SConscript index 31fce0c6bf..5fe0ab2c25 100644 --- a/src/SConscript +++ b/src/SConscript @@ -917,7 +917,7 @@ PySource('m5', 'python/m5/info.py') # 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() @@ -927,16 +927,6 @@ def createSimObjectParamDecl(target, source, env): 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 @@ -997,16 +987,9 @@ for name,simobj in sorted(sim_objects.items()): 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 bdce718172..71b39d0a1f 100644 --- a/src/python/m5/SimObject.py +++ b/src/python/m5/SimObject.py @@ -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 - -#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 ') - 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 ') - code('class Dummy${cls}Shunt::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 ') - code('class Dummy${cls}Shunt::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('M5_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 + +#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 ') + 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 ') + code('class Dummy${cls}Shunt::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 ') + code('class Dummy${cls}Shunt::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('M5_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