sc_object.h revision 12027
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 33 34#include "sysc/utils/sc_iostream.h" 35#include "sysc/kernel/sc_attribute.h" 36 37namespace sc_core { 38 39class sc_event; 40class sc_module; 41class sc_phase_callback_registry; 42class sc_runnable; 43class sc_simcontext; 44class sc_trace_file; 45class sc_trace_file_base; 46 47// ---------------------------------------------------------------------------- 48// CLASS : sc_object 49// 50// Abstract base class of all SystemC `simulation' objects. 51// ---------------------------------------------------------------------------- 52 53class sc_object 54{ 55 friend class sc_event; 56 friend class sc_module; 57 friend struct sc_invoke_method; 58 friend class sc_module_dynalloc_list; 59 friend class sc_object_manager; 60 friend class sc_phase_callback_registry; 61 friend class sc_process_b; 62 friend class sc_runnable; 63 friend class sc_simcontext; 64 friend class sc_trace_file_base; 65 66public: 67 typedef unsigned phase_cb_mask; 68 69 const char* name() const 70 { return m_name.c_str(); } 71 72 const char* basename() const; 73 74 virtual void print(::std::ostream& os=::std::cout ) const; 75 76 // dump() is more detailed than print() 77 virtual void dump(::std::ostream& os=::std::cout ) const; 78 79 virtual void trace( sc_trace_file* tf ) const; 80 81 virtual const char* kind() const { return "sc_object"; } 82 83 sc_simcontext* simcontext() const 84 { return m_simc; } 85 86 // add attribute 87 bool add_attribute( sc_attr_base& ); 88 89 // get attribute by name 90 sc_attr_base* get_attribute( const std::string& name_ ); 91 const sc_attr_base* get_attribute( const std::string& name_ ) const; 92 93 // remove attribute by name 94 sc_attr_base* remove_attribute( const std::string& name_ ); 95 96 // remove all attributes 97 void remove_all_attributes(); 98 99 // get the number of attributes 100 int num_attributes() const; 101 102 // get the attribute collection 103 sc_attr_cltn& attr_cltn(); 104 const sc_attr_cltn& attr_cltn() const; 105 106 virtual const std::vector<sc_event*>& get_child_events() const 107 { return m_child_events; } 108 109 virtual const std::vector<sc_object*>& get_child_objects() const 110 { return m_child_objects; } 111 112 sc_object* get_parent() const; 113 sc_object* get_parent_object() const { return m_parent; } 114 115protected: 116 117 sc_object(); 118 sc_object(const char* nm); 119 120 sc_object( const sc_object& ); 121 sc_object& operator=( const sc_object& ); 122 123 124 virtual ~sc_object(); 125 126 virtual void add_child_event( sc_event* event_p ); 127 virtual void add_child_object( sc_object* object_p ); 128 virtual bool remove_child_event( sc_event* event_p ); 129 virtual bool remove_child_object( sc_object* object_p ); 130 131 phase_cb_mask register_simulation_phase_callback( phase_cb_mask ); 132 phase_cb_mask unregister_simulation_phase_callback( phase_cb_mask ); 133 134 class hierarchy_scope; 135 136private: 137 void do_simulation_phase_callback(); 138 virtual void simulation_phase_callback(); 139 140 void detach(); 141 virtual void orphan_child_events(); 142 virtual void orphan_child_objects(); 143 void sc_object_init(const char* nm); 144 145private: 146 147 /* Each simulation object is associated with a simulation context */ 148 mutable sc_attr_cltn* m_attr_cltn_p; // attributes for this object. 149 std::vector<sc_event*> m_child_events; // list of child events. 150 std::vector<sc_object*> m_child_objects; // list of child objects. 151 std::string m_name; // name of this object. 152 sc_object* m_parent; // parent for this object. 153 sc_simcontext* m_simc; // simcontext ptr / empty indicator 154}; 155 156inline 157sc_object& 158sc_object::operator=( sc_object const & ) 159{ 160 // deliberately do nothing 161 return *this; 162} 163 164// ---------------------------------------------------------------------------- 165 166extern const char SC_HIERARCHY_CHAR; 167extern bool sc_enable_name_checking; 168 169 170inline 171sc_object* sc_get_parent( const sc_object* obj_p ) 172{ 173 return obj_p->get_parent_object(); 174} 175 176} // namespace sc_core 177 178/***************************************************************************** 179 180 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 181 changes you are making here. 182 183 Name, Affiliation, Date: Andy Goodrich, Forte Design Systems 184 5 September 2003 185 Description of Modification: - Made creation of attributes structure 186 conditional on its being used. This eliminates 187 100 bytes of storage for each normal sc_object. 188 189 *****************************************************************************/ 190 191// $Log: sc_object.h,v $ 192// Revision 1.13 2011/08/29 18:04:32 acg 193// Philipp A. Hartmann: miscellaneous clean ups. 194// 195// Revision 1.12 2011/08/26 20:46:10 acg 196// Andy Goodrich: moved the modification log to the end of the file to 197// eliminate source line number skew when check-ins are done. 198// 199// Revision 1.11 2011/03/06 15:55:11 acg 200// Andy Goodrich: Changes for named events. 201// 202// Revision 1.10 2011/03/05 19:44:20 acg 203// Andy Goodrich: changes for object and event naming and structures. 204// 205// Revision 1.9 2011/03/05 01:39:21 acg 206// Andy Goodrich: changes for named events. 207// 208// Revision 1.8 2011/02/18 20:27:14 acg 209// Andy Goodrich: Updated Copyrights. 210// 211// Revision 1.7 2011/02/13 21:47:37 acg 212// Andy Goodrich: update copyright notice. 213// 214// Revision 1.6 2011/01/25 20:50:37 acg 215// Andy Goodrich: changes for IEEE 1666 2011. 216// 217// Revision 1.5 2011/01/18 20:10:44 acg 218// Andy Goodrich: changes for IEEE1666_2011 semantics. 219// 220// Revision 1.4 2010/07/22 20:02:33 acg 221// Andy Goodrich: bug fixes. 222// 223// Revision 1.3 2009/02/28 00:26:58 acg 224// Andy Goodrich: changed boost name space to sc_boost to allow use with 225// full boost library applications. 226// 227// Revision 1.2 2008/05/22 17:06:26 acg 228// Andy Goodrich: updated copyright notice to include 2008. 229// 230// Revision 1.1.1.1 2006/12/15 20:20:05 acg 231// SystemC 2.3 232// 233// Revision 1.5 2006/04/20 17:08:17 acg 234// Andy Goodrich: 3.0 style process changes. 235// 236// Revision 1.4 2006/04/11 23:13:21 acg 237// Andy Goodrich: Changes for reduced reset support that only includes 238// sc_cthread, but has preliminary hooks for expanding to method and thread 239// processes also. 240// 241// Revision 1.3 2006/01/13 18:44:30 acg 242// Added $Log to record CVS changes into the source. 243 244#endif // SC_OBJECT_H 245