SystemC 3.0.0
Accellera SystemC proof-of-concept library
sc_object.h
Go to the documentation of this file.
1/*****************************************************************************
2
3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4 more contributor license agreements. See the NOTICE file distributed
5 with this work for additional information regarding copyright ownership.
6 Accellera licenses this file to you under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with the
8 License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15 implied. See the License for the specific language governing
16 permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22 sc_object.h -- Abstract base class of all SystemC `simulation' objects.
23
24 Original Author: Stan Y. Liao, Synopsys, Inc.
25
26 CHANGE LOG AT THE END OF THE FILE
27 *****************************************************************************/
28
29
30#ifndef SC_OBJECT_H
31#define SC_OBJECT_H
32
34#include <iostream>
35
36#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
37#pragma warning(push)
38#pragma warning(disable: 4251) // DLL import for std::string,vector
39#endif
40
41namespace sc_core {
42
43class SC_API sc_event;
45class sc_name_gen;
48class sc_phase_callback_registry;
49class sc_runnable;
53
54SC_API const char* sc_gen_unique_name( const char*, bool preserve_first );
55
56// ----------------------------------------------------------------------------
57// CLASS : sc_hierarchy_scope
58//
59// Scoped manipulation of the current SystemC object hierarchy
60// ----------------------------------------------------------------------------
61
63{
64 friend class sc_object;
65 friend class sc_object_host;
66 friend class sc_module;
67
68 struct root_tag {};
69 struct kernel_tag {};
70
71 [[nodiscard]] sc_hierarchy_scope move()
72 { return std::move(*this); }
73
74 sc_hierarchy_scope(kernel_tag, sc_object*);
75 sc_hierarchy_scope(kernel_tag, sc_object_host*);
76public:
77 ~sc_hierarchy_scope() noexcept(false);
78
79 // get root scope
80 static sc_hierarchy_scope get_root() { return sc_hierarchy_scope(sc_core::sc_hierarchy_scope::root); }
81
83
84private:
85 // disabled copying and assignment
86 sc_hierarchy_scope(const sc_hierarchy_scope&) /* = delete */;
87 sc_hierarchy_scope& operator=(const sc_hierarchy_scope&) /* = delete */;
88 // disabled dynamic allocation
89 void* operator new(std::size_t) /* = delete */;
90 void* operator new[](std::size_t) /* = delete */;
91
92 static const root_tag root;
93 sc_hierarchy_scope( root_tag );
94
95private:
96 sc_simcontext* m_simc;
97 sc_object_host* m_scoped_top;
98}; // class sc_hierarchy_scope
99
100// ----------------------------------------------------------------------------
101// CLASS : sc_object
102//
103// Abstract base class of all SystemC `simulation' objects.
104// ----------------------------------------------------------------------------
105
107{
108 friend class sc_event;
109 friend class sc_invoke_method;
110 friend class sc_module;
111 friend class sc_object_host;
112 friend class sc_object_manager;
113 friend class sc_phase_callback_registry;
114 friend class sc_process_b;
115 friend class sc_runnable;
116 friend class sc_simcontext;
117 friend class sc_trace_file_base;
118
120
121public:
122 const char* name() const
123 { return m_name.c_str(); }
124
125 const char* basename() const;
126
127 virtual void print(::std::ostream& os=::std::cout ) const;
128
129 // dump() is more detailed than print()
130 virtual void dump(::std::ostream& os=::std::cout ) const;
131
132 virtual void trace( sc_trace_file* tf ) const;
133
134 virtual const char* kind() const { return "sc_object"; }
135
137 { return m_simc; }
138
139 // add attribute
141
142 // get attribute by name
143 sc_attr_base* get_attribute( const std::string& name_ );
144 const sc_attr_base* get_attribute( const std::string& name_ ) const;
145
146 // remove attribute by name
147 sc_attr_base* remove_attribute( const std::string& name_ );
148
149 // remove all attributes
151
152 // get the number of attributes
153 int num_attributes() const;
154
155 // get the attribute collection
157 const sc_attr_cltn& attr_cltn() const;
158
159 virtual const std::vector<sc_event*>& get_child_events() const;
160 virtual const std::vector<sc_object*>& get_child_objects() const;
161
163 sc_object* get_parent_object() const;
164
165 virtual ~sc_object();
166
167protected:
169 sc_object(const char* nm);
170
172 sc_object& operator=( const sc_object& );
173
174 // restore SystemC hierarchy to current object's hierarchical scope
175 [[nodiscard]] virtual hierarchy_scope get_hierarchy_scope();
176
177private:
178 void detach();
179 void sc_object_init(const char* nm);
180
181private:
182
183 /* Each simulation object is associated with a simulation context */
184 mutable sc_attr_cltn* m_attr_cltn_p; // attributes for this object.
185 std::string m_name; // name of this object.
186 sc_object_host* m_parent; // parent for this object.
187 sc_simcontext* m_simc; // simcontext ptr / empty indicator
188};
189
190inline sc_object&
192{
193 // deliberately do nothing
194 return *this;
195}
196
197// ----------------------------------------------------------------------------
198// CLASS : sc_object_host
199//
200// Abstract (implementation-defined) base class of all SystemC objects, that
201// can hold child objects/events (i.e. _modules and processes)
202// ----------------------------------------------------------------------------
203
205{
206 friend class sc_event;
207 friend class sc_module;
208 friend class sc_object;
209 friend class sc_process_b;
210 friend SC_API const char* sc_gen_unique_name( const char*, bool preserve_first );
211protected:
213 sc_object_host(const char* nm);
215
216public:
217 virtual const std::vector<sc_event*>& get_child_events() const
218 { return m_child_events; }
219
220 virtual const std::vector<sc_object*>& get_child_objects() const
221 { return m_child_objects; }
222
223protected:
224 // restore SystemC hierarchy to current object's hierarchical scope
225 [[nodiscard]] virtual hierarchy_scope get_hierarchy_scope();
226
227private:
228 virtual void add_child_event( sc_event* event_p );
229 virtual void add_child_object( sc_object* object_p );
230 virtual bool remove_child_event( sc_event* event_p );
231 virtual bool remove_child_object( sc_object* object_p );
232
233 void orphan_child_events();
234 void orphan_child_objects();
235
236 const char* gen_unique_name( const char* basename_, bool preserve_first );
237
238private:
239 // disabled copying and assignment
240 sc_object_host(const sc_object_host&) /*= delete*/;
241 sc_object_host& operator=(const sc_object_host&) /*= delete*/;
242
243private:
244 std::vector<sc_event*> m_child_events; // list of child events.
245 std::vector<sc_object*> m_child_objects; // list of child objects.
246 sc_name_gen* m_name_gen_p; // sub-object name generator
247};
248
249// ----------------------------------------------------------------------------
250
251extern const char SC_HIERARCHY_CHAR;
252extern bool sc_enable_name_checking;
253
254inline sc_object*
256{
257 return m_parent;
258}
259
260inline sc_object*
262{
263 return obj_p->get_parent_object();
264}
265
266} // namespace sc_core
267
268#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
269#pragma warning(pop)
270#endif
271
272/*****************************************************************************
273
274 MODIFICATION LOG - modifiers, enter your name, affiliation, date and
275 changes you are making here.
276
277 Name, Affiliation, Date: Andy Goodrich, Forte Design Systems
278 5 September 2003
279 Description of Modification: - Made creation of attributes structure
280 conditional on its being used. This eliminates
281 100 bytes of storage for each normal sc_object.
282
283 *****************************************************************************/
284
285// $Log: sc_object.h,v $
286// Revision 1.13 2011/08/29 18:04:32 acg
287// Philipp A. Hartmann: miscellaneous clean ups.
288//
289// Revision 1.12 2011/08/26 20:46:10 acg
290// Andy Goodrich: moved the modification log to the end of the file to
291// eliminate source line number skew when check-ins are done.
292//
293// Revision 1.11 2011/03/06 15:55:11 acg
294// Andy Goodrich: Changes for named events.
295//
296// Revision 1.10 2011/03/05 19:44:20 acg
297// Andy Goodrich: changes for object and event naming and structures.
298//
299// Revision 1.9 2011/03/05 01:39:21 acg
300// Andy Goodrich: changes for named events.
301//
302// Revision 1.8 2011/02/18 20:27:14 acg
303// Andy Goodrich: Updated Copyrights.
304//
305// Revision 1.7 2011/02/13 21:47:37 acg
306// Andy Goodrich: update copyright notice.
307//
308// Revision 1.6 2011/01/25 20:50:37 acg
309// Andy Goodrich: changes for IEEE 1666 2011.
310//
311// Revision 1.5 2011/01/18 20:10:44 acg
312// Andy Goodrich: changes for IEEE1666_2011 semantics.
313//
314// Revision 1.4 2010/07/22 20:02:33 acg
315// Andy Goodrich: bug fixes.
316//
317// Revision 1.3 2009/02/28 00:26:58 acg
318// Andy Goodrich: changed boost name space to sc_boost to allow use with
319// full boost library applications.
320//
321// Revision 1.2 2008/05/22 17:06:26 acg
322// Andy Goodrich: updated copyright notice to include 2008.
323//
324// Revision 1.1.1.1 2006/12/15 20:20:05 acg
325// SystemC 2.3
326//
327// Revision 1.5 2006/04/20 17:08:17 acg
328// Andy Goodrich: 3.0 style process changes.
329//
330// Revision 1.4 2006/04/11 23:13:21 acg
331// Andy Goodrich: Changes for reduced reset support that only includes
332// sc_cthread, but has preliminary hooks for expanding to method and thread
333// processes also.
334//
335// Revision 1.3 2006/01/13 18:44:30 acg
336// Added $Log to record CVS changes into the source.
337
338#endif // SC_OBJECT_H
#define SC_API
Definition: sc_cmnhdr.h:148
sc_object * sc_get_parent(const sc_object *obj_p)
Definition: sc_object.h:261
class SC_API sc_event
Definition: sc_interface.h:36
SC_API const char * sc_gen_unique_name(const char *, bool preserve_first)
class SC_API sc_object
Definition: sc_object.h:46
const char SC_HIERARCHY_CHAR
bool sc_enable_name_checking
class SC_API sc_object_host
Definition: sc_object.h:47
~sc_hierarchy_scope() noexcept(false)
sc_hierarchy_scope(sc_hierarchy_scope &&)
sc_object * get_parent() const
virtual const std::vector< sc_event * > & get_child_events() const
sc_object * get_parent_object() const
Definition: sc_object.h:255
sc_object & operator=(const sc_object &)
Definition: sc_object.h:191
virtual hierarchy_scope get_hierarchy_scope()
sc_object(const sc_object &)
const char * name() const
Definition: sc_object.h:122
const char * basename() const
int num_attributes() const
virtual ~sc_object()
bool add_attribute(sc_attr_base &)
const sc_attr_base * get_attribute(const std::string &name_) const
sc_simcontext * simcontext() const
Definition: sc_object.h:136
virtual void print(::std::ostream &os=::std::cout) const
void remove_all_attributes()
virtual void trace(sc_trace_file *tf) const
sc_attr_base * get_attribute(const std::string &name_)
sc_attr_base * remove_attribute(const std::string &name_)
sc_attr_cltn & attr_cltn()
sc_object(const char *nm)
const sc_attr_cltn & attr_cltn() const
virtual void dump(::std::ostream &os=::std::cout) const
virtual const std::vector< sc_object * > & get_child_objects() const
virtual const char * kind() const
Definition: sc_object.h:134
friend SC_API const char * sc_gen_unique_name(const char *, bool preserve_first)
virtual hierarchy_scope get_hierarchy_scope()
virtual const std::vector< sc_object * > & get_child_objects() const
Definition: sc_object.h:220
virtual const std::vector< sc_event * > & get_child_events() const
Definition: sc_object.h:217