SystemC 3.0.0
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 and hierarchy.
24
25 Original Author: Stan Y. Liao, Synopsys, Inc.
26
27 CHANGE LOG AT THE END OF THE FILE
28 *****************************************************************************/
29
30// $Log: sc_module_name.h,v $
31// Revision 1.5 2011/08/26 20:46:10 acg
32// Andy Goodrich: moved the modification log to the end of the file to
33// eliminate source line number skew when check-ins are done.
34//
35
36#ifndef SC_MODULE_NAME_H
37#define SC_MODULE_NAME_H
38
40
41#include <functional>
42
43#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
44#pragma warning(push)
45#pragma warning(disable: 4251) // DLL import for std::vector
46#endif
47
48namespace sc_core {
49
50class sc_module;
51class sc_simcontext;
52class sc_initializer_function;
53
54
55// ----------------------------------------------------------------------------
56// CLASS : sc_module_name
57//
58// Module name class.
59// ----------------------------------------------------------------------------
60
62{
63 friend class sc_module;
64 friend class sc_object_manager;
66
67public:
68
69 sc_module_name( const char* );
71
72 // might throw from initializer function
73 ~sc_module_name() noexcept(false);
74
75 operator const char*() const;
76
77protected:
78 inline void clear_module( sc_module* module_p );
79 inline void set_module( sc_module* module_p );
80
81 void execute_initializers();
82
83private:
84
85 const char* m_name;
86 sc_module* m_module_p;
87 sc_module_name* m_next;
88 sc_simcontext* m_simc;
89 bool m_pushed;
90 std::vector<std::function<void()>> m_initializer_fn_vec;
91
92private:
93
94 // disabled
96 sc_module_name& operator = ( const sc_module_name& );
97};
98
99inline void sc_module_name::clear_module( sc_module* module_p )
100{
101 sc_assert( m_module_p == module_p );
102 m_module_p = module_p = 0; // avoid unused parameter warning (module_p)
103 m_initializer_fn_vec.clear();
104}
105
106inline void sc_module_name::set_module( sc_module* module_p )
107{
108 m_module_p = module_p;
109}
110
111} // namespace sc_core
112
113#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
114#pragma warning(pop)
115#endif
116
117// Revision 1.4 2011/02/18 20:27:14 acg
118// Andy Goodrich: Updated Copyrights.
119//
120// Revision 1.3 2011/02/13 21:47:37 acg
121// Andy Goodrich: update copyright notice.
122//
123// Revision 1.2 2008/05/22 17:06:26 acg
124// Andy Goodrich: updated copyright notice to include 2008.
125//
126// Revision 1.1.1.1 2006/12/15 20:20:05 acg
127// SystemC 2.3
128//
129// Revision 1.4 2006/03/14 23:56:58 acg
130// Andy Goodrich: This fixes a bug when an exception is thrown in
131// sc_module::sc_module() for a dynamically allocated sc_module
132// object. We are calling sc_module::end_module() on a module that has
133// already been deleted. The scenario runs like this:
134//
135// a) the sc_module constructor is entered
136// b) the exception is thrown
137// c) the exception processor deletes the storage for the sc_module
138// d) the stack is unrolled causing the sc_module_name instance to be deleted
139// e) ~sc_module_name() calls end_module() with its pointer to the sc_module
140// f) because the sc_module has been deleted its storage is corrupted,
141// either by linking it to a free space chain, or by reuse of some sort
142// g) the m_simc field is garbage
143// h) the m_object_manager field is also garbage
144// i) an exception occurs
145//
146// This does not happen for automatic sc_module instances since the
147// storage for the module is not reclaimed its just part of the stack.
148//
149// I am fixing this by having the destructor for sc_module clear the
150// module pointer in its sc_module_name instance. That cuts things at
151// step (e) above, since the pointer will be null if the module has
152// already been deleted. To make sure the module stack is okay, I call
153// end-module() in ~sc_module in the case where there is an
154// sc_module_name pointer lying around.
155//
156// Revision 1.3 2006/01/13 18:44:30 acg
157// Added $Log to record CVS changes into the source.
158
159#endif
#define SC_API
Definition: sc_cmnhdr.h:148
#define sc_assert(expr)
Definition: sc_report.h:248
class SC_API sc_simcontext
Definition: sc_object.h:50
class SC_API sc_module
Definition: sc_object.h:44
~sc_module_name() noexcept(false)
void set_module(sc_module *module_p)
sc_module_name(const char *)
sc_module_name(const sc_module_name &)