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 <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu>
diff --git a/src/SConscript b/src/SConscript
index 31fce0c..5fe0ab2 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -917,7 +917,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()
@@ -927,16 +927,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
@@ -997,16 +987,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 bdce718..71b39d0 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('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 @@
         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('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