This is tested by the regression tests. Also make sure the handshake
which sets up instances of sc_module is cleaned up if we bail partway
through for some reason, for instance if an intermediate class throws
an exception as part of its constructor.
Change-Id: I89afe5f76832cc132aa2bb8f19916dea64546784
Reviewed-on: https://gem5-review.googlesource.com/12251
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Gabe Black <gabeblack@google.com>
#include <cassert>
#include "base/logging.hh"
+#include "systemc/ext/utils/sc_report_handler.hh"
namespace sc_gem5
{
_new_module = this;
}
-Module::~Module() { allModules.remove(this); }
+Module::~Module()
+{
+ if (_new_module == this) {
+ // Aborted module construction?
+ _new_module = nullptr;
+ }
+ allModules.remove(this);
+}
void
Module::finish(Object *this_obj)
return _modules.back();
}
+Module *
+newModuleChecked()
+{
+ if (!_new_module) {
+ SC_REPORT_ERROR("(E533) module name stack is empty: "
+ "did you forget to add a sc_module_name parameter to "
+ "your module constructor?", nullptr);
+ }
+ return _new_module;
+}
+
Module *
newModule()
{
};
Module *currentModule();
+Module *newModuleChecked();
Module *newModule();
void callbackModule(Module *m);
}
sc_module::sc_module() :
- sc_object(sc_gem5::newModule()->name()),
+ sc_object(sc_gem5::newModuleChecked()->name()),
_gem5_module(sc_gem5::currentModule())
{}