Gabe Black has submitted this change and it was merged. (
https://gem5-review.googlesource.com/c/public/gem5/+/12610 )
Change subject: systemc: Centralize module callbacks and report new
warnings.
......................................................................
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 <[email protected]>
Maintainer: Gabe Black <[email protected]>
---
M src/systemc/core/kernel.cc
M src/systemc/core/module.cc
M src/systemc/core/module.hh
M src/systemc/core/sc_module.cc
M src/systemc/ext/core/sc_export.hh
M src/systemc/ext/core/sc_module.hh
M src/systemc/tests/verify.py
7 files changed, 97 insertions(+), 40 deletions(-)
Approvals:
Gabe Black: Looks good to me, approved; Looks good to me, approved
diff --git a/src/systemc/core/kernel.cc b/src/systemc/core/kernel.cc
index dc5a861..ca99e19 100644
--- a/src/systemc/core/kernel.cc
+++ b/src/systemc/core/kernel.cc
@@ -75,15 +75,8 @@
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 @@
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 @@
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 @@
{
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 (...) {
diff --git a/src/systemc/core/module.cc b/src/systemc/core/module.cc
index 78ce2c6..dcd6faa 100644
--- a/src/systemc/core/module.cc
+++ b/src/systemc/core/module.cc
@@ -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 @@
} // 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 @@
}
}
+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()
{
diff --git a/src/systemc/core/module.hh b/src/systemc/core/module.hh
index e60018e..aa72336 100644
--- a/src/systemc/core/module.hh
+++ b/src/systemc/core/module.hh
@@ -74,6 +74,8 @@
const char *_name;
sc_core::sc_module *_sc_mod;
Object *_obj;
+ bool _ended;
+ bool _deprecatedConstructor;
UniqueNameGen nameGen;
@@ -85,6 +87,8 @@
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 @@
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();
diff --git a/src/systemc/core/sc_module.cc b/src/systemc/core/sc_module.cc
index 3cceff1..2fc6e8c 100644
--- a/src/systemc/core/sc_module.cc
+++ b/src/systemc/core/sc_module.cc
@@ -221,10 +221,27 @@
{}
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)
diff --git a/src/systemc/ext/core/sc_export.hh
b/src/systemc/ext/core/sc_export.hh
index f5ce894..e8bf0d9 100644
--- a/src/systemc/ext/core/sc_export.hh
+++ b/src/systemc/ext/core/sc_export.hh
@@ -48,7 +48,7 @@
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;
diff --git a/src/systemc/ext/core/sc_module.hh
b/src/systemc/ext/core/sc_module.hh
index 0e5e679..e5e4c20 100644
--- a/src/systemc/ext/core/sc_module.hh
+++ b/src/systemc/ext/core/sc_module.hh
@@ -95,6 +95,7 @@
{
public:
friend class ::sc_gem5::Kernel;
+ friend class ::sc_gem5::Module;
virtual ~sc_module();
@@ -177,7 +178,7 @@
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);
diff --git a/src/systemc/tests/verify.py b/src/systemc/tests/verify.py
index 051d5b5..fe16551 100755
--- a/src/systemc/tests/verify.py
+++ b/src/systemc/tests/verify.py
@@ -233,7 +233,6 @@
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,
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12610
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I55887284af9c05150fe9d054f5b6147cad6092a1
Gerrit-Change-Number: 12610
Gerrit-PatchSet: 8
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Matthias Jung <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev