SystemC  Recoding Infrastructure for SystemC v0.6.3 derived from Accellera SystemC 2.3.1
Accellera SystemC proof-of-concept library
sc_phase_callback_registry.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_phase_callback_registry.h -- Definition of the simulation phase callbacks
21 
22  The most critical functions are defined inline in this file. Only active,
23  if SC_ENABLE_SIMULATION_PHASE_CALLBACKS[_TRACING] is defined during the
24  SystemC library build.
25 
26  Original Author: Philipp A. Hartmann, OFFIS, 2013-02-15
27 
28  CHANGE LOG AT END OF FILE
29  *****************************************************************************/
30 
31 #ifndef SC_PHASE_CALLBACK_REGISTRY_H_INCLUDED_
32 #define SC_PHASE_CALLBACK_REGISTRY_H_INCLUDED_
33 
34 #if defined( SC_ENABLE_SIMULATION_PHASE_CALLBACKS ) \
35  || defined( SC_ENABLE_SIMULATION_PHASE_CALLBACKS_TRACING )
36 # define SC_HAS_PHASE_CALLBACKS_ 1
37 #else
38 # define SC_HAS_PHASE_CALLBACKS_ 0
39 #endif
40 
43 #include "sysc/kernel/sc_status.h"
44 
45 #include <vector>
46 
47 namespace sc_core {
48 
49 class sc_simcontext;
50 class sc_object;
51 
53 {
54 public:
56  typedef sc_object cb_type;
58 
59  struct entry
60  {
63  };
64 
65  friend class sc_simcontext;
66  friend class sc_object;
67 
68 private: // interface completely internal
69 
70  explicit
72 
74 
75  // --- callback forwarders
76 
77  bool construction_done() const; //< returns false
78  void elaboration_done() const;
79  void initialization_done() const;
80  void start_simulation() const;
81 
82  void evaluation_done() const;
83  void update_done() const;
84  void before_timestep() const;
85 
86  void simulation_paused() const;
87  void simulation_stopped() const;
88  void simulation_done() const;
89 
90 
91  // --- callback registration and implementation
92 
93  mask_type register_callback( cb_type&, mask_type mask );
94  mask_type unregister_callback( cb_type&, mask_type mask );
95 
96  // generic caller
97  void do_callback( sc_status ) const;
98 
99 private:
100  typedef std::vector<entry> storage_type;
101  typedef std::vector<cb_type*> single_storage_type;
102 
103 #if SC_HAS_PHASE_CALLBACKS_
104 
105  // set and restore simulation status
106  struct scoped_status
107  {
108  scoped_status( sc_status& ref, sc_status s )
109  : ref_(ref), prev_(ref) { ref_ = s;}
110  ~scoped_status() { ref_ = prev_; }
111  private:
112  sc_status& ref_;
113  sc_status prev_;
114  }; // scoped_status
115 
116  mask_type validate_mask( cb_type&, mask_type, bool warn );
117 
118 private:
119 
120  sc_simcontext* m_simc;
121  storage_type m_cb_vec; // all callbacks
122 #if 0
123  single_storage_type m_cb_eval_vec; // - eval cb shortcut
124 #endif
125  single_storage_type m_cb_update_vec; // - update cb shortcut
126  single_storage_type m_cb_timestep_vec; // - timestep cb shortcut
127 
128 #endif // SC_HAS_PHASE_CALLBACKS_
129 
130 private:
131  // disabled
132  sc_phase_callback_registry( const this_type& );
133  this_type& operator=(const this_type&);
134 
135 }; // sc_phase_callback_registry
136 
137 
138 // -------------------- callback implementations --------------------
139 // (empty, if feature is disabled)
140 
141 inline bool
142 sc_phase_callback_registry::construction_done() const
143 {
144 #if SC_HAS_PHASE_CALLBACKS_
145  do_callback( SC_BEFORE_END_OF_ELABORATION );
146 #endif
147  return false;
148 }
149 
150 inline void
151 sc_phase_callback_registry::elaboration_done() const
152 {
153 #if SC_HAS_PHASE_CALLBACKS_
154  do_callback( SC_END_OF_ELABORATION );
155 #endif
156 }
157 
158 inline void
159 sc_phase_callback_registry::start_simulation() const
160 {
161 #if SC_HAS_PHASE_CALLBACKS_
162  do_callback( SC_START_OF_SIMULATION );
163 #endif
164 }
165 
166 inline void
167 sc_phase_callback_registry::initialization_done() const
168 {
169 #if SC_HAS_PHASE_CALLBACKS_
170  scoped_status scope( m_simc->m_simulation_status
172 
173  do_callback( SC_END_OF_INITIALIZATION );
174 #endif
175 }
176 
177 inline void
178 sc_phase_callback_registry::simulation_paused() const
179 {
180 #if SC_HAS_PHASE_CALLBACKS_
181  do_callback( SC_PAUSED );
182 #endif
183 }
184 
185 inline void
186 sc_phase_callback_registry::simulation_stopped() const
187 {
188 #if SC_HAS_PHASE_CALLBACKS_
189  do_callback( SC_STOPPED );
190 #endif
191 }
192 
193 inline void
194 sc_phase_callback_registry::simulation_done() const
195 {
196 #if SC_HAS_PHASE_CALLBACKS_
197  do_callback( SC_END_OF_SIMULATION );
198 #endif
199 }
200 
201 // -------------- specialized callback implementations --------------
202 
203 #if 0
204 inline void
205 sc_phase_callback_registry::evaluation_done() const
206 {
207 #if SC_HAS_PHASE_CALLBACKS_
208 
209  if( !m_cb_eval_vec.size() ) return;
210 
211  typedef single_storage_type::const_iterator it_type;
212  single_storage_type const & vec = m_cb_eval_vec;
213 
214  scoped_status scope( m_simc->m_simulation_status
215  , SC_END_OF_EVALUATION );
216 
217  for(it_type it = vec.begin(), end = vec.end(); it != end; ++it)
218  (*it)->do_simulation_phase_callback();
219 #endif
220 }
221 #endif
222 
223 inline void
224 sc_phase_callback_registry::update_done() const
225 {
226 #if SC_HAS_PHASE_CALLBACKS_
227 
228  if( !m_cb_update_vec.size() ) return;
229 
230  typedef single_storage_type::const_iterator it_type;
231  single_storage_type const & vec = m_cb_update_vec;
232 
233  scoped_status scope( m_simc->m_simulation_status
234  , SC_END_OF_UPDATE );
235 
236  for(it_type it = vec.begin(), end = vec.end(); it != end; ++it)
237  (*it)->do_simulation_phase_callback();
238 #endif
239 }
240 
241 inline void
242 sc_phase_callback_registry::before_timestep() const
243 {
244 #if SC_HAS_PHASE_CALLBACKS_
245 
246  if( !m_cb_timestep_vec.size() ) return;
247 
248  typedef single_storage_type::const_iterator it_type;
249  single_storage_type const & vec = m_cb_timestep_vec;
250 
251  scoped_status scope( m_simc->m_simulation_status
252  , SC_BEFORE_TIMESTEP );
253 
254  for(it_type it = vec.begin(), end = vec.end(); it != end; ++it)
255  (*it)->do_simulation_phase_callback();
256 #endif
257 }
258 
259 // ------------------------------------------------------------------
260 
261 } // namespace sc_core
262 
263 /*****************************************************************************
264 
265  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
266  changes you are making here.
267 
268  Name, Affiliation, Date:
269  Description of Modification:
270 
271  *****************************************************************************/
272 #endif /* SC_PHASE_CALLBACK_REGISTRY_H_INCLUDED_ */
273 // Taf!
274 
unsigned phase_cb_mask
Definition: sc_object.h:69
The simulation context.
Abstract base class of all SystemC `simulation&#39; objects.
Definition: sc_object.h:51