sc_module_name.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2006 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 Version 2.4 (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.systemc.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  *****************************************************************************/
00026 
00027 /*****************************************************************************
00028 
00029   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00030   changes you are making here.
00031 
00032       Name, Affiliation, Date:
00033   Description of Modification:
00034 
00035  *****************************************************************************/
00036 
00037 // $Log: sc_module_name.h,v $
00038 // Revision 1.1.1.1  2006/12/15 20:31:37  acg
00039 // SystemC 2.2
00040 //
00041 // Revision 1.4  2006/03/14 23:56:58  acg
00042 //   Andy Goodrich: This fixes a bug when an exception is thrown in
00043 //   sc_module::sc_module() for a dynamically allocated sc_module
00044 //   object. We are calling sc_module::end_module() on a module that has
00045 //   already been deleted. The scenario runs like this:
00046 //
00047 //   a) the sc_module constructor is entered
00048 //   b) the exception is thrown
00049 //   c) the exception processor deletes the storage for the sc_module
00050 //   d) the stack is unrolled causing the sc_module_name instance to be deleted
00051 //   e) ~sc_module_name() calls end_module() with its pointer to the sc_module
00052 //   f) because the sc_module has been deleted its storage is corrupted,
00053 //      either by linking it to a free space chain, or by reuse of some sort
00054 //   g) the m_simc field is garbage
00055 //   h) the m_object_manager field is also garbage
00056 //   i) an exception occurs
00057 //
00058 //   This does not happen for automatic sc_module instances since the
00059 //   storage for the module is not reclaimed its just part of the stack.
00060 //
00061 //   I am fixing this by having the destructor for sc_module clear the
00062 //   module pointer in its sc_module_name instance. That cuts things at
00063 //   step (e) above, since the pointer will be null if the module has
00064 //   already been deleted. To make sure the module stack is okay, I call
00065 //   end-module() in ~sc_module in the case where there is an
00066 //   sc_module_name pointer lying around.
00067 //
00068 // Revision 1.3  2006/01/13 18:44:30  acg
00069 // Added $Log to record CVS changes into the source.
00070 //
00071 
00072 #ifndef SC_MODULE_NAME_H
00073 #define SC_MODULE_NAME_H
00074 
00075 
00076 namespace sc_core {
00077 
00078 class sc_module;
00079 class sc_simcontext;
00080 
00081 
00082 // ----------------------------------------------------------------------------
00083 //  CLASS : sc_module_name
00084 //
00085 //  Module name class.
00086 // ----------------------------------------------------------------------------
00087 
00088 class sc_module_name
00089 {
00090     friend class sc_module;
00091     friend class sc_object_manager;
00092 
00093 public:
00094 
00095     sc_module_name( const char* );
00096     sc_module_name( const sc_module_name& );
00097 
00098     ~sc_module_name();
00099 
00100     operator const char*() const;
00101 
00102 protected:
00103     inline void clear_module( sc_module* module_p );
00104     inline void set_module( sc_module* module_p );
00105 
00106 private:
00107 
00108     const char*     m_name;
00109     sc_module*      m_module_p;
00110     sc_module_name* m_next;
00111     sc_simcontext*  m_simc;
00112     bool            m_pushed;
00113 
00114 private:
00115 
00116     // disabled
00117     sc_module_name();
00118     sc_module_name& operator = ( const sc_module_name& );
00119 };
00120 
00121 inline void sc_module_name::clear_module( sc_module* module_p )
00122 {
00123     assert( m_module_p == module_p );
00124     m_module_p = 0;
00125 }
00126 
00127 inline void sc_module_name::set_module( sc_module* module_p )
00128 {
00129     m_module_p = module_p;
00130 }
00131 
00132 } // namespace sc_core
00133 
00134 #endif

Generated on Wed Jan 21 15:32:09 2009 for SystemC by  doxygen 1.5.5