summaryrefslogtreecommitdiff
path: root/src/systemc/core
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-09-07 18:25:10 -0700
committerGabe Black <gabeblack@google.com>2018-10-09 21:44:00 +0000
commita4b82a86115649cbe403315bf04231d5c9512015 (patch)
tree2cd692e0d2f8e179c5b89c3b76ef23415f5d3ac6 /src/systemc/core
parent18ca156d81b7399945fdb11a3a8aee34f05bf92c (diff)
downloadgem5-a4b82a86115649cbe403315bf04231d5c9512015.tar.xz
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>
Diffstat (limited to 'src/systemc/core')
-rw-r--r--src/systemc/core/kernel.cc42
-rw-r--r--src/systemc/core/module.cc59
-rw-r--r--src/systemc/core/module.hh9
-rw-r--r--src/systemc/core/sc_module.cc21
4 files changed, 94 insertions, 37 deletions
diff --git a/src/systemc/core/kernel.cc b/src/systemc/core/kernel.cc
index dc5a86148..ca99e1932 100644
--- a/src/systemc/core/kernel.cc
+++ b/src/systemc/core/kernel.cc
@@ -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 (...) {
diff --git a/src/systemc/core/module.cc b/src/systemc/core/module.cc
index 78ce2c6fb..dcd6faa53 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 @@ 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()
{
diff --git a/src/systemc/core/module.hh b/src/systemc/core/module.hh
index e60018e2b..aa723368a 100644
--- a/src/systemc/core/module.hh
+++ b/src/systemc/core/module.hh
@@ -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();
diff --git a/src/systemc/core/sc_module.cc b/src/systemc/core/sc_module.cc
index 3cceff119..2fc6e8c75 100644
--- a/src/systemc/core/sc_module.cc
+++ b/src/systemc/core/sc_module.cc
@@ -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)