00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2014 by all Contributors. 00005 All Rights reserved. 00006 00007 The contents of this file are subject to the restrictions and limitations 00008 set forth in the SystemC Open Source License (the "License"); 00009 You may not use this file except in compliance with such restrictions and 00010 limitations. You may obtain instructions on how to receive a copy of the 00011 License at http://www.accellera.org/. Software distributed by Contributors 00012 under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF 00013 ANY KIND, either express or implied. See the License for the specific 00014 language governing rights and limitations under the License. 00015 00016 *****************************************************************************/ 00017 00018 /***************************************************************************** 00019 00020 sc_object.h -- Abstract base class of all SystemC `simulation' objects. 00021 00022 Original Author: Stan Y. Liao, Synopsys, Inc. 00023 00024 CHANGE LOG AT THE END OF THE FILE 00025 *****************************************************************************/ 00026 00027 00028 #ifndef SC_OBJECT_H 00029 #define SC_OBJECT_H 00030 00031 00032 #include "sysc/utils/sc_iostream.h" 00033 #include "sysc/kernel/sc_attribute.h" 00034 00035 namespace sc_core { 00036 00037 class sc_event; 00038 class sc_module; 00039 class sc_phase_callback_registry; 00040 class sc_runnable; 00041 class sc_simcontext; 00042 class sc_trace_file; 00043 class sc_trace_file_base; 00044 00045 /**************************************************************************/ 00051 class sc_object 00052 { 00053 friend class sc_event; 00054 friend class sc_module; 00055 00056 // 04/07/2015 GL: a new sc_channel class is derived from sc_module 00057 friend class sc_channel; 00058 00059 friend struct sc_invoke_method; 00060 friend class sc_module_dynalloc_list; 00061 friend class sc_object_manager; 00062 friend class sc_phase_callback_registry; 00063 friend class sc_process_b; 00064 friend class sc_runnable; 00065 friend class sc_simcontext; 00066 friend class sc_trace_file_base; 00067 00068 public: 00069 typedef unsigned phase_cb_mask; 00070 00071 const char* name() const 00072 { return m_name.c_str(); } 00073 00074 const char* basename() const; 00075 00076 virtual void print(::std::ostream& os=::std::cout ) const; 00077 00078 // dump() is more detailed than print() 00079 virtual void dump(::std::ostream& os=::std::cout ) const; 00080 00081 virtual void trace( sc_trace_file* tf ) const; 00082 00083 virtual const char* kind() const { return "sc_object"; } 00084 00085 sc_simcontext* simcontext() const 00086 { return m_simc; } 00087 00088 // add attribute 00089 bool add_attribute( sc_attr_base& ); 00090 00091 // get attribute by name 00092 sc_attr_base* get_attribute( const std::string& name_ ); 00093 const sc_attr_base* get_attribute( const std::string& name_ ) const; 00094 00095 // remove attribute by name 00096 sc_attr_base* remove_attribute( const std::string& name_ ); 00097 00098 // remove all attributes 00099 void remove_all_attributes(); 00100 00101 // get the number of attributes 00102 int num_attributes() const; 00103 00104 // get the attribute collection 00105 sc_attr_cltn& attr_cltn(); 00106 const sc_attr_cltn& attr_cltn() const; 00107 00108 virtual const std::vector<sc_event*>& get_child_events() const 00109 { return m_child_events; } 00110 00111 virtual const std::vector<sc_object*>& get_child_objects() const 00112 { return m_child_objects; } 00113 00114 sc_object* get_parent() const; 00115 sc_object* get_parent_object() const { return m_parent; } 00116 00117 protected: 00118 00119 sc_object(); 00120 sc_object(const char* nm); 00121 00122 sc_object( const sc_object& ); 00123 sc_object& operator=( const sc_object& ); 00124 00125 00126 virtual ~sc_object(); 00127 00128 virtual void add_child_event( sc_event* event_p ); 00129 virtual void add_child_object( sc_object* object_p ); 00130 virtual bool remove_child_event( sc_event* event_p ); 00131 virtual bool remove_child_object( sc_object* object_p ); 00132 00133 phase_cb_mask register_simulation_phase_callback( phase_cb_mask ); 00134 phase_cb_mask unregister_simulation_phase_callback( phase_cb_mask ); 00135 00136 class hierarchy_scope; 00137 00138 private: 00139 void do_simulation_phase_callback(); 00140 virtual void simulation_phase_callback(); 00141 00142 void detach(); 00143 virtual void orphan_child_events(); 00144 virtual void orphan_child_objects(); 00145 void sc_object_init(const char* nm); 00146 00147 private: 00148 00149 /* Each simulation object is associated with a simulation context */ 00150 mutable sc_attr_cltn* m_attr_cltn_p; // attributes for this object. 00151 std::vector<sc_event*> m_child_events; // list of child events. 00152 std::vector<sc_object*> m_child_objects; // list of child objects. 00153 std::string m_name; // name of this object. 00154 sc_object* m_parent; // parent for this object. 00155 sc_simcontext* m_simc; // simcontext ptr / empty indicator 00156 }; 00157 00158 inline 00159 sc_object& 00160 sc_object::operator=( sc_object const & ) 00161 { 00162 // deliberately do nothing 00163 return *this; 00164 } 00165 00166 // ---------------------------------------------------------------------------- 00167 00168 extern const char SC_HIERARCHY_CHAR; 00169 extern bool sc_enable_name_checking; 00170 00171 00172 inline 00173 sc_object* sc_get_parent( const sc_object* obj_p ) 00174 { 00175 return obj_p->get_parent_object(); 00176 } 00177 00178 } // namespace sc_core 00179 00180 /***************************************************************************** 00181 00182 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 00183 changes you are making here. 00184 00185 Name, Affiliation, Date: Andy Goodrich, Forte Design Systems 00186 5 September 2003 00187 Description of Modification: - Made creation of attributes structure 00188 conditional on its being used. This eliminates 00189 100 bytes of storage for each normal sc_object. 00190 00191 *****************************************************************************/ 00192 00193 // $Log: sc_object.h,v $ 00194 // Revision 1.13 2011/08/29 18:04:32 acg 00195 // Philipp A. Hartmann: miscellaneous clean ups. 00196 // 00197 // Revision 1.12 2011/08/26 20:46:10 acg 00198 // Andy Goodrich: moved the modification log to the end of the file to 00199 // eliminate source line number skew when check-ins are done. 00200 // 00201 // Revision 1.11 2011/03/06 15:55:11 acg 00202 // Andy Goodrich: Changes for named events. 00203 // 00204 // Revision 1.10 2011/03/05 19:44:20 acg 00205 // Andy Goodrich: changes for object and event naming and structures. 00206 // 00207 // Revision 1.9 2011/03/05 01:39:21 acg 00208 // Andy Goodrich: changes for named events. 00209 // 00210 // Revision 1.8 2011/02/18 20:27:14 acg 00211 // Andy Goodrich: Updated Copyrights. 00212 // 00213 // Revision 1.7 2011/02/13 21:47:37 acg 00214 // Andy Goodrich: update copyright notice. 00215 // 00216 // Revision 1.6 2011/01/25 20:50:37 acg 00217 // Andy Goodrich: changes for IEEE 1666 2011. 00218 // 00219 // Revision 1.5 2011/01/18 20:10:44 acg 00220 // Andy Goodrich: changes for IEEE1666_2011 semantics. 00221 // 00222 // Revision 1.4 2010/07/22 20:02:33 acg 00223 // Andy Goodrich: bug fixes. 00224 // 00225 // Revision 1.3 2009/02/28 00:26:58 acg 00226 // Andy Goodrich: changed boost name space to sc_boost to allow use with 00227 // full boost library applications. 00228 // 00229 // Revision 1.2 2008/05/22 17:06:26 acg 00230 // Andy Goodrich: updated copyright notice to include 2008. 00231 // 00232 // Revision 1.1.1.1 2006/12/15 20:20:05 acg 00233 // SystemC 2.3 00234 // 00235 // Revision 1.5 2006/04/20 17:08:17 acg 00236 // Andy Goodrich: 3.0 style process changes. 00237 // 00238 // Revision 1.4 2006/04/11 23:13:21 acg 00239 // Andy Goodrich: Changes for reduced reset support that only includes 00240 // sc_cthread, but has preliminary hooks for expanding to method and thread 00241 // processes also. 00242 // 00243 // Revision 1.3 2006/01/13 18:44:30 acg 00244 // Added $Log to record CVS changes into the source. 00245 00246 #endif // SC_OBJECT_H