diff --git a/build_tools/cxx_config_cc.py b/build_tools/cxx_config_cc.py new file mode 100644 index 0000000000..7047857760 --- /dev/null +++ b/build_tools/cxx_config_cc.py @@ -0,0 +1,50 @@ +# 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 argparse +import importlib +import os.path +import sys + +import importer + +from code_formatter import code_formatter + +parser = argparse.ArgumentParser() +parser.add_argument('modpath', help='module the simobject belongs to') +parser.add_argument('cxx_config_cc', help='cxx config cc file to generate') + +args = parser.parse_args() + +basename = os.path.basename(args.cxx_config_cc) +sim_object_name = os.path.splitext(basename)[0] + +importer.install() +module = importlib.import_module(args.modpath) +sim_object = getattr(module, sim_object_name) + +code = code_formatter() +sim_object.cxx_config_param_file(code, False) +code.write(args.cxx_config_cc) diff --git a/build_tools/cxx_config_hh.py b/build_tools/cxx_config_hh.py new file mode 100644 index 0000000000..3cae84b69e --- /dev/null +++ b/build_tools/cxx_config_hh.py @@ -0,0 +1,50 @@ +# 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 argparse +import importlib +import os.path +import sys + +import importer + +from code_formatter import code_formatter + +parser = argparse.ArgumentParser() +parser.add_argument('modpath', help='module the simobject belongs to') +parser.add_argument('cxx_config_hh', help='cxx config header file to generate') + +args = parser.parse_args() + +basename = os.path.basename(args.cxx_config_hh) +sim_object_name = os.path.splitext(basename)[0] + +importer.install() +module = importlib.import_module(args.modpath) +sim_object = getattr(module, sim_object_name) + +code = code_formatter() +sim_object.cxx_config_param_file(code, True) +code.write(args.cxx_config_hh) diff --git a/src/SConscript b/src/SConscript index bd4d630601..49f8c985c2 100644 --- a/src/SConscript +++ b/src/SConscript @@ -672,67 +672,57 @@ gem5py_env.Program(gem5py_m5, [ 'python/gem5py.cc' ] + m5_module_static) # 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()): tags = SimObject.tags[module] 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=build_tools.File( - 'sim_object_param_struct_hh.py'), + PYSCRIPT=build_tools.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=build_tools.File( - 'sim_object_param_struct_cc.py'), + PYSCRIPT=build_tools.File('sim_object_param_struct_cc.py'), MODULE=module, SIMOBJ=simobj, PARAMS_CC=cc_file, USE_PYTHON=env['USE_PYTHON']) Source(cc_file, tags=tags, add_tags='python') + # CXX config header. + gem5py_env.Command([ "${CXXCONFIG_HH}" ], srcs, + MakeAction(cmdline('CXXCONFIG_HH'), Transform("CXXCPRHH", 2)), + PYSCRIPT=build_tools.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=build_tools.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):