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_module_name.cpp -- An object used to help manage object names
23                        and hierarchy
24
25  Original Author: Stan Y. Liao, Synopsys, Inc.
26
27  CHANGE LOG AT THE END OF THE FILE
28 *****************************************************************************/
29
30#include <cstdlib>
31
32#include "sysc/kernel/sc_kernel_ids.h"
33#include "sysc/kernel/sc_module.h"
34#include "sysc/kernel/sc_module_name.h"
35#include "sysc/kernel/sc_object_manager.h"
36#include "sysc/kernel/sc_simcontext.h"
37#include "sysc/utils/sc_iostream.h"
38
39namespace sc_core {
40
41sc_module_name::sc_module_name( const char* name_ )
42: m_name( name_ ),
43  m_module_p( 0 ),
44  m_next( 0 ),
45  m_simc( sc_get_curr_simcontext() ),
46  m_pushed( true )
47{
48    m_simc->get_object_manager()->push_module_name( this );
49}
50
51sc_module_name::sc_module_name( const sc_module_name& name_ )
52: m_name( name_.m_name ),
53  m_module_p( 0 ),
54  m_next( 0 ),
55  m_simc( name_.m_simc ),
56  m_pushed( false )
57{}
58
59sc_module_name::~sc_module_name()
60{
61    if( m_pushed ) {
62        sc_module_name* smn = m_simc->get_object_manager()->pop_module_name();
63        if( this != smn ) {
64            SC_REPORT_ERROR( SC_ID_SC_MODULE_NAME_USE_, 0 );
65        }
66	if ( m_module_p ) m_module_p->end_module();
67    }
68}
69
70sc_module_name::operator const char*() const
71{
72    return m_name;
73}
74
75} // namespace sc_core
76
77// $Log: sc_module_name.cpp,v $
78// Revision 1.5  2011/08/26 20:46:10  acg
79//  Andy Goodrich: moved the modification log to the end of the file to
80//  eliminate source line number skew when check-ins are done.
81//
82// Revision 1.4  2011/02/18 20:27:14  acg
83//  Andy Goodrich: Updated Copyrights.
84//
85// Revision 1.3  2011/02/13 21:47:37  acg
86//  Andy Goodrich: update copyright notice.
87//
88// Revision 1.2  2008/05/22 17:06:26  acg
89//  Andy Goodrich: updated copyright notice to include 2008.
90//
91// Revision 1.1.1.1  2006/12/15 20:20:05  acg
92// SystemC 2.3
93//
94// Revision 1.4  2006/03/14 23:56:58  acg
95//   Andy Goodrich: This fixes a bug when an exception is thrown in
96//   sc_module::sc_module() for a dynamically allocated sc_module
97//   object. We are calling sc_module::end_module() on a module that has
98//   already been deleted. The scenario runs like this:
99//
100//   a) the sc_module constructor is entered
101//   b) the exception is thrown
102//   c) the exception processor deletes the storage for the sc_module
103//   d) the stack is unrolled causing the sc_module_name instance to be deleted
104//   e) ~sc_module_name() calls end_module() with its pointer to the sc_module
105//   f) because the sc_module has been deleted its storage is corrupted,
106//      either by linking it to a free space chain, or by reuse of some sort
107//   g) the m_simc field is garbage
108//   h) the m_object_manager field is also garbage
109//   i) an exception occurs
110//
111//   This does not happen for automatic sc_module instances since the
112//   storage for the module is not reclaimed its just part of the stack.
113//
114//   I am fixing this by having the destructor for sc_module clear the
115//   module pointer in its sc_module_name instance. That cuts things at
116//   step (e) above, since the pointer will be null if the module has
117//   already been deleted. To make sure the module stack is okay, I call
118//   end-module() in ~sc_module in the case where there is an
119//   sc_module_name pointer lying around.
120//
121// Revision 1.3  2006/01/13 18:44:30  acg
122// Added $Log to record CVS changes into the source.
123//
124