From 9bd3bb7bc804a16b2f0de03fa6d3d9d0928f38a2 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Fri, 22 Jun 2018 14:19:44 -0700 Subject: systemc: Implement most of sc_object. To avoid making it hard to change sc_object's implementation in the future, this change keeps most of the data members out of sc_object and keeps them in a seperate Object which is managed independently but still matches to the sc_objects one to one. This change also moves away from the SystemC/sc_gem5 namespace pair in favor of sc_gem5. Having two namespaces with classes, etc, living in both was complicating things. Having to use a namespace that doesn't fit in one scheme or the other isn't great, but it's the lesser of two evils. Change-Id: Ib59c3c515ca98c7fe519c59e9fe9270304b71cc0 Reviewed-on: https://gem5-review.googlesource.com/11611 Reviewed-by: Gabe Black Maintainer: Gabe Black --- src/systemc/core/module.cc | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'src/systemc/core/module.cc') diff --git a/src/systemc/core/module.cc b/src/systemc/core/module.cc index 97a4a9ffa..3b7e922e3 100644 --- a/src/systemc/core/module.cc +++ b/src/systemc/core/module.cc @@ -29,42 +29,59 @@ #include "systemc/core/module.hh" +#include #include #include "base/logging.hh" -namespace SystemC +namespace sc_gem5 { namespace { std::list _modules; - -Module *_top_module = nullptr; +Module *_new_module; } // anonymous namespace +Module::Module(const char *name) : _name(name), _sc_mod(nullptr), _obj(nullptr) +{ + panic_if(_new_module, "Previous module not finished.\n"); + _new_module = this; +} + void -Module::push() +Module::finish(Object *this_obj) { - if (!_top_module) - _top_module = this; + assert(!_obj); + _obj = this_obj; _modules.push_back(this); + _new_module = nullptr; } void Module::pop() { - panic_if(_modules.size(), "Popping from empty module list.\n"); + 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"); + panic_if(_new_module, "Pop with unfinished module.\n"); + _modules.pop_back(); +} + +Module * +currentModule() +{ + if (_modules.empty()) + return nullptr; + return _modules.back(); } Module * -topModule() +newModule() { - return _top_module; + return _new_module; } -} // namespace SystemC +} // namespace sc_gem5 -- cgit v1.2.3