misc: Merge branch 'release-staging-v21-2' into develop

Change-Id: Icc03e585d87cf89ed844a0249c365cc296fa2d14
This commit is contained in:
Bobby R. Bruce
2021-12-16 23:07:11 -08:00
26 changed files with 135 additions and 245 deletions

View File

@@ -32,4 +32,4 @@ env.UseSystemcCheck(warn=True)
env.Append(CPPPATH=Dir('ext'))
SimObject('Tlm.py')
SimObject('Tlm.py', sim_objects=[])

View File

@@ -63,11 +63,3 @@ class SystemC_ScModule(SystemC_ScObject):
@cxxMethod(return_value_policy="reference", cxx_name="gem5_getPort")
def getPort(self, if_name, iex):
return None
try:
import _m5
except:
pass
else:
import _m5.systemc
_m5.systemc.python_ready()

View File

@@ -38,13 +38,6 @@ namespace sc_gem5
namespace
{
PythonReadyFunc *&
firstReadyFunc()
{
static PythonReadyFunc *first = nullptr;
return first;
}
PythonInitFunc *&
firstInitFunc()
{
@@ -52,33 +45,31 @@ firstInitFunc()
return first;
}
void
python_ready(pybind11::args args)
{
for (auto ptr = firstReadyFunc(); ptr; ptr = ptr->next)
ptr->run();
}
bool python_initialized = false;
void
systemc_pybind(pybind11::module_ &m_internal)
{
pybind11::module_ m = m_internal.def_submodule("systemc");
m.def("python_ready", &python_ready);
for (auto ptr = firstInitFunc(); ptr; ptr = ptr->next)
ptr->run(m);
ptr->callback(m);
python_initialized = true;
}
gem5::EmbeddedPyBind embed_("systemc", &systemc_pybind);
} // anonymous namespace
PythonReadyFunc::PythonReadyFunc() : next(firstReadyFunc())
{
firstReadyFunc() = this;
}
PythonInitFunc::PythonInitFunc() : next(firstInitFunc())
PythonInitFunc::PythonInitFunc(Callback run) :
callback(run), next(firstInitFunc())
{
firstInitFunc() = this;
// If the python was already initialized, run the callback immediately.
if (python_initialized) {
auto systemc_module = pybind11::module_::import("_m5.systemc");
callback(systemc_module);
}
}
} // namespace sc_gem5

View File

@@ -33,22 +33,14 @@
namespace sc_gem5
{
struct PythonReadyFunc
{
PythonReadyFunc *next;
PythonReadyFunc();
~PythonReadyFunc() {}
virtual void run() = 0;
};
struct PythonInitFunc
{
using Callback = void(*)(pybind11::module_ &systemc);
Callback callback;
PythonInitFunc *next;
PythonInitFunc();
~PythonInitFunc() {}
virtual void run(pybind11::module_ &systemc) = 0;
PythonInitFunc(Callback run);
};
} // namespace sc_gem5

View File

@@ -92,15 +92,10 @@ sc_main_result_str()
// Make our sc_main wrapper available in the internal _m5 python module under
// the systemc submodule.
struct InstallScMain : public ::sc_gem5::PythonInitFunc
{
void
run(pybind11::module_ &systemc) override
{
systemc.def("sc_main", &sc_main);
systemc.def("sc_main_result_code", &sc_main_result_code);
systemc.def("sc_main_result_str", &sc_main_result_str);
}
} installScMain;
::sc_gem5::PythonInitFunc installScMain([](pybind11::module_ &systemc) {
systemc.def("sc_main", &sc_main);
systemc.def("sc_main_result_code", &sc_main_result_code);
systemc.def("sc_main_result_str", &sc_main_result_str);
});
} // anonymous namespace

View File

@@ -33,48 +33,43 @@
namespace
{
struct InstallScTime : public ::sc_gem5::PythonInitFunc
{
void
run(pybind11::module_ &systemc) override
{
pybind11::class_<sc_core::sc_time> sc_time(systemc, "sc_time");
sc_time
// Constructors (omitting nonstandard and deprecated)
.def(pybind11::init<>())
.def(pybind11::init<double, sc_core::sc_time_unit>())
.def(pybind11::init<const sc_core::sc_time &>())
::sc_gem5::PythonInitFunc installScTime([](pybind11::module_ &systemc) {
pybind11::class_<sc_core::sc_time> sc_time(systemc, "sc_time");
sc_time
// Constructors (omitting nonstandard and deprecated)
.def(pybind11::init<>())
.def(pybind11::init<double, sc_core::sc_time_unit>())
.def(pybind11::init<const sc_core::sc_time &>())
// Converters.
.def("value", &sc_core::sc_time::value)
.def("to_double", &sc_core::sc_time::to_double)
.def("to_seconds", &sc_core::sc_time::to_seconds)
.def("to_string", &sc_core::sc_time::to_string)
.def("__str__", &sc_core::sc_time::to_string)
// Converters.
.def("value", &sc_core::sc_time::value)
.def("to_double", &sc_core::sc_time::to_double)
.def("to_seconds", &sc_core::sc_time::to_seconds)
.def("to_string", &sc_core::sc_time::to_string)
.def("__str__", &sc_core::sc_time::to_string)
// Operators.
.def(pybind11::self == pybind11::self)
.def(pybind11::self != pybind11::self)
.def(pybind11::self < pybind11::self)
.def(pybind11::self <= pybind11::self)
.def(pybind11::self > pybind11::self)
.def(pybind11::self >= pybind11::self)
.def(pybind11::self += pybind11::self)
.def(pybind11::self -= pybind11::self)
.def(pybind11::self *= double())
.def(pybind11::self /= double())
;
// Operators.
.def(pybind11::self == pybind11::self)
.def(pybind11::self != pybind11::self)
.def(pybind11::self < pybind11::self)
.def(pybind11::self <= pybind11::self)
.def(pybind11::self > pybind11::self)
.def(pybind11::self >= pybind11::self)
.def(pybind11::self += pybind11::self)
.def(pybind11::self -= pybind11::self)
.def(pybind11::self *= double())
.def(pybind11::self /= double())
;
pybind11::enum_<sc_core::sc_time_unit>(sc_time, "sc_time_unit")
.value("SC_FS", sc_core::SC_FS)
.value("SC_PS", sc_core::SC_PS)
.value("SC_NS", sc_core::SC_NS)
.value("SC_US", sc_core::SC_US)
.value("SC_MS", sc_core::SC_MS)
.value("SC_SEC", sc_core::SC_SEC)
.export_values()
;
}
} installScTime;
pybind11::enum_<sc_core::sc_time_unit>(sc_time, "sc_time_unit")
.value("SC_FS", sc_core::SC_FS)
.value("SC_PS", sc_core::SC_PS)
.value("SC_NS", sc_core::SC_NS)
.value("SC_US", sc_core::SC_US)
.value("SC_MS", sc_core::SC_MS)
.value("SC_SEC", sc_core::SC_SEC)
.export_values()
;
});
} // anonymous namespace

