48,49d47
< Module *_callbackModule = nullptr;
<
62,63c60,61
< if (_new_module == this) {
< // Aborted module construction?
---
> // Aborted module construction?
> if (_new_module == this)
65c63,68
< }
---
>
> // Attempt to pop now in case we're at the top of the stack, so that
> // a stale pointer to us isn't left floating around for somebody to trip
> // on.
> pop();
>
75,79c78,88
< _new_module = nullptr;
< // This is called from the constructor of this_obj, so it can't use
< // dynamic cast.
< sc_mod(static_cast<::sc_core::sc_module *>(this_obj->sc_obj()));
< allModules.emplace_back(this);
---
> pushParentModule(this);
> try {
> _new_module = nullptr;
> // This is called from the constructor of this_obj, so it can't use
> // dynamic cast.
> sc_mod(static_cast<::sc_core::sc_module *>(this_obj->sc_obj()));
> allModules.emplace_back(this);
> } catch (...) {
> popParentModule();
> throw;
> }
85,87c94,96
< panic_if(!_modules.size(), "Popping from empty module list.\n");
< panic_if(_modules.back() != this,
< "Popping module which isn't at the end of the module list.\n");
---
> if (_modules.empty() || _modules.back() != this)
> return;
>
88a98
>
89a100
> popParentModule();
114,118c125,134
< callbackModule(this);
< _sc_mod->before_end_of_elaboration();
< for (auto e: exports)
< e->before_end_of_elaboration();
< callbackModule(nullptr);
---
> pushParentModule(this);
> try {
> _sc_mod->before_end_of_elaboration();
> for (auto e: exports)
> e->before_end_of_elaboration();
> } catch (...) {
> popParentModule();
> throw;
> }
> popParentModule();
130,134c146,155
< callbackModule(this);
< _sc_mod->end_of_elaboration();
< for (auto e: exports)
< e->end_of_elaboration();
< callbackModule(nullptr);
---
> pushParentModule(this);
> try {
> _sc_mod->end_of_elaboration();
> for (auto e: exports)
> e->end_of_elaboration();
> } catch (...) {
> popParentModule();
> throw;
> }
> popParentModule();
140,144c161,170
< callbackModule(this);
< _sc_mod->start_of_simulation();
< for (auto e: exports)
< e->start_of_simulation();
< callbackModule(nullptr);
---
> pushParentModule(this);
> try {
> _sc_mod->start_of_simulation();
> for (auto e: exports)
> e->start_of_simulation();
> } catch (...) {
> popParentModule();
> throw;
> }
> popParentModule();
150,154c176,185
< callbackModule(this);
< _sc_mod->end_of_simulation();
< for (auto e: exports)
< e->end_of_simulation();
< callbackModule(nullptr);
---
> pushParentModule(this);
> try {
> _sc_mod->end_of_simulation();
> for (auto e: exports)
> e->end_of_simulation();
> } catch(...) {
> popParentModule();
> throw;
> }
> popParentModule();
182,184d212
< void callbackModule(Module *m) { _callbackModule = m; }
< Module *callbackModule() { return _callbackModule; }
<