112027Sjungma@eit.uni-kl.de/*****************************************************************************
212027Sjungma@eit.uni-kl.de
312027Sjungma@eit.uni-kl.de  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412027Sjungma@eit.uni-kl.de  more contributor license agreements.  See the NOTICE file distributed
512027Sjungma@eit.uni-kl.de  with this work for additional information regarding copyright ownership.
612027Sjungma@eit.uni-kl.de  Accellera licenses this file to you under the Apache License, Version 2.0
712027Sjungma@eit.uni-kl.de  (the "License"); you may not use this file except in compliance with the
812027Sjungma@eit.uni-kl.de  License.  You may obtain a copy of the License at
912027Sjungma@eit.uni-kl.de
1012027Sjungma@eit.uni-kl.de    http://www.apache.org/licenses/LICENSE-2.0
1112027Sjungma@eit.uni-kl.de
1212027Sjungma@eit.uni-kl.de  Unless required by applicable law or agreed to in writing, software
1312027Sjungma@eit.uni-kl.de  distributed under the License is distributed on an "AS IS" BASIS,
1412027Sjungma@eit.uni-kl.de  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512027Sjungma@eit.uni-kl.de  implied.  See the License for the specific language governing
1612027Sjungma@eit.uni-kl.de  permissions and limitations under the License.
1712027Sjungma@eit.uni-kl.de
1812027Sjungma@eit.uni-kl.de *****************************************************************************/
1912027Sjungma@eit.uni-kl.de
2012027Sjungma@eit.uni-kl.de/*****************************************************************************
2112027Sjungma@eit.uni-kl.de
2212027Sjungma@eit.uni-kl.de  sc_module_name.h -- An object used to help manage object names
2312027Sjungma@eit.uni-kl.de                      and hierarchy.
2412027Sjungma@eit.uni-kl.de
2512027Sjungma@eit.uni-kl.de  Original Author: Stan Y. Liao, Synopsys, Inc.
2612027Sjungma@eit.uni-kl.de
2712027Sjungma@eit.uni-kl.de  CHANGE LOG AT THE END OF THE FILE
2812027Sjungma@eit.uni-kl.de *****************************************************************************/
2912027Sjungma@eit.uni-kl.de
3012027Sjungma@eit.uni-kl.de// $Log: sc_module_name.h,v $
3112027Sjungma@eit.uni-kl.de// Revision 1.5  2011/08/26 20:46:10  acg
3212027Sjungma@eit.uni-kl.de//  Andy Goodrich: moved the modification log to the end of the file to
3312027Sjungma@eit.uni-kl.de//  eliminate source line number skew when check-ins are done.
3412027Sjungma@eit.uni-kl.de//
3512027Sjungma@eit.uni-kl.de
3612027Sjungma@eit.uni-kl.de#ifndef SC_MODULE_NAME_H
3712027Sjungma@eit.uni-kl.de#define SC_MODULE_NAME_H
3812027Sjungma@eit.uni-kl.de
3912027Sjungma@eit.uni-kl.de
4012027Sjungma@eit.uni-kl.denamespace sc_core {
4112027Sjungma@eit.uni-kl.de
4212027Sjungma@eit.uni-kl.declass sc_module;
4312027Sjungma@eit.uni-kl.declass sc_simcontext;
4412027Sjungma@eit.uni-kl.de
4512027Sjungma@eit.uni-kl.de
4612027Sjungma@eit.uni-kl.de// ----------------------------------------------------------------------------
4712027Sjungma@eit.uni-kl.de//  CLASS : sc_module_name
4812027Sjungma@eit.uni-kl.de//
4912027Sjungma@eit.uni-kl.de//  Module name class.
5012027Sjungma@eit.uni-kl.de// ----------------------------------------------------------------------------
5112027Sjungma@eit.uni-kl.de
5212027Sjungma@eit.uni-kl.declass sc_module_name
5312027Sjungma@eit.uni-kl.de{
5412027Sjungma@eit.uni-kl.de    friend class sc_module;
5512027Sjungma@eit.uni-kl.de    friend class sc_object_manager;
5612027Sjungma@eit.uni-kl.de
5712027Sjungma@eit.uni-kl.depublic:
5812027Sjungma@eit.uni-kl.de
5912027Sjungma@eit.uni-kl.de    sc_module_name( const char* );
6012027Sjungma@eit.uni-kl.de    sc_module_name( const sc_module_name& );
6112027Sjungma@eit.uni-kl.de
6212027Sjungma@eit.uni-kl.de    ~sc_module_name();
6312027Sjungma@eit.uni-kl.de
6412027Sjungma@eit.uni-kl.de    operator const char*() const;
6512027Sjungma@eit.uni-kl.de
6612027Sjungma@eit.uni-kl.deprotected:
6712027Sjungma@eit.uni-kl.de    inline void clear_module( sc_module* module_p );
6812027Sjungma@eit.uni-kl.de    inline void set_module( sc_module* module_p );
6912027Sjungma@eit.uni-kl.de
7012027Sjungma@eit.uni-kl.deprivate:
7112027Sjungma@eit.uni-kl.de
7212027Sjungma@eit.uni-kl.de    const char*     m_name;
7312027Sjungma@eit.uni-kl.de    sc_module*      m_module_p;
7412027Sjungma@eit.uni-kl.de    sc_module_name* m_next;
7512027Sjungma@eit.uni-kl.de    sc_simcontext*  m_simc;
7612027Sjungma@eit.uni-kl.de    bool            m_pushed;
7712027Sjungma@eit.uni-kl.de
7812027Sjungma@eit.uni-kl.deprivate:
7912027Sjungma@eit.uni-kl.de
8012027Sjungma@eit.uni-kl.de    // disabled
8112027Sjungma@eit.uni-kl.de    sc_module_name();
8212027Sjungma@eit.uni-kl.de    sc_module_name& operator = ( const sc_module_name& );
8312027Sjungma@eit.uni-kl.de};
8412027Sjungma@eit.uni-kl.de
8512027Sjungma@eit.uni-kl.deinline void sc_module_name::clear_module( sc_module* module_p )
8612027Sjungma@eit.uni-kl.de{
8712027Sjungma@eit.uni-kl.de    assert( m_module_p == module_p );
8812027Sjungma@eit.uni-kl.de    m_module_p = 0;
8912027Sjungma@eit.uni-kl.de}
9012027Sjungma@eit.uni-kl.de
9112027Sjungma@eit.uni-kl.deinline void sc_module_name::set_module( sc_module* module_p )
9212027Sjungma@eit.uni-kl.de{
9312027Sjungma@eit.uni-kl.de    m_module_p = module_p;
9412027Sjungma@eit.uni-kl.de}
9512027Sjungma@eit.uni-kl.de
9612027Sjungma@eit.uni-kl.de} // namespace sc_core
9712027Sjungma@eit.uni-kl.de
9812027Sjungma@eit.uni-kl.de// Revision 1.4  2011/02/18 20:27:14  acg
9912027Sjungma@eit.uni-kl.de//  Andy Goodrich: Updated Copyrights.
10012027Sjungma@eit.uni-kl.de//
10112027Sjungma@eit.uni-kl.de// Revision 1.3  2011/02/13 21:47:37  acg
10212027Sjungma@eit.uni-kl.de//  Andy Goodrich: update copyright notice.
10312027Sjungma@eit.uni-kl.de//
10412027Sjungma@eit.uni-kl.de// Revision 1.2  2008/05/22 17:06:26  acg
10512027Sjungma@eit.uni-kl.de//  Andy Goodrich: updated copyright notice to include 2008.
10612027Sjungma@eit.uni-kl.de//
10712027Sjungma@eit.uni-kl.de// Revision 1.1.1.1  2006/12/15 20:20:05  acg
10812027Sjungma@eit.uni-kl.de// SystemC 2.3
10912027Sjungma@eit.uni-kl.de//
11012027Sjungma@eit.uni-kl.de// Revision 1.4  2006/03/14 23:56:58  acg
11112027Sjungma@eit.uni-kl.de//   Andy Goodrich: This fixes a bug when an exception is thrown in
11212027Sjungma@eit.uni-kl.de//   sc_module::sc_module() for a dynamically allocated sc_module
11312027Sjungma@eit.uni-kl.de//   object. We are calling sc_module::end_module() on a module that has
11412027Sjungma@eit.uni-kl.de//   already been deleted. The scenario runs like this:
11512027Sjungma@eit.uni-kl.de//
11612027Sjungma@eit.uni-kl.de//   a) the sc_module constructor is entered
11712027Sjungma@eit.uni-kl.de//   b) the exception is thrown
11812027Sjungma@eit.uni-kl.de//   c) the exception processor deletes the storage for the sc_module
11912027Sjungma@eit.uni-kl.de//   d) the stack is unrolled causing the sc_module_name instance to be deleted
12012027Sjungma@eit.uni-kl.de//   e) ~sc_module_name() calls end_module() with its pointer to the sc_module
12112027Sjungma@eit.uni-kl.de//   f) because the sc_module has been deleted its storage is corrupted,
12212027Sjungma@eit.uni-kl.de//      either by linking it to a free space chain, or by reuse of some sort
12312027Sjungma@eit.uni-kl.de//   g) the m_simc field is garbage
12412027Sjungma@eit.uni-kl.de//   h) the m_object_manager field is also garbage
12512027Sjungma@eit.uni-kl.de//   i) an exception occurs
12612027Sjungma@eit.uni-kl.de//
12712027Sjungma@eit.uni-kl.de//   This does not happen for automatic sc_module instances since the
12812027Sjungma@eit.uni-kl.de//   storage for the module is not reclaimed its just part of the stack.
12912027Sjungma@eit.uni-kl.de//
13012027Sjungma@eit.uni-kl.de//   I am fixing this by having the destructor for sc_module clear the
13112027Sjungma@eit.uni-kl.de//   module pointer in its sc_module_name instance. That cuts things at
13212027Sjungma@eit.uni-kl.de//   step (e) above, since the pointer will be null if the module has
13312027Sjungma@eit.uni-kl.de//   already been deleted. To make sure the module stack is okay, I call
13412027Sjungma@eit.uni-kl.de//   end-module() in ~sc_module in the case where there is an
13512027Sjungma@eit.uni-kl.de//   sc_module_name pointer lying around.
13612027Sjungma@eit.uni-kl.de//
13712027Sjungma@eit.uni-kl.de// Revision 1.3  2006/01/13 18:44:30  acg
13812027Sjungma@eit.uni-kl.de// Added $Log to record CVS changes into the source.
13912027Sjungma@eit.uni-kl.de
14012027Sjungma@eit.uni-kl.de#endif
141