[gem5-dev] Change in gem5/gem5[minor-release-staging-v21-0-1]: python,scons: Only generate pybind if using python

2021-06-22 Thread Bobby R. Bruce (Gerrit) via gem5-dev
Bobby R. Bruce has submitted this change. (  
https://gem5-review.googlesource.com/c/public/gem5/+/46880 )


Change subject: python,scons: Only generate pybind if using python
..

python,scons: Only generate pybind if using python

This reimplements the previously reverted change: Always generate default
create() methods.

The pybind code should only be generated when python is enabled. This
change passes whether python is enabled into the SimObject code creation
method. Then, the params code is optionally included.

Note: Due to some problems in GCC's linker (or something else...) we
need to have a single file with all of the generated code for the
SimObject.

Change-Id: I0f93b3d787d47f26db2de6c4447730f7df87a0dc
Issue-on: https://gem5.atlassian.net/browse/GEM5-1003
Signed-off-by: Jason Lowe-Power 
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/46880
Maintainer: Bobby R. Bruce 
Tested-by: kokoro 
Reviewed-by: Bobby R. Bruce 
---
M src/SConscript
M src/python/m5/SimObject.py
2 files changed, 97 insertions(+), 76 deletions(-)

Approvals:
  Bobby R. Bruce: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/SConscript b/src/SConscript
index 5fe0ab2..1ff6a07 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -962,12 +962,16 @@
 obj.cxx_decl(code)
 code.write(target[0].abspath)

-def createSimObjectPyBindWrapper(target, source, env):
+def createSimObjectWrappers(target, source, env):
 name = source[0].get_text_contents()
 obj = sim_objects[name]

 code = code_formatter()
-obj.pybind_decl(code)
+# We want to generate a single .cc file which contains most of the
+# SimObject autogenerated code to reduce the number of files to  
compile and

+# link. We need to pass in whether python is enabled so that the pybind
+# wrappers are only generated when python is enabled
+obj.params_create_decl(code, env['USE_PYTHON'])
 code.write(target[0].abspath)

 # Generate all of the SimObject param C++ struct header files
@@ -1061,17 +1065,16 @@
 MakeAction(createEnumDecls, Transform("ENUMDECL")))
 env.Depends(hh_file, depends + extra_deps)

-# Generate SimObject Python bindings wrapper files
-if env['USE_PYTHON']:
-for name,simobj in sorted(sim_objects.items()):
-py_source = PySource.modules[simobj.__module__]
-extra_deps = [ py_source.tnode ]
-cc_file = File('python/_m5/param_%s.cc' % name)
-env.Command(cc_file, Value(name),
-MakeAction(createSimObjectPyBindWrapper,
-   Transform("SO PyBind")))
-env.Depends(cc_file, depends + extra_deps)
-Source(cc_file)
+# Generate SimObject Python bindings and create method wrapper files
+for name,simobj in sorted(sim_objects.items()):
+py_source = PySource.modules[simobj.__module__]
+extra_deps = [ py_source.tnode ]
+cc_file = File('python/_m5/param_%s.cc' % name)
+env.Command(cc_file, Value(name),
+MakeAction(createSimObjectWrappers,
+Transform("SO PyB/C")))
+env.Depends(cc_file, depends + extra_deps)
+Source(cc_file)

 #
 # Handle debug flags
diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py
index 71b39d0..e2f5d58 100644
--- a/src/python/m5/SimObject.py
+++ b/src/python/m5/SimObject.py
@@ -700,17 +700,21 @@
 def pybind_predecls(cls, code):
 code('#include "${{cls.cxx_header}}"')

-def pybind_decl(cls, code):
+def params_create_decl(cls, code, python_enabled):
 py_class_name = cls.pybind_class

 # 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). Sort the params based on their key
