SystemC  2.3.2
Accellera SystemC proof-of-concept library
sc_module_name.h
Go to the documentation of this file.
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.h -- An object used to help manage object names
23 */
34 // $Log: sc_module_name.h,v $
35 // Revision 1.5 2011/08/26 20:46:10 acg
36 // Andy Goodrich: moved the modification log to the end of the file to
37 // eliminate source line number skew when check-ins are done.
38 //
39 
40 #ifndef SC_MODULE_NAME_H
41 #define SC_MODULE_NAME_H
42 
43 
44 namespace sc_core {
45 
46 class sc_module;
47 class sc_simcontext;
48 
49 
57 {
58  friend class sc_module;
59  friend class sc_object_manager;
60 
61 public:
62 
63  sc_module_name( const char* );
65 
66  ~sc_module_name();
67 
68  operator const char*() const;
69 
70 protected:
71  inline void clear_module( sc_module* module_p );
72  inline void set_module( sc_module* module_p );
73 
74 private:
75 
76  const char* m_name;
77  sc_module* m_module_p;
78  sc_module_name* m_next;
79  sc_simcontext* m_simc;
80  bool m_pushed;
81 
82 private:
83 
84  // disabled
86  sc_module_name& operator = ( const sc_module_name& );
87 };
88 
89 inline void sc_module_name::clear_module( sc_module* module_p )
90 {
91  sc_assert( m_module_p == module_p );
92  m_module_p = module_p = 0; // avoid unused parameter warning (module_p)
93 }
94 
95 inline void sc_module_name::set_module( sc_module* module_p )
96 {
97  m_module_p = module_p;
98 }
99 
100 } // namespace sc_core
101 
102 // Revision 1.4 2011/02/18 20:27:14 acg
103 // Andy Goodrich: Updated Copyrights.
104 //
105 // Revision 1.3 2011/02/13 21:47:37 acg
106 // Andy Goodrich: update copyright notice.
107 //
108 // Revision 1.2 2008/05/22 17:06:26 acg
109 // Andy Goodrich: updated copyright notice to include 2008.
110 //
111 // Revision 1.1.1.1 2006/12/15 20:20:05 acg
112 // SystemC 2.3
113 //
114 // Revision 1.4 2006/03/14 23:56:58 acg
115 // Andy Goodrich: This fixes a bug when an exception is thrown in
116 // sc_module::sc_module() for a dynamically allocated sc_module
117 // object. We are calling sc_module::end_module() on a module that has
118 // already been deleted. The scenario runs like this:
119 //
120 // a) the sc_module constructor is entered
121 // b) the exception is thrown
122 // c) the exception processor deletes the storage for the sc_module
123 // d) the stack is unrolled causing the sc_module_name instance to be deleted
124 // e) ~sc_module_name() calls end_module() with its pointer to the sc_module
125 // f) because the sc_module has been deleted its storage is corrupted,
126 // either by linking it to a free space chain, or by reuse of some sort
127 // g) the m_simc field is garbage
128 // h) the m_object_manager field is also garbage
129 // i) an exception occurs
130 //
131 // This does not happen for automatic sc_module instances since the
132 // storage for the module is not reclaimed its just part of the stack.
133 //
134 // I am fixing this by having the destructor for sc_module clear the
135 // module pointer in its sc_module_name instance. That cuts things at
136 // step (e) above, since the pointer will be null if the module has
137 // already been deleted. To make sure the module stack is okay, I call
138 // end-module() in ~sc_module in the case where there is an
139 // sc_module_name pointer lying around.
140 //
141 // Revision 1.3 2006/01/13 18:44:30 acg
142 // Added $Log to record CVS changes into the source.
143 
144 #endif
#define sc_assert(expr)
Definition: sc_report.h:270
void clear_module(sc_module *module_p)
Module name class.
Manager of objects.
Base class for all structural entities.
Definition: sc_module.h:83
The simulation context.
class SC_API sc_module
Definition: sc_object.h:48
void set_module(sc_module *module_p)
class SC_API sc_simcontext
Definition: sc_object.h:51
#define SC_API
Definition: sc_cmnhdr.h:168