Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/49425 )

Change subject: scons,util: Also build param struct .cc files using a helper script.
......................................................................

scons,util: Also build param struct .cc files using a helper script.

There was a comment in the SConscript talking about building a single
.cc file for all the param structs, but that's not what the code was
actually doing. This change drops that misleading comment.

Change-Id: I3a5e4424e1021d6dfbdeafcef7709dae988747a4
---
M src/SConscript
A util/bld/sim_object_param_struct_cc.py
R util/bld/sim_object_param_struct_hh.py
3 files changed, 70 insertions(+), 27 deletions(-)



diff --git a/src/SConscript b/src/SConscript
index b151308..8e33fdd 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -655,14 +655,29 @@

 for module, simobjs in sorted(SimObject.sim_objects.items()):
     for simobj in simobjs:
-        gem5py_env.Command(f'params/{simobj}.hh',
+        gem5py_env.Command([ "${PARAMS_HH}" ],
                 [ Value(module), Value(simobj),
                     "${GEM5PY_M5}", "${PARAMSTRUCT_PY}" ],
MakeAction('"${GEM5PY_M5}" "${PARAMSTRUCT_PY}" "${MODULE}" ' \
-                        '"${TARGET}"',
+                        '"${PARAMS_HH}"',
                     Transform("SO Param", 2)),
-                PARAMSTRUCT_PY=util_bld.File('sim_object_param_struct.py'),
-                MODULE=module)
+                MODULE=module,
+                SIMOBJ=simobj,
+ PARAMSTRUCT_PY=util_bld.File('sim_object_param_struct_hh.py'),
+                PARAMS_HH=File(f'params/{simobj}.hh'))
+        cc_file = File(f'python/_m5/param_{simobj}.cc')
+        gem5py_env.Command([ "${PARAMS_CC}" ],
+                [ Value(module), Value(simobj),
+                    "${GEM5PY_M5}", "${PARAMSTRUCT_PY}" ],
+ MakeAction('"${GEM5PY_M5}" "${PARAMSTRUCT_PY}" "${MODULE}" ' \
+                        '"${PARAMS_CC}" "${USE_PYTHON}"',
+                    Transform("SO Param", 2)),
+ PARAMSTRUCT_PY=util_bld.File('sim_object_param_struct_cc.py'),
+                MODULE=module,
+                SIMOBJ=simobj,
+                PARAMS_CC=cc_file,
+                USE_PYTHON=env['USE_PYTHON'])
+        Source(cc_file, add_tags='python')

 # C++ parameter description files
 if GetOption('with_cxx_config'):
@@ -766,29 +781,6 @@
                 MakeAction(createEnumDecls, Transform("ENUMDECL")))
     env.Depends(hh_file, depends + extra_deps)

-# Generate SimObject Python bindings and create method wrapper files
-def createSimObjectWrappers(target, source, env):
-    name = source[0].get_text_contents()
-    obj = sim_objects[name]
-
-    code = code_formatter()
-    # 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)
-
-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, add_tags='python')
-
 #
 # Handle debug flags
 #
diff --git a/util/bld/sim_object_param_struct_cc.py b/util/bld/sim_object_param_struct_cc.py
new file mode 100644
index 0000000..70951e7
--- /dev/null
+++ b/util/bld/sim_object_param_struct_cc.py
@@ -0,0 +1,51 @@
+# Copyright 2021 Google, Inc.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import importlib
+import os.path
+import sys
+
+import importer
+
+from code_formatter import code_formatter
+
+if len(sys.argv) != 4:
+ print(f"Usage: {sys.argv[0]} MODULE PARAM_CC USE_PYTHON", file=sys.stderr)
+    sys.exit(1)
+
+_, modpath, cc, use_python = sys.argv
+use_python = eval(use_python)
+
+basename = os.path.basename(cc)
+no_ext = os.path.splitext(basename)[0]
+sim_object_name = '_'.join(no_ext.split('_')[1:])
+
+importer.install()
+module = importlib.import_module(modpath)
+sim_object = getattr(module, sim_object_name)
+
+code = code_formatter()
+sim_object.params_create_decl(code, use_python)
+code.write(cc)
diff --git a/util/bld/sim_object_param_struct.py b/util/bld/sim_object_param_struct_hh.py
similarity index 100%
rename from util/bld/sim_object_param_struct.py
rename to util/bld/sim_object_param_struct_hh.py

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/49425
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: I3a5e4424e1021d6dfbdeafcef7709dae988747a4
Gerrit-Change-Number: 49425
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabe.bl...@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

Reply via email to