SystemC 3.0.0
Accellera SystemC proof-of-concept library
sc_export.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_export.h -- Base classes of all export classes.
23
24 Original Author: Andy Goodrich, Forte Design Systems
25 Bishnupriya Bhattacharya, Cadence Design Systems
26
27 CHANGE LOG IS AT THE END OF THE FILE
28 *****************************************************************************/
29
30#ifndef SC_EXPORT_H
31#define SC_EXPORT_H
32#include <typeindex>
33
37
38namespace sc_core {
39
40//=============================================================================
41// CLASS : sc_export_base
42//
43// Abstract base class for class sc_export<IF>.
44//=============================================================================
45
47{
48 friend class sc_export_registry;
49public:
50
51 // typedefs
52
54
55public:
56
58 virtual const sc_interface* get_interface() const = 0;
59
60 // return RTTI information of associated interface
61 virtual std::type_index get_interface_type() const = 0;
62
63protected:
64
65 // constructors
66
68 sc_export_base(const char* name);
69
70 // destructor
71
72 virtual ~sc_export_base();
73
74protected:
75
76 // called when construction is done
78
79 // called when elaboration is done (does nothing by default)
80 virtual void end_of_elaboration();
81
82 // called before simulation starts (does nothing by default)
83 virtual void start_of_simulation();
84
85 // called after simulation ends (does nothing)
86 virtual void end_of_simulation();
87
88 // error reporting
89 void report_error( const char* id, const char* add_msg = 0) const;
90
91private:
92 const char* if_typename() const
93 { return get_interface_type().name(); }
94
95 void construction_done();
96 void elaboration_done();
97 void start_simulation();
98 void simulation_done();
99
100 // disabled
101 sc_export_base(const this_type&);
102 this_type& operator = (const this_type& );
103
104};
105
106//=============================================================================
107// CLASS : sc_export
108//
109// Generic export class for other export classes. This
110// class provides a binding point for access to an interface.
111//=============================================================================
112template<class IF>
114{
115 typedef sc_export<IF> this_type;
116
117public: // constructors:
119 {
120 m_interface_p = 0;
121 }
122
123 explicit sc_export( const char* name_ ) : sc_export_base(name_)
124 {
125 m_interface_p = 0;
126 }
127
128public: // destructor:
129 virtual ~sc_export()
130 {
131 }
132
133public: // interface access:
134
136 {
137 return m_interface_p;
138 }
139
140 virtual const sc_interface* get_interface() const
141 {
142 return m_interface_p;
143 }
144
145 const IF* operator -> () const {
146 if ( m_interface_p == 0 )
147 {
149 // may continue, if suppressed
150 }
151 return m_interface_p;
152 }
153
155 if ( m_interface_p == 0 )
156 {
158 // may continue, if suppressed
159 }
160 return m_interface_p;
161 }
162
163 operator IF& ()
164 {
165 if ( m_interface_p == 0 )
166 {
168 sc_abort(); // can't recover from here
169 }
170 return *m_interface_p;
171 }
172 operator const IF&() const
173 { return *const_cast<this_type*>(this); }
174
175
176public: // binding:
177 virtual void bind( IF& interface_ )
178 {
179 if ( m_interface_p )
180 {
182 return;
183 }
184 m_interface_p = &interface_;
185 }
186
187 void operator () ( IF& interface_ )
188 {
189 this->bind(interface_);
190 }
191
192public: // identification:
193 virtual const char* kind() const { return "sc_export"; }
194
195 // return RTTI information of associated interface
196 virtual std::type_index get_interface_type() const
197 {
198 return typeid( IF );
199 }
200
201private: // disabled
202 sc_export( const this_type& );
203 this_type& operator = ( const this_type& );
204
205protected: // data fields:
206 IF* m_interface_p; // Interface this port provides.
207};
208
209// ----------------------------------------------------------------------------
210// CLASS : sc_export_registry
211//
212// Registry for all exports.
213// FOR INTERNAL USE ONLY!
214// ----------------------------------------------------------------------------
215
217{
218 friend class sc_simcontext;
219
220public:
221
224
225 int size() const
226 { return static_cast<int>(m_export_vec.size()); }
227
228private:
229
230 // constructor
231 explicit sc_export_registry( sc_simcontext& simc_ );
232
233 // destructor
235
236 // called when construction is done
237 bool construction_done();
238
239 // called when elaboration is done
240 void elaboration_done();
241
242 // called before simulation starts
243 void start_simulation();
244
245 // called after simulation ends
246 void simulation_done();
247
248private:
249
250 int m_construction_done;
251 std::vector<sc_export_base*> m_export_vec;
252 sc_simcontext* m_simc;
253
254private:
255
256 // disabled
259 sc_export_registry& operator = ( const sc_export_registry& );
260};
261
262} // namespace sc_core
263
264// $Log: sc_export.h,v $
265// Revision 1.7 2011/08/26 20:45:40 acg
266// Andy Goodrich: moved the modification log to the end of the file to
267// eliminate source line number skew when check-ins are done.
268//
269// Revision 1.6 2011/05/09 04:07:37 acg
270// Philipp A. Hartmann:
271// (1) Restore hierarchy in all phase callbacks.
272// (2) Ensure calls to before_end_of_elaboration.
273//
274// Revision 1.5 2011/04/02 00:02:14 acg
275// Philipp A. Hartmann: add const overload for sc_export::operator IF&
276//
277// Revision 1.4 2011/02/18 20:23:45 acg
278// Andy Goodrich: Copyright update.
279//
280// Revision 1.3 2011/02/14 17:50:16 acg
281// Andy Goodrich: testing for sc_port and sc_export instantiations during
282// end of elaboration and issuing appropriate error messages.
283//
284// Revision 1.2 2011/01/20 16:52:15 acg
285// Andy Goodrich: changes for IEEE 1666 2011.
286//
287// Revision 1.1.1.1 2006/12/15 20:20:04 acg
288// SystemC 2.3
289//
290// Revision 1.3 2006/01/13 18:47:42 acg
291// Added $Log command so that CVS comments are reproduced in the source.
292//
293
294#endif
295
296// Taf!
#define SC_API
Definition: sc_cmnhdr.h:148
#define SC_REPORT_ERROR(msg_type, msg)
Definition: sc_report.h:217
const char SC_ID_SC_EXPORT_ALREADY_BOUND_[]
const char SC_ID_SC_EXPORT_HAS_NO_INTERFACE_[]
SC_API void sc_abort()
virtual void end_of_simulation()
void report_error(const char *id, const char *add_msg=0) const
virtual sc_interface * get_interface()=0
virtual void before_end_of_elaboration()
virtual void end_of_elaboration()
virtual const sc_interface * get_interface() const =0
virtual std::type_index get_interface_type() const =0
sc_export_base(const char *name)
sc_export_base this_type
Definition: sc_export.h:53
virtual void start_of_simulation()
void operator()(IF &interface_)
Definition: sc_export.h:187
virtual std::type_index get_interface_type() const
Definition: sc_export.h:196
sc_export(const char *name_)
Definition: sc_export.h:123
virtual const char * kind() const
Definition: sc_export.h:193
virtual const sc_interface * get_interface() const
Definition: sc_export.h:140
virtual ~sc_export()
Definition: sc_export.h:129
const IF * operator->() const
Definition: sc_export.h:145
virtual void bind(IF &interface_)
Definition: sc_export.h:177
virtual sc_interface * get_interface()
Definition: sc_export.h:135
void insert(sc_export_base *)
void remove(sc_export_base *)
const char * name() const
Definition: sc_object.h:122