module.cc (13207:034ca389a810) | module.cc (13268:9802f3e0a6ae) |
---|---|
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 | 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 |
48Module *_callbackModule = nullptr; 49 | |
50} // anonymous namespace 51 52Module::Module(const char *name) : 53 _name(name), _sc_mod(nullptr), _obj(nullptr), _ended(false), 54 _deprecatedConstructor(false) 55{ 56 panic_if(_new_module, "Previous module not finished.\n"); 57 _new_module = this; 58} 59 60Module::~Module() 61{ | 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{ |
62 if (_new_module == this) { 63 // Aborted module construction? | 60 // Aborted module construction? 61 if (_new_module == this) |
64 _new_module = nullptr; | 62 _new_module = nullptr; |
65 } | 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 |
66 allModules.remove(this); 67} 68 69void 70Module::finish(Object *this_obj) 71{ 72 assert(!_obj); 73 _obj = this_obj; 74 _modules.push_back(this); | 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); |
75 _new_module = nullptr; 76 // This is called from the constructor of this_obj, so it can't use 77 // dynamic cast. 78 sc_mod(static_cast<::sc_core::sc_module *>(this_obj->sc_obj())); 79 allModules.emplace_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 } |
80} 81 82void 83Module::pop() 84{ | 89} 90 91void 92Module::pop() 93{ |
85 panic_if(!_modules.size(), "Popping from empty module list.\n"); 86 panic_if(_modules.back() != this, 87 "Popping module which isn't at the end of the module list.\n"); | 94 if (_modules.empty() || _modules.back() != this) 95 return; 96 |
88 panic_if(_new_module, "Pop with unfinished module.\n"); | 97 panic_if(_new_module, "Pop with unfinished module.\n"); |
98 |
|
89 _modules.pop_back(); | 99 _modules.pop_back(); |
100 popParentModule(); |
|
90} 91 92void 93Module::bindPorts(std::vector<const ::sc_core::sc_bind_proxy *> &proxies) 94{ 95 panic_if(proxies.size() > ports.size(), 96 "Trying to bind %d interfaces/ports to %d ports.\n", 97 proxies.size(), ports.size()); --- 8 unchanged lines hidden (view full) --- 106 else 107 port->vbind(*proxy->port()); 108 } 109} 110 111void 112Module::beforeEndOfElaboration() 113{ | 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{ |
114 callbackModule(this); 115 _sc_mod->before_end_of_elaboration(); 116 for (auto e: exports) 117 e->before_end_of_elaboration(); 118 callbackModule(nullptr); | 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(); |
119} 120 121void 122Module::endOfElaboration() 123{ 124 if (_deprecatedConstructor && !_ended) { 125 std::string msg = csprintf("module '%s'", name()); 126 SC_REPORT_WARNING("(W509) module construction not properly completed: " 127 "did you forget to add a sc_module_name parameter to " 128 "your module constructor?", msg.c_str()); 129 } | 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 } |
130 callbackModule(this); 131 _sc_mod->end_of_elaboration(); 132 for (auto e: exports) 133 e->end_of_elaboration(); 134 callbackModule(nullptr); | 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(); |
135} 136 137void 138Module::startOfSimulation() 139{ | 156} 157 158void 159Module::startOfSimulation() 160{ |
140 callbackModule(this); 141 _sc_mod->start_of_simulation(); 142 for (auto e: exports) 143 e->start_of_simulation(); 144 callbackModule(nullptr); | 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(); |
145} 146 147void 148Module::endOfSimulation() 149{ | 171} 172 173void 174Module::endOfSimulation() 175{ |
150 callbackModule(this); 151 _sc_mod->end_of_simulation(); 152 for (auto e: exports) 153 e->end_of_simulation(); 154 callbackModule(nullptr); | 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(); |
155} 156 157Module * 158currentModule() 159{ 160 if (_modules.empty()) 161 return nullptr; 162 return _modules.back(); --- 11 unchanged lines hidden (view full) --- 174} 175 176Module * 177newModule() 178{ 179 return _new_module; 180} 181 | 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 |
182void callbackModule(Module *m) { _callbackModule = m; } 183Module *callbackModule() { return _callbackModule; } 184 | |
185std::list<Module *> allModules; 186 187} // namespace sc_gem5 | 213std::list<Module *> allModules; 214 215} // namespace sc_gem5 |