-params = list(map(lambda k_v: k_v[1],  
sorted(cls._params.local.items(

+params = list(map(lambda k_v: k_v[1],
+  sorted(cls._params.local.items(
 ports = cls._ports.local

-code('''#include "pybind11/pybind11.h"
+# only include pybind if python is enabled in the build
+if python_enabled:
+
+code('''#include "pybind11/pybind11.h"
 #include "pybind11/stl.h"

 #include 
@@ -724,79 +728,93 @@
 #include "${{cls.cxx_header}}"

 ''')
+else:
+code('''
+#include 

-for param in params:
-param.pybind_predecls(code)
+#include "base/compiler.hh"
+#include "params/$cls.hh"

-code('''namespace py = pybind11;
+#include "${{cls.cxx_header}}"
+
+''')
+# only include the python params code if python is enabled.
+if python_enabled:
+for param in params:
+param.pybind_predecls(code)
+
+code('''namespace py = pybind11;

 static void
 

[gem5-dev] Change in gem5/gem5[minor-release-staging-v21-0-1]: python,scons: Only generate pybind if using python

2021-06-14 Thread Bobby R. Bruce (Gerrit) via gem5-dev
Bobby R. Bruce has uploaded this change for review. (  
https://gem5-review.googlesource.com/c/public/gem5/+/46880 )



Change subject: python,scons: Only generate pybind if using python
..

python,scons: Only generate pybind if using python

This reimplements the previously reverted change: Always generate default
create() methods.

The pybind code should only be generated when python is enabled. This
change passes whether python is enabled into the SimObject code creation
method. Then, the params code is optionally included.

Note: Due to some problems in GCC's linker (or something else...) we
need to have a single file with all of the generated code for the
SimObject.

Change-Id: I0f93b3d787d47f26db2de6c4447730f7df87a0dc
Issue-on: https://gem5.atlassian.net/browse/GEM5-1003
Signed-off-by: Jason Lowe-Power 
---
M src/SConscript
M src/python/m5/SimObject.py
2 files changed, 97 insertions(+), 76 deletions(-)



diff --git a/src/SConscript b/src/SConscript
index 5fe0ab2..1ff6a07 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -962,12 +962,16 @@
 obj.cxx_decl(code)
 code.write(target[0].abspath)

-def createSimObjectPyBindWrapper(target, source, env):
+def createSimObjectWrappers(target, source, env):
 name = source[0].get_text_contents()
 obj = sim_objects[name]

 code = code_formatter()
-obj.pybind_decl(code)
+# We want to generate a single .cc file which contains most of the
+# SimObject autogenerated code to reduce the number of files to  
compile and

+# link. We need to pass in whether python is enabled so that the pybind
+# wrappers are only generated when python is enabled
+obj.params_create_decl(code, env['USE_PYTHON'])
 code.write(target[0].abspath)

 # Generate all of the SimObject param C++ struct header files
@@ -1061,17 +1065,16 @@
 MakeAction(createEnumDecls, Transform("ENUMDECL")))
 env.Depends(hh_file, depends + extra_deps)

-# Generate SimObject Python bindings wrapper files
-if env['USE_PYTHON']:
-for name,simobj in sorted(sim_objects.items()):
-py_source = PySource.modules[simobj.__module__]
-extra_deps = [ py_source.tnode ]
-cc_file = File('python/_m5/param_%s.cc' % name)
-env.Command(cc_file, Value(name),
-MakeAction(createSimObjectPyBindWrapper,
-   Transform("SO PyBind")))
-env.Depends(cc_file, depends + extra_deps)
-Source(cc_file)
+# Generate SimObject Python bindings and create method wrapper files
+for name,simobj in sorted(sim_objects.items()):
+py_source = PySource.modules[simobj.__module__]
+extra_deps = [ py_source.tnode ]
+cc_file = File('python/_m5/param_%s.cc' % name)
+env.Command(cc_file, Value(name),
+MakeAction(createSimObjectWrappers,
+Transform("SO PyB/C")))
+env.Depends(cc_file, depends + extra_deps)
+Source(cc_file)

 #
 # Handle debug flags
diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py
index 978535f..1d46a6d 100644
--- a/src/python/m5/SimObject.py
+++ b/src/python/m5/SimObject.py
@@ -700,17 +700,21 @@
 def pybind_predecls(cls, code):
 code('#include "${{cls.cxx_header}}"')

-def pybind_decl(cls, code):
+def params_create_decl(cls, code, python_enabled):
 py_class_name = cls.pybind_class

 # 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). Sort the params based on their key
-params = list(map(lambda k_v: k_v[1],  
sorted(cls._params.local.items(

+params = list(map(lambda k_v: k_v[1],
+  sorted(cls._params.local.items(
 ports = cls._ports.local

-code('''#include "pybind11/pybind11.h"
+# only include pybind if python is enabled in the build
+if python_enabled:
+
+code('''#include "pybind11/pybind11.h"
 #include "pybind11/stl.h"

 #include 
@@ -724,79 +728,93 @@
 #include "${{cls.cxx_header}}"

 ''')
+else:
+code('''
+#include 

-for param in params:
-param.pybind_predecls(code)
+#include "base/compiler.hh"
+#include "params/$cls.hh"

-code('''namespace py = pybind11;
+#include "${{cls.cxx_header}}"
+
+''')
+# only include the python params code if python is enabled.
+if python_enabled:
+for param in params:
+param.pybind_predecls(code)
+
+code('''namespace py = pybind11;

 static void
 module_init(py::module_ _internal)
 {
 py::module_ m = m_internal.def_submodule("param_${cls}");
 ''')
-code.indent()
-if cls._base:
-code('py::class_<${cls}Params, ${{cls._base.type}}Params, ' \
-