Deleted Added
sdiff udiff text old ( 13207:034ca389a810 ) new ( 13268:9802f3e0a6ae )
full compact
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

--- 31 unchanged lines hidden (view full) ---

40{
41
42namespace
43{
44
45std::list<Module *> _modules;
46Module *_new_module;
47
48} // anonymous namespace
49
50Module::Module(const char *name) :
51 _name(name), _sc_mod(nullptr), _obj(nullptr), _ended(false),
52 _deprecatedConstructor(false)
53{
54 panic_if(_new_module, "Previous module not finished.\n");
55 _new_module = this;
56}
57
58Module::~Module()
59{
60 // Aborted module construction?
61 if (_new_module == this)
62 _new_module = nullptr;
63
64 // Attempt to pop now in case we're at the top of the stack, so that
65 // a stale pointer to us isn't left floating around for somebody to trip
66 // on.
67 pop();
68
69 allModules.remove(this);
70}
71
72void
73Module::finish(Object *this_obj)
74{
75 assert(!_obj);
76 _obj = this_obj;
77 _modules.push_back(this);
78 pushParentModule(this);
79 try {
80 _new_module = nullptr;
81 // This is called from the constructor of this_obj, so it can't use
82 // dynamic cast.
83 sc_mod(static_cast<::sc_core::sc_module *>(this_obj->sc_obj()));
84 allModules.emplace_back(this);
85 } catch (...) {
86 popParentModule();
87 throw;
88 }
89}
90
91void
92Module::pop()
93{
94 if (_modules.empty() || _modules.back() != this)
95 return;
96
97 panic_if(_new_module, "Pop with unfinished module.\n");
98
99 _modules.pop_back();
100 popParentModule();
101}
102
103void
104Module::bindPorts(std::vector<const ::sc_core::sc_bind_proxy *> &proxies)
105{
106 panic_if(proxies.size() > ports.size(),
107 "Trying to bind %d interfaces/ports to %d ports.\n",
108 proxies.size(), ports.size());

--- 8 unchanged lines hidden (view full) ---

117 else
118 port->vbind(*proxy->port());
119 }
120}
121
122void
123Module::beforeEndOfElaboration()
124{
125 pushParentModule(this);
126 try {
127 _sc_mod->before_end_of_elaboration();
128 for (auto e: exports)
129 e->before_end_of_elaboration();
130 } catch (...) {
131 popParentModule();
132 throw;
133 }
134 popParentModule();
135}
136
137void
138Module::endOfElaboration()
139{
140 if (_deprecatedConstructor && !_ended) {
141 std::string msg = csprintf("module '%s'", name());
142 SC_REPORT_WARNING("(W509) module construction not properly completed: "
143 "did you forget to add a sc_module_name parameter to "
144 "your module constructor?", msg.c_str());
145 }
146 pushParentModule(this);
147 try {
148 _sc_mod->end_of_elaboration();
149 for (auto e: exports)
150 e->end_of_elaboration();
151 } catch (...) {
152 popParentModule();
153 throw;
154 }
155 popParentModule();
156}
157
158void
159Module::startOfSimulation()
160{
161 pushParentModule(this);
162 try {
163 _sc_mod->start_of_simulation();
164 for (auto e: exports)
165 e->start_of_simulation();
166 } catch (...) {
167 popParentModule();
168 throw;
169 }
170 popParentModule();
171}
172
173void
174Module::endOfSimulation()
175{
176 pushParentModule(this);
177 try {
178 _sc_mod->end_of_simulation();
179 for (auto e: exports)
180 e->end_of_simulation();
181 } catch(...) {
182 popParentModule();
183 throw;
184 }
185 popParentModule();
186}
187
188Module *
189currentModule()
190{
191 if (_modules.empty())
192 return nullptr;
193 return _modules.back();

--- 11 unchanged lines hidden (view full) ---

205}
206
207Module *
208newModule()
209{
210 return _new_module;
211}
212
213std::list<Module *> allModules;
214
215} // namespace sc_gem5