gem5 v24.0.0.0
Loading...
Searching...
No Matches
module.cc
Go to the documentation of this file.
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
29
30#include <cassert>
31
32#include "base/logging.hh"
37
38namespace sc_gem5
39{
40
41namespace
42{
43
44std::list<Module *> _modules;
45Module *_new_module;
46
47} // anonymous namespace
48
50
51Module::Module(const char *name) :
52 _name(name), _sc_mod(nullptr), _obj(nullptr), _ended(false),
53 _deprecatedConstructor(false), bindingIndex(0)
54{
55 using namespace gem5;
56 panic_if(_new_module, "Previous module not finished.\n");
57 _new_module = this;
58}
59
61{
62 // Aborted module construction?
63 if (_new_module == this)
64 _new_module = nullptr;
65
66 // Attempt to pop now in case we're at the top of the stack, so that
67 // a stale pointer to us isn't left floating around for somebody to trip
68 // on.
69 pop();
70
71 allModules.remove(this);
72}
73
74void
76{
77 assert(!_obj);
78 _obj = this_obj;
79 _modules.push_back(this);
80 pushParentModule(this);
81 try {
82 _new_module = nullptr;
83 // This is called from the constructor of this_obj, so it can't use
84 // dynamic cast.
85 sc_mod(static_cast<::sc_core::sc_module *>(this_obj->sc_obj()));
86 allModules.emplace_back(this);
87 } catch (...) {
89 throw;
90 }
91}
92
93void
95{
96 if (_modules.empty() || _modules.back() != this)
97 return;
98
99 using namespace gem5;
100 panic_if(_new_module, "Pop with unfinished module.\n");
101
102 _modules.pop_back();
104}
105
106void
108{
109 using namespace gem5;
110 panic_if(proxies.size() > ports.size(),
111 "Trying to bind %d interfaces/ports to %d ports.\n",
112 proxies.size(), ports.size());
113
114 auto proxyIt = proxies.begin();
115 auto portIt = ports.begin();
116 portIt += bindingIndex;
117 for (; proxyIt != proxies.end(); proxyIt++, portIt++) {
118 auto proxy = *proxyIt;
119 auto port = *portIt;
120 if (proxy->interface())
121 port->vbind(*proxy->interface());
122 else
123 port->vbind(*proxy->port());
124 }
125 bindingIndex += proxies.size();
126}
127
128void
130{
131 pushParentModule(this);
132 try {
134 for (auto e: exports)
135 e->before_end_of_elaboration();
136 } catch (...) {
138 throw;
139 }
141}
142
143void
145{
147 std::string msg = gem5::csprintf("module '%s'", name());
149 }
150 pushParentModule(this);
151 try {
153 for (auto e: exports)
154 e->end_of_elaboration();
155 } catch (...) {
157 throw;
158 }
160}
161
162void
164{
165 pushParentModule(this);
166 try {
168 for (auto e: exports)
169 e->start_of_simulation();
170 } catch (...) {
172 throw;
173 }
175}
176
177void
179{
180 pushParentModule(this);
181 try {
183 for (auto e: exports)
184 e->end_of_simulation();
185 } catch(...) {
187 throw;
188 }
190}
191
192Module *
194{
195 if (_modules.empty())
196 return nullptr;
197 return _modules.back();
198}
199
200Module *
202{
203 if (!_new_module)
205 return _new_module;
206}
207
208Module *
210{
211 return _new_module;
212}
213
215
216} // namespace sc_gem5
virtual void end_of_simulation()
Definition sc_module.hh:255
virtual void before_end_of_elaboration()
Definition sc_module.hh:252
virtual void start_of_simulation()
Definition sc_module.hh:254
virtual void end_of_elaboration()
Definition sc_module.hh:253
bool _deprecatedConstructor
Definition module.hh:78
sc_core::sc_module * sc_mod() const
Definition module.hh:99
void endOfElaboration()
Definition module.cc:144
void endOfSimulation()
Definition module.cc:178
std::vector<::sc_core::sc_export_base * > exports
Definition module.hh:126
sc_core::sc_module * _sc_mod
Definition module.hh:75
void beforeEndOfElaboration()
Definition module.cc:129
void startOfSimulation()
Definition module.cc:163
void bindPorts(std::vector< const ::sc_core::sc_bind_proxy * > &proxies)
Definition module.cc:107
const char * name() const
Definition module.hh:94
Object * _obj
Definition module.hh:76
std::vector<::sc_core::sc_port_base * > ports
Definition module.hh:125
Module(const char *name)
Definition module.cc:51
void finish(Object *this_obj)
Definition module.cc:75
sc_core::sc_object * sc_obj()
Definition object.hh:86
STL list class.
Definition stl.hh:51
STL vector class.
Definition stl.hh:37
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161
const char SC_ID_MODULE_NAME_STACK_EMPTY_[]
Definition messages.cc:84
const char SC_ID_END_MODULE_NOT_CALLED_[]
Definition messages.cc:45
UniqueNameGen globalNameGen
Definition module.cc:49
static void popParentModule()
Definition module.hh:155
Module * newModule()
Definition module.cc:209
Module * currentModule()
Definition module.cc:193
static void pushParentModule(Module *m)
Definition module.hh:150
Module * newModuleChecked()
Definition module.cc:201
std::list< Module * > allModules
Definition module.cc:214
#define SC_REPORT_WARNING(msg_type, msg)
#define SC_REPORT_ERROR(msg_type, msg)
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0