summaryrefslogtreecommitdiff
path: root/src/systemc/core/module.cc
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-06-22 14:19:44 -0700
committerGabe Black <gabeblack@google.com>2018-09-05 06:01:39 +0000
commit9bd3bb7bc804a16b2f0de03fa6d3d9d0928f38a2 (patch)
treea9500949c781d55fea96bf9fb7098a9639b7af5a /src/systemc/core/module.cc
parent97018a3b20c129a3413011d205f18189dd1a75c9 (diff)
downloadgem5-9bd3bb7bc804a16b2f0de03fa6d3d9d0928f38a2.tar.xz
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 <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/systemc/core/module.cc')
-rw-r--r--src/systemc/core/module.cc37
1 files changed, 27 insertions, 10 deletions
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 <cassert>
#include <list>
#include "base/logging.hh"
-namespace SystemC
+namespace sc_gem5
{
namespace
{
std::list<Module *> _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