scons: 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 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/49425 Reviewed-by: Jason Lowe-Power <power.jg@gmail.com> Maintainer: Jason Lowe-Power <power.jg@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
62
build_tools/sim_object_param_struct_cc.py
Normal file
62
build_tools/sim_object_param_struct_cc.py
Normal file
@@ -0,0 +1,62 @@
|
||||
# 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('param_cc', help='parameter cc file to generate')
|
||||
parser.add_argument('use_python',
|
||||
help='whether python is enabled in gem5 (True or False)')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
use_python = args.use_python.lower()
|
||||
if use_python == 'true':
|
||||
use_python = True
|
||||
elif use_python == 'false':
|
||||
use_python = False
|
||||
else:
|
||||
print(f'Unrecognized "use_python" value {use_python}', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
basename = os.path.basename(args.param_cc)
|
||||
no_ext = os.path.splitext(basename)[0]
|
||||
sim_object_name = '_'.join(no_ext.split('_')[1:])
|
||||
|
||||
importer.install()
|
||||
module = importlib.import_module(args.modpath)
|
||||
sim_object = getattr(module, sim_object_name)
|
||||
|
||||
code = code_formatter()
|
||||
sim_object.params_create_decl(code, use_python)
|
||||
code.write(args.param_cc)
|
||||
@@ -147,6 +147,7 @@ class SimObject(PySource):
|
||||
|
||||
sim_objects = dict()
|
||||
enums = dict()
|
||||
tags = dict()
|
||||
|
||||
def __init__(self, source, *, sim_objects=[], enums=[],
|
||||
tags=None, add_tags=None):
|
||||
@@ -158,6 +159,7 @@ class SimObject(PySource):
|
||||
|
||||
SimObject.sim_objects[self.modpath] = sim_objects
|
||||
SimObject.enums[self.modpath] = enums
|
||||
SimObject.tags[self.modpath] = self.tags
|
||||
|
||||
# This regular expression is simplistic and assumes that the import takes up
|
||||
# the entire line, doesn't have the keyword "public", uses double quotes, has
|
||||
@@ -665,16 +667,33 @@ gem5py_env.Program(gem5py_m5, [ 'python/gem5py.cc' ] + m5_module_static)
|
||||
# Generate all of the SimObject param C++ struct header files
|
||||
|
||||
for module, simobjs in sorted(SimObject.sim_objects.items()):
|
||||
tags = SimObject.tags[module]
|
||||
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)),
|
||||
MODULE=module,
|
||||
SIMOBJ=simobj,
|
||||
PARAMSTRUCT_PY=build_tools.File(
|
||||
'sim_object_param_struct_hh.py'),
|
||||
MODULE=module)
|
||||
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=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')
|
||||
|
||||
# C++ parameter description files
|
||||
if GetOption('with_cxx_config'):
|
||||
@@ -778,28 +797,6 @@ for name,enum in sorted(all_enums.items()):
|
||||
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')
|
||||
|
||||
# version tags
|
||||
tags = \
|
||||
|
||||
Reference in New Issue
Block a user