systemc: Centralize module callbacks and report new warnings.
By centralizing module callbacks, the gem5 module class knows when different stages of the simulation are happening and can do it's own extra checks. It also compartmentalizes modules more since the kernel object doesn't have to reach into them to enumerate ports and exports. Change-Id: I55887284af9c05150fe9d054f5b6147cad6092a1 Reviewed-on: https://gem5-review.googlesource.com/c/12610 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
This commit is contained in:
@@ -75,15 +75,8 @@ Kernel::init()
|
||||
fatal("Simulation called sc_stop during elaboration.\n");
|
||||
|
||||
status(::sc_core::SC_BEFORE_END_OF_ELABORATION);
|
||||
for (auto m: sc_gem5::allModules) {
|
||||
callbackModule(m);
|
||||
m->sc_mod()->before_end_of_elaboration();
|
||||
for (auto p: m->ports)
|
||||
p->before_end_of_elaboration();
|
||||
for (auto e: m->exports)
|
||||
e->before_end_of_elaboration();
|
||||
}
|
||||
callbackModule(nullptr);
|
||||
for (auto m: sc_gem5::allModules)
|
||||
m->beforeEndOfElaboration();
|
||||
for (auto c: sc_gem5::allChannels)
|
||||
c->sc_chan()->before_end_of_elaboration();
|
||||
}
|
||||
@@ -100,15 +93,8 @@ Kernel::regStats()
|
||||
p->_gem5Finalize();
|
||||
|
||||
status(::sc_core::SC_END_OF_ELABORATION);
|
||||
for (auto m: sc_gem5::allModules) {
|
||||
callbackModule(m);
|
||||
m->sc_mod()->end_of_elaboration();
|
||||
for (auto p: m->ports)
|
||||
p->end_of_elaboration();
|
||||
for (auto e: m->exports)
|
||||
e->end_of_elaboration();
|
||||
}
|
||||
callbackModule(nullptr);
|
||||
for (auto m: sc_gem5::allModules)
|
||||
m->endOfElaboration();
|
||||
for (auto c: sc_gem5::allChannels)
|
||||
c->sc_chan()->end_of_elaboration();
|
||||
} catch (...) {
|
||||
@@ -131,14 +117,8 @@ Kernel::startup()
|
||||
|
||||
try {
|
||||
status(::sc_core::SC_START_OF_SIMULATION);
|
||||
for (auto m: sc_gem5::allModules) {
|
||||
m->sc_mod()->start_of_simulation();
|
||||
for (auto p: m->ports)
|
||||
p->start_of_simulation();
|
||||
for (auto e: m->exports)
|
||||
e->start_of_simulation();
|
||||
}
|
||||
callbackModule(nullptr);
|
||||
for (auto m: sc_gem5::allModules)
|
||||
m->startOfSimulation();
|
||||
for (auto c: sc_gem5::allChannels)
|
||||
c->sc_chan()->start_of_simulation();
|
||||
} catch (...) {
|
||||
@@ -167,14 +147,8 @@ Kernel::stopWork()
|
||||
{
|
||||
status(::sc_core::SC_END_OF_SIMULATION);
|
||||
try {
|
||||
for (auto m: sc_gem5::allModules) {
|
||||
m->sc_mod()->end_of_simulation();
|
||||
for (auto p: m->ports)
|
||||
p->end_of_simulation();
|
||||
for (auto e: m->exports)
|
||||
e->end_of_simulation();
|
||||
}
|
||||
callbackModule(nullptr);
|
||||
for (auto m: sc_gem5::allModules)
|
||||
m->endOfSimulation();
|
||||
for (auto c: sc_gem5::allChannels)
|
||||
c->sc_chan()->end_of_simulation();
|
||||
} catch (...) {
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <cassert>
|
||||
|
||||
#include "base/logging.hh"
|
||||
#include "systemc/ext/core/sc_export.hh"
|
||||
#include "systemc/ext/core/sc_port.hh"
|
||||
#include "systemc/ext/utils/sc_report_handler.hh"
|
||||
|
||||
@@ -48,7 +49,9 @@ Module *_callbackModule = nullptr;
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
Module::Module(const char *name) : _name(name), _sc_mod(nullptr), _obj(nullptr)
|
||||
Module::Module(const char *name) :
|
||||
_name(name), _sc_mod(nullptr), _obj(nullptr), _ended(false),
|
||||
_deprecatedConstructor(false)
|
||||
{
|
||||
panic_if(_new_module, "Previous module not finished.\n");
|
||||
_new_module = this;
|
||||
@@ -105,6 +108,60 @@ Module::bindPorts(std::vector<const ::sc_core::sc_bind_proxy *> &proxies)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Module::beforeEndOfElaboration()
|
||||
{
|
||||
callbackModule(this);
|
||||
_sc_mod->before_end_of_elaboration();
|
||||
for (auto p: ports)
|
||||
p->before_end_of_elaboration();
|
||||
for (auto e: exports)
|
||||
e->before_end_of_elaboration();
|
||||
callbackModule(nullptr);
|
||||
}
|
||||
|
||||
void
|
||||
Module::endOfElaboration()
|
||||
{
|
||||
if (_deprecatedConstructor && !_ended) {
|
||||
std::string msg = csprintf("module '%s'", name());
|
||||
SC_REPORT_WARNING("(W509) module construction not properly completed: "
|
||||
"did you forget to add a sc_module_name parameter to "
|
||||
"your module constructor?", msg.c_str());
|
||||
}
|
||||
callbackModule(this);
|
||||
_sc_mod->end_of_elaboration();
|
||||
for (auto p: ports)
|
||||
p->end_of_elaboration();
|
||||
for (auto e: exports)
|
||||
e->end_of_elaboration();
|
||||
callbackModule(nullptr);
|
||||
}
|
||||
|
||||
void
|
||||
Module::startOfSimulation()
|
||||
{
|
||||
callbackModule(this);
|
||||
_sc_mod->start_of_simulation();
|
||||
for (auto p: ports)
|
||||
p->start_of_simulation();
|
||||
for (auto e: exports)
|
||||
e->start_of_simulation();
|
||||
callbackModule(nullptr);
|
||||
}
|
||||
|
||||
void
|
||||
Module::endOfSimulation()
|
||||
{
|
||||
callbackModule(this);
|
||||
_sc_mod->end_of_simulation();
|
||||
for (auto p: ports)
|
||||
p->end_of_simulation();
|
||||
for (auto e: exports)
|
||||
e->end_of_simulation();
|
||||
callbackModule(nullptr);
|
||||
}
|
||||
|
||||
Module *
|
||||
currentModule()
|
||||
{
|
||||
|
||||
@@ -74,6 +74,8 @@ class Module
|
||||
const char *_name;
|
||||
sc_core::sc_module *_sc_mod;
|
||||
Object *_obj;
|
||||
bool _ended;
|
||||
bool _deprecatedConstructor;
|
||||
|
||||
UniqueNameGen nameGen;
|
||||
|
||||
@@ -85,6 +87,8 @@ class Module
|
||||
void finish(Object *this_obj);
|
||||
|
||||
const char *name() const { return _name; }
|
||||
void endModule() { _ended = true; }
|
||||
void deprecatedConstructor() { _deprecatedConstructor = true; }
|
||||
|
||||
sc_core::sc_module *
|
||||
sc_mod() const
|
||||
@@ -115,6 +119,11 @@ class Module
|
||||
|
||||
std::vector<::sc_core::sc_port_base *> ports;
|
||||
std::vector<::sc_core::sc_export_base *> exports;
|
||||
|
||||
void beforeEndOfElaboration();
|
||||
void endOfElaboration();
|
||||
void startOfSimulation();
|
||||
void endOfSimulation();
|
||||
};
|
||||
|
||||
Module *currentModule();
|
||||
|
||||
@@ -221,10 +221,27 @@ sc_module::sc_module() :
|
||||
{}
|
||||
|
||||
sc_module::sc_module(const sc_module_name &) : sc_module() {}
|
||||
sc_module::sc_module(const char *_name) : sc_module(sc_module_name(_name)) {}
|
||||
sc_module::sc_module(const char *_name) : sc_module(sc_module_name(_name))
|
||||
{
|
||||
_gem5_module->deprecatedConstructor();
|
||||
SC_REPORT_WARNING("(W569) sc_module(const char*), "
|
||||
"sc_module(const std::string&) have been deprecated, use "
|
||||
"sc_module(const sc_module_name&)", _name);
|
||||
}
|
||||
sc_module::sc_module(const std::string &_name) :
|
||||
sc_module(sc_module_name(_name.c_str()))
|
||||
{}
|
||||
{
|
||||
_gem5_module->deprecatedConstructor();
|
||||
SC_REPORT_WARNING("(W569) sc_module(const char*), "
|
||||
"sc_module(const std::string&) have been deprecated, use "
|
||||
"sc_module(const sc_module_name&)", _name.c_str());
|
||||
}
|
||||
|
||||
void
|
||||
sc_module::end_module()
|
||||
{
|
||||
_gem5_module->endModule();
|
||||
}
|
||||
|
||||
void
|
||||
sc_module::reset_signal_is(const sc_in<bool> &, bool)
|
||||
|
||||
@@ -48,7 +48,7 @@ class sc_export_base : public sc_object
|
||||
virtual const sc_interface *get_interface() const = 0;
|
||||
|
||||
protected:
|
||||
friend class sc_gem5::Kernel;
|
||||
friend class sc_gem5::Module;
|
||||
|
||||
virtual void before_end_of_elaboration() = 0;
|
||||
virtual void end_of_elaboration() = 0;
|
||||
|
||||
@@ -95,6 +95,7 @@ class sc_module : public sc_object
|
||||
{
|
||||
public:
|
||||
friend class ::sc_gem5::Kernel;
|
||||
friend class ::sc_gem5::Module;
|
||||
|
||||
virtual ~sc_module();
|
||||
|
||||
@@ -177,7 +178,7 @@ class sc_module : public sc_object
|
||||
sc_module(const std::string &);
|
||||
|
||||
/* Deprecated, but used in the regression tests. */
|
||||
void end_module() {}
|
||||
void end_module();
|
||||
|
||||
void reset_signal_is(const sc_in<bool> &, bool);
|
||||
void reset_signal_is(const sc_inout<bool> &, bool);
|
||||
|
||||
@@ -233,7 +233,6 @@ class LogChecker(Checker):
|
||||
r'^\nInfo: \(I804\) /IEEE_Std_1666/deprecated: \n' +
|
||||
r' sc_clock\(const char(.*\n){3}',
|
||||
warning_filt(540),
|
||||
warning_filt(569),
|
||||
warning_filt(571),
|
||||
info_filt(804),
|
||||
in_file_filt,
|
||||
|
||||
Reference in New Issue
Block a user