View File

@@ -63,7 +63,8 @@ if env['USE_SYSTEMC'] and GetOption('with_systemc_tests'):
test_dir = Dir('.')
class SystemCTestBin(Executable):
def __init__(self, test):
super().__init__(test.target, *test.sources)
all_sources = test.sources + [with_tag('main')]
super().__init__(test.target, *all_sources)
self.reldir = test.reldir
self.test_deps = test.deps
@@ -78,26 +79,16 @@ if env['USE_SYSTEMC'] and GetOption('with_systemc_tests'):
env.Append(CPPPATH=test_dir.Dir('include'))
shared_lib_path = env['SHARED_LIB'][0].abspath
sl_dir, sl_base = os.path.split(shared_lib_path)
env.Append(LIBPATH=[sl_dir], LIBS=[sl_base])
env.Append(LIBPATH=['${BUILDDIR}'], LIBS=['gem5_${ENV_LABEL}'])
env.AddLocalRPATH('${BUILDDIR}')
env['OBJSUFFIX'] = '.sc' + env['OBJSUFFIX'][1:]
env['SHOBJSUFFIX'] = '.sc' + env['OBJSUFFIX'][1:]
super().declare_all(env)
def declare(self, env):
env = env.Clone()
sources = list(self.sources)
for f in self.filters:
sources += Source.all.apply_filter(f)
objs = self.srcs_to_objs(env, sources)
objs = objs + env['MAIN_OBJS']
relpath = os.path.relpath(
env['SHARED_LIB'][0].dir.abspath,
self.path(env).dir.abspath)
env.Append(LINKFLAGS=Split('-z origin'))
env.Append(RPATH=[
env.Literal(os.path.join('\\$$ORIGIN', relpath))])
test_bin = super().declare(env, objs)
test_bin, _u = super().declare(env)
test_dir = self.dir.Dir(self.reldir)
for dep in self.test_deps:
env.Depends(test_bin, test_dir.File(dep))

View File

@@ -277,9 +277,9 @@ class LogChecker(DiffingChecker):
test_filt = merge_filts(
r'^/.*:\d+: ',
r'^Global frequency set at \d* ticks per second\n',
r'info: Entering event queue @ \d*\. Starting simulation\.\.\.\n',
r'warn: Ignoring request to set stack size\.\n',
r'^warn: No dot file generated. Please install pydot ' +
r'.*info: Entering event queue @ \d*\. Starting simulation\.\.\.\n',
r'.*warn: Ignoring request to set stack size\.\n',
r'^.*warn: No dot file generated. Please install pydot ' +
r'to generate the dot file and pdf.\n',
info_filt(804),
in_file_filt,

View File

@@ -31,21 +31,17 @@
namespace
{
struct InstallTlmGlobalQuantum : public ::sc_gem5::PythonInitFunc
{
void
run(pybind11::module_ &systemc) override
{
pybind11::class_<tlm::tlm_global_quantum>(
systemc, "tlm_global_quantum")
.def_static("instance", &tlm::tlm_global_quantum::instance,
pybind11::return_value_policy::reference)
.def("set", &tlm::tlm_global_quantum::set)
.def("get", &tlm::tlm_global_quantum::get)
.def("compute_local_quantum",
&tlm::tlm_global_quantum::compute_local_quantum)
;
}
} installTlmGlobalQuantum;
::sc_gem5::PythonInitFunc installTlmGlobalQuantum(
[](pybind11::module_ &systemc) {
pybind11::class_<tlm::tlm_global_quantum>(
systemc, "tlm_global_quantum")
.def_static("instance", &tlm::tlm_global_quantum::instance,
pybind11::return_value_policy::reference)
.def("set", &tlm::tlm_global_quantum::set)
.def("get", &tlm::tlm_global_quantum::get)
.def("compute_local_quantum",
&tlm::tlm_global_quantum::compute_local_quantum)
;
});
} // anonymous namespace