From 5f6021a3545ceee676324f05ffdf10318919f53e Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Tue, 17 Aug 2021 21:17:27 -0700 Subject: [PATCH] python,scons: Add a gem5py_m5 program which supports the m5 module. Like gem5py which uses the same main source file, this program will run arbitrary python scripts. Unlike the other program, it will include support for the m5 module. That will make it capable of generating SimObject param, enum, etc c++ files. Change-Id: I15fd7545f6b1ea6559cbe27cef30c778867ebe70 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/49421 Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power Tested-by: kokoro --- src/SConscript | 16 ++++++++++++++-- src/python/SConscript | 6 +++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/SConscript b/src/SConscript index b19c3c5c84..d566010445 100644 --- a/src/SConscript +++ b/src/SConscript @@ -81,8 +81,11 @@ build_tools = Dir('#build_tools') # as gem5. This is in an unorthodox location to avoid building it for every # variant. gem5py_env = gem5py_env.Clone() -gem5py = gem5py_env.Program('gem5py', 'python/gem5py.cc')[0] +gem5py = gem5py_env.File('gem5py') +gem5py_m5 = gem5py_env.File('gem5py_m5') gem5py_env['GEM5PY'] = gem5py +gem5py_env['GEM5PY_M5'] = gem5py_m5 +gem5py_env['OBJSUFFIX'] = '.pyo' # Inject build_tools into PYTHONPATH for when we run gem5py. pythonpath = gem5py_env['ENV'].get('PYTHONPATH', '').split(':') pythonpath.append(build_tools.abspath) @@ -134,7 +137,7 @@ class PySource(SourceFile): '"${PYSOURCE_ABSPATH}"', Transform("EMBED PY", max_sources=1)), **overrides) - Source(cpp, tags=self.tags, add_tags='python') + Source(cpp, tags=self.tags, add_tags=['python', 'm5_module']) class SimObject(PySource): '''Add a SimObject python file as a python source object and add @@ -640,6 +643,15 @@ gem5py_env.Command('python/m5/info.py', INFOPY_PY=build_tools.File('infopy.py')) PySource('m5', 'python/m5/info.py') +gem5py_m5_env = gem5py_env.Clone() +gem5py_env.Append(CPPPATH=env['CPPPATH']) +gem5py_env.Append(LIBS='z') +gem5py_env.Program(gem5py, 'python/gem5py.cc')[0] +m5_module_source = \ + Source.all.with_all_tags(env, 'm5_module', 'gem5 lib') +m5_module_static = list(map(lambda s: s.static(gem5py_env), m5_module_source)) +gem5py_env.Program(gem5py_m5, [ 'python/gem5py.cc' ] + m5_module_static) + ######################################################################## # # Create all of the SimObject param headers and enum headers diff --git a/src/python/SConscript b/src/python/SConscript index c9cd2d497c..19391003eb 100644 --- a/src/python/SConscript +++ b/src/python/SConscript @@ -253,10 +253,10 @@ PySource('m5.ext.pystats', 'm5/ext/pystats/timeconversion.py') PySource('m5.ext.pystats', 'm5/ext/pystats/jsonloader.py') PySource('m5.stats', 'm5/stats/gem5stats.py') -Source('embedded.cc', add_tags='python') -Source('importer.cc', add_tags='python') +Source('embedded.cc', add_tags=['python', 'm5_module']) +Source('importer.cc', add_tags=['python', 'm5_module']) cc, hh = env.Blob('m5ImporterCode', 'importer.py') -Source(cc, add_tags='python') +Source(cc, add_tags=['python', 'm5_module']) Source('pybind11/core.cc', add_tags='python') Source('pybind11/debug.cc', add_tags='python')