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

Change subject: scons,util: Generate cxx config wrappers using a helper script.
......................................................................

scons,util: Generate cxx config wrappers using a helper script.

Change-Id: I003426881dc0fd8a338048abbdfa05a606221c39
---
M src/SConscript
A util/bld/cxx_config_cc.py
A util/bld/cxx_config_hh.py
3 files changed, 135 insertions(+), 44 deletions(-)



diff --git a/src/SConscript b/src/SConscript
index 45e2853..48aa48b 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -651,64 +651,56 @@
 # Create all of the SimObject param headers and enum headers
 #

-# Generate all of the SimObject param C++ struct header files
+# Generate all of the SimObject param C++ files.

 for module, simobjs in sorted(SimObject.sim_objects.items()):
     for simobj in simobjs:
-        gem5py_env.Command([ "${PARAMS_HH}" ],
-                [ Value(module), Value(simobj),
-                    "${GEM5PY_M5}", "${PARAMSTRUCT_PY}" ],
- MakeAction('"${GEM5PY_M5}" "${PARAMSTRUCT_PY}" "${MODULE}" ' \
-                        '"${PARAMS_HH}"',
-                    Transform("SO Param", 2)),
+
+        # Some helper functions
+ srcs = [ Value(module), Value(simobj), "${GEM5PY_M5}", "${PYSCRIPT}" ]
+        def cmdline(*args):
+            all_args = [ 'GEM5PY_M5', 'PYSCRIPT', 'MODULE' ] + list(args)
+            return ' '.join(list('"${%s}"' % arg for arg in all_args))
+
+        # Params header.
+        gem5py_env.Command([ "${PARAMS_HH}" ], srcs,
+                MakeAction(cmdline('PARAMS_HH'), Transform("SO Param", 2)),
                 MODULE=module,
                 SIMOBJ=simobj,
- PARAMSTRUCT_PY=util_bld.File('sim_object_param_struct_hh.py'),
+                PYSCRIPT=util_bld.File('sim_object_param_struct_hh.py'),
                 PARAMS_HH=File(f'params/{simobj}.hh'))
+
+        # Params cc.
         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}"',
+        gem5py_env.Command([ "${PARAMS_CC}" ], srcs,
+                MakeAction(cmdline('PARAMS_CC', 'USE_PYTHON'),
                     Transform("SO Param", 2)),
- PARAMSTRUCT_PY=util_bld.File('sim_object_param_struct_cc.py'),
+                PYSCRIPT=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')

+        # CXX config header.
+        gem5py_env.Command([ "${CXXCONFIG_HH}" ], srcs,
+ MakeAction(cmdline('CXXCONFIG_HH'), Transform("CXXCPRHH", 2)),
+                PYSCRIPT=util_bld.File('cxx_config_hh.py'),
+                MODULE=module,
+                CXXCONFIG_HH=File(f'cxx_config/{simobj}.hh'))
+
+        # CXX config cc.
+        cc_file=File(f'cxx_config/{simobj}.cc')
+        gem5py_env.Command([ "${CXXCONFIG_CC}" ], srcs,
+ MakeAction(cmdline('CXXCONFIG_CC'), Transform("CXXCPRCC", 2)),
+                PYSCRIPT=util_bld.File('cxx_config_cc.py'),
+                MODULE=module,
+                CXXCONFIG_CC=cc_file)
+        if GetOption('with_cxx_config'):
+            Source(cc_file)
+
 # C++ parameter description files
 if GetOption('with_cxx_config'):
-    def createSimObjectCxxConfig(is_header):
-        def body(target, source, env):
-            assert len(target) == 1 and len(source) == 1
-
-            name = source[0].get_contents().decode('utf-8')
-            obj = sim_objects[name]
-
-            code = code_formatter()
-            obj.cxx_config_param_file(code, is_header)
-            code.write(target[0].abspath)
-        return body
-
-    for name,simobj in sorted(sim_objects.items()):
-        py_source = PySource.modules[simobj.__module__]
-        extra_deps = [ py_source.tnode ]
-
-        cxx_config_hh_file = File('cxx_config/%s.hh' % name)
-        cxx_config_cc_file = File('cxx_config/%s.cc' % name)
-        env.Command(cxx_config_hh_file, Value(name),
-                    MakeAction(createSimObjectCxxConfig(True),
-                    Transform("CXXCPRHH")))
-        env.Command(cxx_config_cc_file, Value(name),
-                    MakeAction(createSimObjectCxxConfig(False),
-                    Transform("CXXCPRCC")))
-        env.Depends(cxx_config_hh_file, depends + extra_deps)
-        env.Depends(cxx_config_cc_file, depends + extra_deps)
-        Source(cxx_config_cc_file, add_tags='python')
-
     cxx_config_init_cc_file = File('cxx_config/init.cc')

     def createCxxConfigInitCC(target, source, env):
@@ -758,12 +750,13 @@
         gem5py_env.Command([ "${ENUM_CC}" ],
[ Value(module), Value(enum), "${GEM5PY_M5}", "${ENUMCC_PY}" ],
                 MakeAction('"${GEM5PY_M5}" "${ENUMCC_PY}" "${MODULE}" ' \
-                        '"${ENUM_CC}"',
+                        '"${ENUM_CC}" "${USE_PYTHON}"',
                     Transform("ENUM STR", 2)),
                 MODULE=module,
                 ENUM=enum,
                 ENUM_CC=cc_file,
-                ENUMCC_PY=util_bld.File('enum_cc.py'))
+                ENUMCC_PY=util_bld.File('enum_cc.py'),
+                USE_PYTHON=env['USE_PYTHON'])
         Source(cc_file, add_tags='python')

 #
diff --git a/util/bld/cxx_config_cc.py b/util/bld/cxx_config_cc.py
new file mode 100644
index 0000000..fcb9314
--- /dev/null
+++ b/util/bld/cxx_config_cc.py
@@ -0,0 +1,49 @@
+# 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) != 3:
+    print(f"Usage: {sys.argv[0]} MODULE CXX_CONFIG_CC", file=sys.stderr)
+    sys.exit(1)
+
+_, modpath, cc = sys.argv
+
+basename = os.path.basename(cc)
+sim_object_name = os.path.splitext(basename)[0]
+
+importer.install()
+module = importlib.import_module(modpath)
+sim_object = getattr(module, sim_object_name)
+
+code = code_formatter()
+sim_object.cxx_config_param_file(code, False)
+code.write(cc)
diff --git a/util/bld/cxx_config_hh.py b/util/bld/cxx_config_hh.py
new file mode 100644
index 0000000..6e6e260
--- /dev/null
+++ b/util/bld/cxx_config_hh.py
@@ -0,0 +1,49 @@
+# 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) != 3:
+    print(f"Usage: {sys.argv[0]} MODULE CXX_CONFIG_HH", file=sys.stderr)
+    sys.exit(1)
+
+_, modpath, hh = sys.argv
+
+basename = os.path.basename(hh)
+sim_object_name = os.path.splitext(basename)[0]
+
+importer.install()
+module = importlib.import_module(modpath)
+sim_object = getattr(module, sim_object_name)
+
+code = code_formatter()
+sim_object.cxx_config_param_file(code, True)
+code.write(hh)

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/49427
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: I003426881dc0fd8a338048abbdfa05a606221c39
Gerrit-Change-Number: 49427
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