object.cc (12953:ddfd5e4643a9) object.cc (12955:9c8bf6a5f2e3)
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

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

62 ObjectsIt it = findObjectIn(*objects, name);
63 assert(it != objects->end());
64 std::swap(objects->back(), *it);
65 objects->pop_back();
66}
67
68} // anonymous namespace
69
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

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

62 ObjectsIt it = findObjectIn(*objects, name);
63 assert(it != objects->end());
64 std::swap(objects->back(), *it);
65 objects->pop_back();
66}
67
68} // anonymous namespace
69
70Object::Object(sc_core::sc_object *sc_obj) : Object(sc_obj, "object") {}
70Object::Object(sc_core::sc_object *_sc_obj) : Object(_sc_obj, "object") {}
71
71
72Object::Object(sc_core::sc_object *sc_obj, const char *obj_name) :
73 sc_obj(sc_obj), _basename(obj_name), parent(nullptr)
72Object::Object(sc_core::sc_object *_sc_obj, const char *obj_name) :
73 _sc_obj(_sc_obj), _basename(obj_name), parent(nullptr)
74{
75 if (_basename == "")
76 _basename = "object";
77
78 Module *p = currentModule();
79
80 Module *n = newModule();
81 if (n) {
82 // We are a module in the process of being constructed.
83 n->finish(this);
84 }
85
86 if (p) {
87 // We're "within" a parent module, ie we're being created while its
88 // constructor is running.
74{
75 if (_basename == "")
76 _basename = "object";
77
78 Module *p = currentModule();
79
80 Module *n = newModule();
81 if (n) {
82 // We are a module in the process of being constructed.
83 n->finish(this);
84 }
85
86 if (p) {
87 // We're "within" a parent module, ie we're being created while its
88 // constructor is running.
89 parent = p->obj()->sc_obj;
90 addObject(&parent->_gem5_object->children, sc_obj);
89 parent = p->obj()->_sc_obj;
90 addObject(&parent->_gem5_object->children, _sc_obj);
91 } else if (scheduler.current()) {
92 // Our parent is the currently running process.
93 parent = scheduler.current();
94 } else {
95 // We're a top level object.
91 } else if (scheduler.current()) {
92 // Our parent is the currently running process.
93 parent = scheduler.current();
94 } else {
95 // We're a top level object.
96 addObject(&topLevelObjects, sc_obj);
96 addObject(&topLevelObjects, _sc_obj);
97 }
98
97 }
98
99 addObject(&allObjects, sc_obj);
99 addObject(&allObjects, _sc_obj);
100
101 _name = _basename;
102 sc_core::sc_object *sc_p = parent;
103 while (sc_p) {
104 _name = std::string(sc_p->basename()) + std::string(".") + _name;
105 sc_p = sc_p->get_parent_object();
106 }
107}
108
100
101 _name = _basename;
102 sc_core::sc_object *sc_p = parent;
103 while (sc_p) {
104 _name = std::string(sc_p->basename()) + std::string(".") + _name;
105 sc_p = sc_p->get_parent_object();
106 }
107}
108
109Object::Object(sc_core::sc_object *sc_obj, const Object &arg) :
110 Object(sc_obj, arg._basename.c_str())
109Object::Object(sc_core::sc_object *_sc_obj, const Object &arg) :
110 Object(_sc_obj, arg._basename.c_str())
111{}
112
113Object &
114Object::operator = (const Object &)
115{
116 return *this;
117}
118

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

144{
145 out << name();
146}
147
148void
149Object::dump(std::ostream &out) const
150{
151 out << "name = " << name() << "\n";
111{}
112
113Object &
114Object::operator = (const Object &)
115{
116 return *this;
117}
118

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

144{
145 out << name();
146}
147
148void
149Object::dump(std::ostream &out) const
150{
151 out << "name = " << name() << "\n";
152 out << "kind = " << sc_obj->kind() << "\n";
152 out << "kind = " << _sc_obj->kind() << "\n";
153}
154
155const std::vector<sc_core::sc_object *> &
156Object::get_child_objects() const
157{
158 return children;
159}
160

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

213
214sc_core::sc_simcontext *
215Object::simcontext() const
216{
217 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
218 return nullptr;
219}
220
153}
154
155const std::vector<sc_core::sc_object *> &
156Object::get_child_objects() const
157{
158 return children;
159}
160

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

213
214sc_core::sc_simcontext *
215Object::simcontext() const
216{
217 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
218 return nullptr;
219}
220
221EventsIt
222Object::addChildEvent(sc_core::sc_event *e)
223{
224 return events.emplace(events.end(), e);
225}
221
226
227void
228Object::delChildEvent(EventsIt it)
229{
230 std::swap(*it, events.back());
231 events.pop_back();
232}
233
234
222Objects topLevelObjects;
223Objects allObjects;
224
225const std::vector<sc_core::sc_object *> &
226getTopLevelScObjects()
227{
228 return topLevelObjects;
229}
230
231sc_core::sc_object *
232findObject(const char *name, const Objects &objects)
233{
234 ObjectsIt it = findObjectIn(allObjects, name);
235 return it == allObjects.end() ? nullptr : *it;
236}
237
238} // namespace sc_gem5
235Objects topLevelObjects;
236Objects allObjects;
237
238const std::vector<sc_core::sc_object *> &
239getTopLevelScObjects()
240{
241 return topLevelObjects;
242}
243
244sc_core::sc_object *
245findObject(const char *name, const Objects &objects)
246{
247 ObjectsIt it = findObjectIn(allObjects, name);
248 return it == allObjects.end() ? nullptr : *it;
249}
250
251} // namespace sc_gem5