SystemC  Recoding Infrastructure for SystemC v0.6.2 derived from Accellera SystemC 2.3.1
Accellera SystemC proof-of-concept library
sc_export.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 /*****************************************************************************
19 
20  sc_export.h -- Base classes of all export classes.
21 
22  Original Author: Andy Goodrich, Forte Design Systems
23  Bishnupriya Bhattacharya, Cadence Design Systems
24 
25  CHANGE LOG IS AT THE END OF THE FILE
26  *****************************************************************************/
27 
28 #ifndef SC_EXPORT_H
29 #define SC_EXPORT_H
30 #include <typeinfo>
31 
34 #include "sysc/kernel/sc_object.h"
35 
36 #if ! defined( SC_DISABLE_VIRTUAL_BIND )
37 # define SC_VIRTUAL_ virtual
38 #else
39 # define SC_VIRTUAL_ /* non-virtual */
40 #endif
41 
42 namespace sc_core {
43 
44 /**************************************************************************/
50 class sc_export_base : public sc_object
51 {
52  friend class sc_export_registry;
53 public:
54 
55  // typedefs
56 
58 
59 public:
60 
61  virtual sc_interface* get_interface() = 0;
62  virtual const sc_interface* get_interface() const = 0;
63 
64 protected:
65 
66  // constructors
67 
69  sc_export_base(const char* name);
70 
71  // destructor
72 
73  virtual ~sc_export_base();
74 
75 protected:
76 
77  // called when construction is done
78  virtual void before_end_of_elaboration();
79 
80  // called when elaboration is done (does nothing by default)
81  virtual void end_of_elaboration();
82 
83  // called before simulation starts (does nothing by default)
84  virtual void start_of_simulation();
85 
86  // called after simulation ends (does nothing)
87  virtual void end_of_simulation();
88 
89  virtual const char* if_typename() const = 0;
90 
91  // error reporting
92  void report_error( const char* id, const char* add_msg = 0) const;
93 
94 private:
95 
96  void construction_done();
97  void elaboration_done();
98  void start_simulation();
99  void simulation_done();
100 
101  // disabled
102  sc_export_base(const this_type&);
103  this_type& operator = (const this_type& );
104 
105 };
106 
107 /**************************************************************************/
114 template<class IF>
115 class sc_export : public sc_export_base
116 {
117  typedef sc_export<IF> this_type;
118 
119 public: // constructors:
121  {
122  m_interface_p = 0;
123  }
124 
125  explicit sc_export( const char* name_ ) : sc_export_base(name_)
126  {
127  m_interface_p = 0;
128  }
129 
130 public: // destructor:
131  virtual ~sc_export()
132  {
133  }
134 
135 public: // interface access:
136 
138  {
139  return m_interface_p;
140  }
141 
142  virtual const sc_interface* get_interface() const
143  {
144  return m_interface_p;
145  }
146 
147  const IF* operator -> () const {
148  if ( m_interface_p == 0 )
149  {
150  SC_REPORT_ERROR(SC_ID_SC_EXPORT_HAS_NO_INTERFACE_,name());
151  }
152  return m_interface_p;
153  }
154 
155  IF* operator -> () {
156  if ( m_interface_p == 0 )
157  {
158  SC_REPORT_ERROR(SC_ID_SC_EXPORT_HAS_NO_INTERFACE_,name());
159  }
160  return m_interface_p;
161  }
162 
163  operator IF& ()
164  {
165  if ( m_interface_p == 0 )
166  {
167  SC_REPORT_ERROR(SC_ID_SC_EXPORT_HAS_NO_INTERFACE_,name());
168  }
169  return *m_interface_p;
170  }
171  operator const IF&() const
172  { return *const_cast<this_type*>(this); }
173 
174 
175 public: // binding:
176  SC_VIRTUAL_ void bind( IF& interface_ )
177  {
178  if ( m_interface_p )
179  {
180  SC_REPORT_ERROR(SC_ID_SC_EXPORT_ALREADY_BOUND_,name());
181  }
182  else
183  {
184  m_interface_p = &interface_;
185  }
186  }
187 
188  void operator () ( IF& interface_ )
189  {
190  this->bind(interface_);
191  }
192 
193 public: // identification:
194  virtual const char* kind() const { return "sc_export"; }
195 
196 protected:
197  const char* if_typename() const {
198  return typeid( IF ).name();
199  }
200 
201 private: // disabled
202  sc_export( const this_type& );
203  this_type& operator = ( const this_type& );
204 
205 protected: // data fields:
206  IF* m_interface_p; // Interface this port provides.
207 };
208 
209 /**************************************************************************/
218 {
219  friend class sc_simcontext;
220 
221 public:
222 
223  void insert( sc_export_base* );
224  void remove( sc_export_base* );
225 
226  int size() const
227  { return m_export_vec.size(); }
228 
229 private:
230 
231  // constructor
232  explicit sc_export_registry( sc_simcontext& simc_ );
233 
234  // destructor
236 
237  // called when construction is done
238  bool construction_done();
239 
240  // called when elaboration is done
241  void elaboration_done();
242 
243  // called before simulation starts
244  void start_simulation();
245 
246  // called after simulation ends
247  void simulation_done();
248 
249 private:
250 
251  int m_construction_done;
252  std::vector<sc_export_base*> m_export_vec;
253  sc_simcontext* m_simc;
254 
255 private:
256 
257  // disabled
260  sc_export_registry& operator = ( const sc_export_registry& );
261 };
262 
263 } // namespace sc_core
264 
265 #undef SC_VIRTUAL_
266 
267 // $Log: sc_export.h,v $
268 // Revision 1.7 2011/08/26 20:45:40 acg
269 // Andy Goodrich: moved the modification log to the end of the file to
270 // eliminate source line number skew when check-ins are done.
271 //
272 // Revision 1.6 2011/05/09 04:07:37 acg
273 // Philipp A. Hartmann:
274 // (1) Restore hierarchy in all phase callbacks.
275 // (2) Ensure calls to before_end_of_elaboration.
276 //
277 // Revision 1.5 2011/04/02 00:02:14 acg
278 // Philipp A. Hartmann: add const overload for sc_export::operator IF&
279 //
280 // Revision 1.4 2011/02/18 20:23:45 acg
281 // Andy Goodrich: Copyright update.
282 //
283 // Revision 1.3 2011/02/14 17:50:16 acg
284 // Andy Goodrich: testing for sc_port and sc_export instantiations during
285 // end of elaboration and issuing appropriate error messages.
286 //
287 // Revision 1.2 2011/01/20 16:52:15 acg
288 // Andy Goodrich: changes for IEEE 1666 2011.
289 //
290 // Revision 1.1.1.1 2006/12/15 20:20:04 acg
291 // SystemC 2.3
292 //
293 // Revision 1.3 2006/01/13 18:47:42 acg
294 // Added $Log command so that CVS comments are reproduced in the source.
295 //
296 
297 #endif
298 
299 // Taf!
virtual void before_end_of_elaboration()
const IF * operator->() const
Definition: sc_export.h:147
sc_export_base this_type
Definition: sc_export.h:57
#define SC_REPORT_ERROR(msg_type, msg)
Definition: sc_report.h:213
SC_VIRTUAL_ void bind(IF &interface_)
Definition: sc_export.h:176
Registry for all exports.
Definition: sc_export.h:217
virtual const sc_interface * get_interface() const
Definition: sc_export.h:142
const char * name() const
Definition: sc_object.h:71
void operator()(IF &interface_)
Definition: sc_export.h:188
#define SC_VIRTUAL_
Definition: sc_export.h:37
Abstract base class for class sc_export&lt;IF&gt;.
Definition: sc_export.h:50
The simulation context.
Abstract base class of all interface classes.
Definition: sc_interface.h:44
void report_error(const char *id, const char *add_msg=0) const
virtual void start_of_simulation()
virtual const char * kind() const
Definition: sc_export.h:194
sc_export(const char *name_)
Definition: sc_export.h:125
Generic export class for other export classes.
Definition: sc_export.h:115
void insert(sc_export_base *)
const char * if_typename() const
Definition: sc_export.h:197
virtual void end_of_simulation()
virtual sc_interface * get_interface()=0
virtual ~sc_export()
Definition: sc_export.h:131
virtual sc_interface * get_interface()
Definition: sc_export.h:137
virtual const char * if_typename() const =0
virtual void end_of_elaboration()
Abstract base class of all SystemC `simulation&#39; objects.
Definition: sc_object.h:51