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_module_name.h -- An object used to help manage object names 00021 and hierarchy. 00022 00023 Original Author: Stan Y. Liao, Synopsys, Inc. 00024 00025 CHANGE LOG AT THE END OF THE FILE 00026 *****************************************************************************/ 00027 00028 // $Log: sc_module_name.h,v $ 00029 // Revision 1.5 2011/08/26 20:46:10 acg 00030 // Andy Goodrich: moved the modification log to the end of the file to 00031 // eliminate source line number skew when check-ins are done. 00032 // 00033 00034 #ifndef SC_MODULE_NAME_H 00035 #define SC_MODULE_NAME_H 00036 00037 00038 namespace sc_core { 00039 00040 class sc_module; 00041 class sc_simcontext; 00042 00043 00044 /**************************************************************************/ 00050 class sc_module_name 00051 { 00052 friend class sc_module; 00053 00054 // 04/07/2015 GL: a new sc_channel class is derived from sc_module 00055 friend class sc_channel; 00056 00057 friend class sc_object_manager; 00058 00059 public: 00060 00061 sc_module_name( const char* ); 00062 sc_module_name( const sc_module_name& ); 00063 00064 ~sc_module_name(); 00065 00066 operator const char*() const; 00067 00068 protected: 00069 inline void clear_module( sc_module* module_p ); 00070 inline void set_module( sc_module* module_p ); 00071 00072 private: 00073 00074 const char* m_name; 00075 sc_module* m_module_p; 00076 sc_module_name* m_next; 00077 sc_simcontext* m_simc; 00078 bool m_pushed; 00079 00080 private: 00081 00082 // disabled 00083 sc_module_name(); 00084 sc_module_name& operator = ( const sc_module_name& ); 00085 }; 00086 00087 inline void sc_module_name::clear_module( sc_module* module_p ) 00088 { 00089 assert( m_module_p == module_p ); 00090 m_module_p = 0; 00091 } 00092 00093 inline void sc_module_name::set_module( sc_module* module_p ) 00094 { 00095 m_module_p = module_p; 00096 } 00097 00098 } // namespace sc_core 00099 00100 // Revision 1.4 2011/02/18 20:27:14 acg 00101 // Andy Goodrich: Updated Copyrights. 00102 // 00103 // Revision 1.3 2011/02/13 21:47:37 acg 00104 // Andy Goodrich: update copyright notice. 00105 // 00106 // Revision 1.2 2008/05/22 17:06:26 acg 00107 // Andy Goodrich: updated copyright notice to include 2008. 00108 // 00109 // Revision 1.1.1.1 2006/12/15 20:20:05 acg 00110 // SystemC 2.3 00111 // 00112 // Revision 1.4 2006/03/14 23:56:58 acg 00113 // Andy Goodrich: This fixes a bug when an exception is thrown in 00114 // sc_module::sc_module() for a dynamically allocated sc_module 00115 // object. We are calling sc_module::end_module() on a module that has 00116 // already been deleted. The scenario runs like this: 00117 // 00118 // a) the sc_module constructor is entered 00119 // b) the exception is thrown 00120 // c) the exception processor deletes the storage for the sc_module 00121 // d) the stack is unrolled causing the sc_module_name instance to be deleted 00122 // e) ~sc_module_name() calls end_module() with its pointer to the sc_module 00123 // f) because the sc_module has been deleted its storage is corrupted, 00124 // either by linking it to a free space chain, or by reuse of some sort 00125 // g) the m_simc field is garbage 00126 // h) the m_object_manager field is also garbage 00127 // i) an exception occurs 00128 // 00129 // This does not happen for automatic sc_module instances since the 00130 // storage for the module is not reclaimed its just part of the stack. 00131 // 00132 // I am fixing this by having the destructor for sc_module clear the 00133 // module pointer in its sc_module_name instance. That cuts things at 00134 // step (e) above, since the pointer will be null if the module has 00135 // already been deleted. To make sure the module stack is okay, I call 00136 // end-module() in ~sc_module in the case where there is an 00137 // sc_module_name pointer lying around. 00138 // 00139 // Revision 1.3 2006/01/13 18:44:30 acg 00140 // Added $Log to record CVS changes into the source. 00141 00142 #endif