object.cc (13179:7445c43d036b) object.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

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

25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * Authors: Gabe Black
28 */
29
30#include "systemc/core/object.hh"
31
32#include <algorithm>
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

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

25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * Authors: Gabe Black
28 */
29
30#include "systemc/core/object.hh"
31
32#include <algorithm>
33#include <stack>
33
34#include "base/logging.hh"
35#include "systemc/core/event.hh"
36#include "systemc/core/module.hh"
37#include "systemc/core/scheduler.hh"
38#include "systemc/ext/core/sc_module.hh"
39
40namespace sc_gem5

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

86Object::Object(sc_core::sc_object *_sc_obj) : Object(_sc_obj, nullptr) {}
87
88Object::Object(sc_core::sc_object *_sc_obj, const char *obj_name) :
89 _sc_obj(_sc_obj), _basename(obj_name ? obj_name : ""), parent(nullptr)
90{
91 if (_basename == "")
92 _basename = ::sc_core::sc_gen_unique_name("object");
93
34
35#include "base/logging.hh"
36#include "systemc/core/event.hh"
37#include "systemc/core/module.hh"
38#include "systemc/core/scheduler.hh"
39#include "systemc/ext/core/sc_module.hh"
40
41namespace sc_gem5

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

87Object::Object(sc_core::sc_object *_sc_obj) : Object(_sc_obj, nullptr) {}
88
89Object::Object(sc_core::sc_object *_sc_obj, const char *obj_name) :
90 _sc_obj(_sc_obj), _basename(obj_name ? obj_name : ""), parent(nullptr)
91{
92 if (_basename == "")
93 _basename = ::sc_core::sc_gen_unique_name("object");
94
94 Module *p = currentModule();
95 if (!p)
96 p = callbackModule();
95 parent = pickParentObj();
97
98 Module *n = newModule();
99 if (n) {
100 // We are a module in the process of being constructed.
101 n->finish(this);
102 }
103
96
97 Module *n = newModule();
98 if (n) {
99 // We are a module in the process of being constructed.
100 n->finish(this);
101 }
102
104 if (p) {
105 // We're "within" a parent module, ie we're being created while its
106 // constructor or end_of_elaboration callback is running.
107 parent = p->obj()->_sc_obj;
108 } else if (scheduler.current()) {
109 // Our parent is the currently running process.
110 parent = scheduler.current();
111 }
112
113 std::string original_name = _basename;
114 _basename = sc_gem5::pickUniqueName(parent, original_name);
115
116 if (parent)
117 addObject(&parent->_gem5_object->children, _sc_obj);
118 else
119 addObject(&topLevelObjects, _sc_obj);
120

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

303
304sc_core::sc_object *
305findObject(const char *name, const Objects &objects)
306{
307 ObjectsIt it = findObjectIn(allObjects, name);
308 return it == allObjects.end() ? nullptr : *it;
309}
310
103 std::string original_name = _basename;
104 _basename = sc_gem5::pickUniqueName(parent, original_name);
105
106 if (parent)
107 addObject(&parent->_gem5_object->children, _sc_obj);
108 else
109 addObject(&topLevelObjects, _sc_obj);
110

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

293
294sc_core::sc_object *
295findObject(const char *name, const Objects &objects)
296{
297 ObjectsIt it = findObjectIn(allObjects, name);
298 return it == allObjects.end() ? nullptr : *it;
299}
300
301namespace
302{
303
304std::stack<sc_core::sc_object *> objParentStack;
305
306} // anonymous namespace
307
308sc_core::sc_object *
309pickParentObj()
310{
311 if (!objParentStack.empty())
312 return objParentStack.top();
313
314 Process *p = scheduler.current();
315 if (p)
316 return p;
317
318 return nullptr;
319}
320
321void pushParentObj(sc_core::sc_object *obj) { objParentStack.push(obj); }
322void popParentObj() { objParentStack.pop(); }
323
311} // namespace sc_gem5
324} // namespace sc_gem5