gem5  v21.1.0.2
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 
28 #include "systemc/core/module.hh"
29 
30 #include <cassert>
31 
32 #include "base/logging.hh"
37 
38 namespace sc_gem5
39 {
40 
41 namespace
42 {
43 
44 std::list<Module *> _modules;
45 Module *_new_module;
46 
47 } // anonymous namespace
48 
50 
51 Module::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 
74 void
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 
93 void
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();
103  popParentModule();
104 }
105 
106 void
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 
128 void
130 {
131  pushParentModule(this);
132  try {
134  for (auto e: exports)
135  e->before_end_of_elaboration();
136  } catch (...) {
137  popParentModule();
138  throw;
139  }
140  popParentModule();
141 }
142 
143 void
145 {
146  if (_deprecatedConstructor && !_ended) {
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 (...) {
156  popParentModule();
157  throw;
158  }
159  popParentModule();
160 }
161 
162 void
164 {
165  pushParentModule(this);
166  try {
168  for (auto e: exports)
169  e->start_of_simulation();
170  } catch (...) {
171  popParentModule();
172  throw;
173  }
174  popParentModule();
175 }
176 
177 void
179 {
180  pushParentModule(this);
181  try {
183  for (auto e: exports)
184  e->end_of_simulation();
185  } catch(...) {
186  popParentModule();
187  throw;
188  }
189  popParentModule();
190 }
191 
192 Module *
194 {
195  if (_modules.empty())
196  return nullptr;
197  return _modules.back();
198 }
199 
200 Module *
202 {
203  if (!_new_module)
205  return _new_module;
206 }
207 
208 Module *
210 {
211  return _new_module;
212 }
213 
215 
216 } // namespace sc_gem5
sc_gem5::globalNameGen
UniqueNameGen globalNameGen
Definition: module.cc:49
sc_gem5::Module::exports
std::vector<::sc_core::sc_export_base * > exports
Definition: module.hh:126
sc_gem5::Module::startOfSimulation
void startOfSimulation()
Definition: module.cc:163
sc_core::sc_module
Definition: sc_module.hh:98
sc_gem5::Object::sc_obj
sc_core::sc_object * sc_obj()
Definition: object.hh:86
module.hh
sc_gem5::Module::ports
std::vector<::sc_core::sc_port_base * > ports
Definition: module.hh:125
sc_gem5::Module::pop
void pop()
Definition: module.cc:94
sc_gem5::Module::_obj
Object * _obj
Definition: module.hh:76
sc_gem5::Module::name
const char * name() const
Definition: module.hh:94
sc_core::SC_ID_END_MODULE_NOT_CALLED_
const char SC_ID_END_MODULE_NOT_CALLED_[]
Definition: messages.cc:45
gem5::ArmISA::e
Bitfield< 9 > e
Definition: misc_types.hh:64
sc_port.hh
sc_gem5::UniqueNameGen
Definition: module.hh:52
std::vector
STL vector class.
Definition: stl.hh:37
gem5::csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
sc_gem5::Module::_ended
bool _ended
Definition: module.hh:77
sc_gem5::Module::sc_mod
sc_core::sc_module * sc_mod() const
Definition: module.hh:99
sc_gem5::Module::Module
Module(const char *name)
Definition: module.cc:51
sc_gem5::Module::finish
void finish(Object *this_obj)
Definition: module.cc:75
sc_gem5::Module::~Module
~Module()
Definition: module.cc:60
sc_gem5::popParentModule
static void popParentModule()
Definition: module.hh:155
sc_core::sc_module::end_of_simulation
virtual void end_of_simulation()
Definition: sc_module.hh:252
sc_gem5::currentModule
Module * currentModule()
Definition: module.cc:193
SC_REPORT_ERROR
#define SC_REPORT_ERROR(msg_type, msg)
Definition: sc_report_handler.hh:127
sc_gem5::Module::bindPorts
void bindPorts(std::vector< const ::sc_core::sc_bind_proxy * > &proxies)
Definition: module.cc:107
sc_gem5::Object
Definition: object.hh:47
sc_gem5::pushParentModule
static void pushParentModule(Module *m)
Definition: module.hh:150
sc_gem5::newModuleChecked
Module * newModuleChecked()
Definition: module.cc:201
messages.hh
name
const std::string & name()
Definition: trace.cc:49
sc_gem5::Module::endOfElaboration
void endOfElaboration()
Definition: module.cc:144
sc_core::sc_module::end_of_elaboration
virtual void end_of_elaboration()
Definition: sc_module.hh:250
sc_gem5::newModule
Module * newModule()
Definition: module.cc:209
SC_REPORT_WARNING
#define SC_REPORT_WARNING(msg_type, msg)
Definition: sc_report_handler.hh:123
sc_report_handler.hh
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:203
sc_gem5::Module::endOfSimulation
void endOfSimulation()
Definition: module.cc:178
sc_core::SC_ID_MODULE_NAME_STACK_EMPTY_
const char SC_ID_MODULE_NAME_STACK_EMPTY_[]
Definition: messages.cc:84
sc_core::sc_module::before_end_of_elaboration
virtual void before_end_of_elaboration()
Definition: sc_module.hh:249
sc_gem5::Module::_deprecatedConstructor
bool _deprecatedConstructor
Definition: module.hh:78
sc_gem5::allModules
std::list< Module * > allModules
Definition: module.cc:214
logging.hh
sc_gem5
Definition: sc_clock.cc:41
sc_export.hh
sc_core::sc_module::start_of_simulation
virtual void start_of_simulation()
Definition: sc_module.hh:251
std::list
STL list class.
Definition: stl.hh:51
sc_gem5::Module::bindingIndex
int bindingIndex
Definition: module.hh:128
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
sc_gem5::Module::beforeEndOfElaboration
void beforeEndOfElaboration()
Definition: module.cc:129
sc_gem5::Module::_sc_mod
sc_core::sc_module * _sc_mod
Definition: module.hh:75
sc_gem5::Module
Definition: module.hh:71

Generated on Tue Sep 21 2021 12:25:50 for gem5 by doxygen 1.8.17