gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sc_module.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * Authors: Gabe Black
28  */
29 
30 #ifndef __SYSTEMC_CORE_EXT_SC_MODULE_HH__
31 #define __SYSTEMC_CORE_EXT_SC_MODULE_HH__
32 
33 #include <string>
34 #include <vector>
35 
36 #include "sc_object.hh"
37 #include "sc_process_handle.hh"
38 #include "sc_sensitive.hh"
39 #include "sc_time.hh"
40 
41 namespace sc_dt
42 {
43 
44 class sc_logic;
45 
46 } // namespace sc_dt
47 
48 namespace sc_gem5
49 {
50 
51 class Kernel;
52 class Module;
53 class Process;
54 struct ProcessFuncWrapper;
55 
56 Process *newMethodProcess(const char *name, ProcessFuncWrapper *func);
57 Process *newThreadProcess(const char *name, ProcessFuncWrapper *func);
58 Process *newCThreadProcess(const char *name, ProcessFuncWrapper *func);
59 
60 } // namespace sc_gem5
61 
62 // Gem5 prototype
63 class Port;
64 
65 namespace sc_core
66 {
67 
68 template <class T>
69 class sc_in;
70 template <class T>
71 class sc_out;
72 template <class T>
73 class sc_inout;
74 template <class T>
75 class sc_signal_in_if;
76 
77 class sc_event;
78 class sc_event_and_list;
79 class sc_event_or_list;
80 class sc_module_name;
81 
83 {
84  private:
87 
88  public:
89  sc_bind_proxy();
90  sc_bind_proxy(sc_interface &_interface);
92 
93  sc_interface *interface() const { return _interface; }
94  sc_port_base *port() const { return _port; }
95 };
96 
97 extern const sc_bind_proxy SC_BIND_PROXY_NIL;
98 
99 class sc_module : public sc_object
100 {
101  public:
102  // Gem5 specific extensions
103  virtual ::Port &gem5_getPort(const std::string &if_name, int idx=-1);
104 
105  public:
106  friend class ::sc_gem5::Kernel;
107  friend class ::sc_gem5::Module;
108 
109  virtual ~sc_module();
110 
111  virtual const char *kind() const { return "sc_module"; }
112 
113  void operator () (const sc_bind_proxy &p001,
114  const sc_bind_proxy &p002 = SC_BIND_PROXY_NIL,
115  const sc_bind_proxy &p003 = SC_BIND_PROXY_NIL,
116  const sc_bind_proxy &p004 = SC_BIND_PROXY_NIL,
117  const sc_bind_proxy &p005 = SC_BIND_PROXY_NIL,
118  const sc_bind_proxy &p006 = SC_BIND_PROXY_NIL,
119  const sc_bind_proxy &p007 = SC_BIND_PROXY_NIL,
120  const sc_bind_proxy &p008 = SC_BIND_PROXY_NIL,
121  const sc_bind_proxy &p009 = SC_BIND_PROXY_NIL,
122  const sc_bind_proxy &p010 = SC_BIND_PROXY_NIL,
123  const sc_bind_proxy &p011 = SC_BIND_PROXY_NIL,
124  const sc_bind_proxy &p012 = SC_BIND_PROXY_NIL,
125  const sc_bind_proxy &p013 = SC_BIND_PROXY_NIL,
126  const sc_bind_proxy &p014 = SC_BIND_PROXY_NIL,
127  const sc_bind_proxy &p015 = SC_BIND_PROXY_NIL,
128  const sc_bind_proxy &p016 = SC_BIND_PROXY_NIL,
129  const sc_bind_proxy &p017 = SC_BIND_PROXY_NIL,
130  const sc_bind_proxy &p018 = SC_BIND_PROXY_NIL,
131  const sc_bind_proxy &p019 = SC_BIND_PROXY_NIL,
132  const sc_bind_proxy &p020 = SC_BIND_PROXY_NIL,
133  const sc_bind_proxy &p021 = SC_BIND_PROXY_NIL,
134  const sc_bind_proxy &p022 = SC_BIND_PROXY_NIL,
135  const sc_bind_proxy &p023 = SC_BIND_PROXY_NIL,
136  const sc_bind_proxy &p024 = SC_BIND_PROXY_NIL,
137  const sc_bind_proxy &p025 = SC_BIND_PROXY_NIL,
138  const sc_bind_proxy &p026 = SC_BIND_PROXY_NIL,
139  const sc_bind_proxy &p027 = SC_BIND_PROXY_NIL,
140  const sc_bind_proxy &p028 = SC_BIND_PROXY_NIL,
141  const sc_bind_proxy &p029 = SC_BIND_PROXY_NIL,
142  const sc_bind_proxy &p030 = SC_BIND_PROXY_NIL,
143  const sc_bind_proxy &p031 = SC_BIND_PROXY_NIL,
144  const sc_bind_proxy &p032 = SC_BIND_PROXY_NIL,
145  const sc_bind_proxy &p033 = SC_BIND_PROXY_NIL,
146  const sc_bind_proxy &p034 = SC_BIND_PROXY_NIL,
147  const sc_bind_proxy &p035 = SC_BIND_PROXY_NIL,
148  const sc_bind_proxy &p036 = SC_BIND_PROXY_NIL,
149  const sc_bind_proxy &p037 = SC_BIND_PROXY_NIL,
150  const sc_bind_proxy &p038 = SC_BIND_PROXY_NIL,
151  const sc_bind_proxy &p039 = SC_BIND_PROXY_NIL,
152  const sc_bind_proxy &p040 = SC_BIND_PROXY_NIL,
153  const sc_bind_proxy &p041 = SC_BIND_PROXY_NIL,
154  const sc_bind_proxy &p042 = SC_BIND_PROXY_NIL,
155  const sc_bind_proxy &p043 = SC_BIND_PROXY_NIL,
156  const sc_bind_proxy &p044 = SC_BIND_PROXY_NIL,
157  const sc_bind_proxy &p045 = SC_BIND_PROXY_NIL,
158  const sc_bind_proxy &p046 = SC_BIND_PROXY_NIL,
159  const sc_bind_proxy &p047 = SC_BIND_PROXY_NIL,
160  const sc_bind_proxy &p048 = SC_BIND_PROXY_NIL,
161  const sc_bind_proxy &p049 = SC_BIND_PROXY_NIL,
162  const sc_bind_proxy &p050 = SC_BIND_PROXY_NIL,
163  const sc_bind_proxy &p051 = SC_BIND_PROXY_NIL,
164  const sc_bind_proxy &p052 = SC_BIND_PROXY_NIL,
165  const sc_bind_proxy &p053 = SC_BIND_PROXY_NIL,
166  const sc_bind_proxy &p054 = SC_BIND_PROXY_NIL,
167  const sc_bind_proxy &p055 = SC_BIND_PROXY_NIL,
168  const sc_bind_proxy &p056 = SC_BIND_PROXY_NIL,
169  const sc_bind_proxy &p057 = SC_BIND_PROXY_NIL,
170  const sc_bind_proxy &p058 = SC_BIND_PROXY_NIL,
171  const sc_bind_proxy &p059 = SC_BIND_PROXY_NIL,
172  const sc_bind_proxy &p060 = SC_BIND_PROXY_NIL,
173  const sc_bind_proxy &p061 = SC_BIND_PROXY_NIL,
174  const sc_bind_proxy &p062 = SC_BIND_PROXY_NIL,
175  const sc_bind_proxy &p063 = SC_BIND_PROXY_NIL,
176  const sc_bind_proxy &p064 = SC_BIND_PROXY_NIL);
177 
178  // Deprecated
183 
184  virtual const std::vector<sc_object *> &get_child_objects() const;
185  virtual const std::vector<sc_event *> &get_child_events() const;
186 
187  protected:
188  sc_module(const sc_module_name &);
189  sc_module();
190 
191  // Deprecated
192  sc_module(const char *);
193  sc_module(const std::string &);
194 
195  /* Deprecated, but used in the regression tests. */
196  void end_module();
197 
198  void reset_signal_is(const sc_in<bool> &, bool);
199  void reset_signal_is(const sc_inout<bool> &, bool);
200  void reset_signal_is(const sc_out<bool> &, bool);
201  void reset_signal_is(const sc_signal_in_if<bool> &, bool);
202 
203  void async_reset_signal_is(const sc_in<bool> &, bool);
204  void async_reset_signal_is(const sc_inout<bool> &, bool);
205  void async_reset_signal_is(const sc_out<bool> &, bool);
206  void async_reset_signal_is(const sc_signal_in_if<bool> &, bool);
207 
209 
210  void dont_initialize();
211  void set_stack_size(size_t);
212 
213  void next_trigger();
214  void next_trigger(const sc_event &);
215  void next_trigger(const sc_event_or_list &);
216  void next_trigger(const sc_event_and_list &);
217  void next_trigger(const sc_time &);
218  void next_trigger(double, sc_time_unit);
219  void next_trigger(const sc_time &, const sc_event &);
220  void next_trigger(double, sc_time_unit, const sc_event &);
221  void next_trigger(const sc_time &, const sc_event_or_list &);
222  void next_trigger(double, sc_time_unit, const sc_event_or_list &);
223  void next_trigger(const sc_time &, const sc_event_and_list &);
224  void next_trigger(double, sc_time_unit, const sc_event_and_list &);
225 
226  // Nonstandard
227  bool timed_out();
228 
229  void wait();
230  void wait(int);
231  void wait(const sc_event &);
232  void wait(const sc_event_or_list &);
233  void wait(const sc_event_and_list &);
234  void wait(const sc_time &);
235  void wait(double, sc_time_unit);
236  void wait(const sc_time &, const sc_event &);
237  void wait(double, sc_time_unit, const sc_event &);
238  void wait(const sc_time &, const sc_event_or_list &);
239  void wait(double, sc_time_unit, const sc_event_or_list &);
240  void wait(const sc_time &, const sc_event_and_list &);
241  void wait(double, sc_time_unit, const sc_event_and_list &);
242 
243  // Nonstandard
244  void halt();
245  void at_posedge(const sc_signal_in_if<bool> &);
247  void at_negedge(const sc_signal_in_if<bool> &);
249 
250  virtual void before_end_of_elaboration() {}
251  virtual void end_of_elaboration() {}
252  virtual void start_of_simulation() {}
253  virtual void end_of_simulation() {}
254 
255  private:
257 
258  // Disabled
259  sc_module(const sc_module &) : sc_object() {};
260  sc_module &operator = (const sc_module &) { return *this; }
261 };
262 
263 void next_trigger();
264 void next_trigger(const sc_event &);
265 void next_trigger(const sc_event_or_list &);
266 void next_trigger(const sc_event_and_list &);
267 void next_trigger(const sc_time &);
268 void next_trigger(double, sc_time_unit);
269 void next_trigger(const sc_time &, const sc_event &);
270 void next_trigger(double, sc_time_unit, const sc_event &);
271 void next_trigger(const sc_time &, const sc_event_or_list &);
272 void next_trigger(double, sc_time_unit, const sc_event_or_list &);
273 void next_trigger(const sc_time &, const sc_event_and_list &);
274 void next_trigger(double, sc_time_unit, const sc_event_and_list &);
275 
276 void wait();
277 void wait(int);
278 void wait(const sc_event &);
279 void wait(const sc_event_or_list &);
280 void wait(const sc_event_and_list &);
281 void wait(const sc_time &);
282 void wait(double, sc_time_unit);
283 void wait(const sc_time &, const sc_event &);
284 void wait(double, sc_time_unit, const sc_event &);
285 void wait(const sc_time &, const sc_event_or_list &);
286 void wait(double, sc_time_unit, const sc_event_or_list &);
287 void wait(const sc_time &, const sc_event_and_list &);
288 void wait(double, sc_time_unit, const sc_event_and_list &);
289 
290 // Nonstandard
291 bool timed_out();
292 
293 #define SC_MODULE(name) struct name : ::sc_core::sc_module
294 
295 #define SC_CTOR(name) \
296  typedef name SC_CURRENT_USER_MODULE; \
297  name(::sc_core::sc_module_name)
298 
299 #define SC_HAS_PROCESS(name) typedef name SC_CURRENT_USER_MODULE
300 
301 #define SC_METHOD(name) \
302  { \
303  ::sc_gem5::Process *p = \
304  ::sc_gem5::newMethodProcess( \
305  #name, new ::sc_gem5::ProcessMemberFuncWrapper< \
306  SC_CURRENT_USER_MODULE>(this, \
307  &SC_CURRENT_USER_MODULE::name)); \
308  if (p) \
309  this->sensitive << p; \
310  }
311 #define SC_THREAD(name) \
312  { \
313  ::sc_gem5::Process *p = \
314  ::sc_gem5::newThreadProcess( \
315  #name, new ::sc_gem5::ProcessMemberFuncWrapper< \
316  SC_CURRENT_USER_MODULE>(this, \
317  &SC_CURRENT_USER_MODULE::name)); \
318  if (p) \
319  this->sensitive << p; \
320  }
321 #define SC_CTHREAD(name, clk) \
322  { \
323  ::sc_gem5::Process *p = \
324  ::sc_gem5::newCThreadProcess( \
325  #name, new ::sc_gem5::ProcessMemberFuncWrapper< \
326  SC_CURRENT_USER_MODULE>(this, \
327  &SC_CURRENT_USER_MODULE::name)); \
328  if (p) \
329  this->sensitive(p, clk); \
330  }
331 
332 // Nonstandard
333 // Documentation for this is very scarce, but it looks like it's supposed to
334 // stop the currently executing cthread, or if a cthread isn't running report
335 // an error.
336 void halt();
337 void at_posedge(const sc_signal_in_if<bool> &);
338 void at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &);
339 void at_negedge(const sc_signal_in_if<bool> &);
340 void at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &);
341 
342 const char *sc_gen_unique_name(const char *);
343 
344 // Nonstandard
345 bool sc_hierarchical_name_exists(const char *name);
346 
349 
352 
353 // Nonstandard
354 // Allocates a module of type x and records a pointer to it so that it gets
355 // destructed automatically at the end of the simulation.
357 #define SC_NEW(x) ::sc_core::sc_module_sc_new(new x);
358 
359 // Nonstandard
360 #define SC_WAIT() \
361  ::sc_core::sc_set_location(__FILE__, __LINE__); \
362  ::sc_core::wait(); \
363  ::sc_core::sc_set_location(NULL, 0)
364 
365 // Nonstandard
366 #define SC_WAITN(n) \
367  ::sc_core::sc_set_location(__FILE__, __LINE__); \
368  ::sc_core::wait(n); \
369  ::sc_core::sc_set_location(NULL, 0)
370 
371 // Nonstandard
372 #define SC_WAIT_UNTIL(expr) \
373  do { SC_WAIT(); } while (!(expr))
374 
375 } // namespace sc_core
376 
377 #endif //__SYSTEMC_EXT_CORE_SC_MODULE_HH__
Ports are used to interface objects to each other.
Definition: port.hh:60
sc_gem5::Module * _gem5_module
Definition: sc_module.hh:256
sc_module(const sc_module &)
Definition: sc_module.hh:259
const std::string & name()
Definition: trace.cc:54
sc_time_unit
Definition: sc_time.hh:42
sc_module * sc_module_sc_new(sc_module *mod)
Definition: sc_module.cc:860
sc_signed operator<<(const sc_signed &u, const sc_int_base &v)
Definition: sc_signed.cc:853
const char * sc_gen_unique_name(const char *seed)
Definition: sc_module.cc:822
sc_concref_r< sc_bitref_r< T1 >, sc_bitref_r< T2 > > operator,(sc_bitref_r< T1 >, sc_bitref_r< T2 >)
bool sc_start_of_simulation_invoked()
Definition: sc_module.cc:848
Definition: sc_bit.cc:67
sc_sensitive sensitive
Definition: sc_module.hh:208
bool sc_hierarchical_name_exists(const char *name)
Definition: sc_module.cc:841
STL vector class.
Definition: stl.hh:40
virtual void end_of_simulation()
Definition: sc_module.hh:253
sc_interface * interface() const
Definition: sc_module.hh:93
virtual void start_of_simulation()
Definition: sc_module.hh:252
Process * newCThreadProcess(const char *name, ProcessFuncWrapper *func)
Definition: sc_module.cc:86
sc_module sc_behavior
Definition: sc_module.hh:347
const sc_bind_proxy SC_BIND_PROXY_NIL
Definition: sc_module.cc:116
sc_port_base * _port
Definition: sc_module.hh:86
sc_module sc_channel
Definition: sc_module.hh:348
Process * newMethodProcess(const char *name, ProcessFuncWrapper *func)
Definition: sc_module.cc:56
void wait()
Definition: sc_module.cc:655
virtual void end_of_elaboration()
Definition: sc_module.hh:251
sc_interface * _interface
Definition: sc_module.hh:85
Process * newThreadProcess(const char *name, ProcessFuncWrapper *func)
Definition: sc_module.cc:71
void at_negedge(const sc_signal_in_if< bool > &s)
Definition: sc_module.cc:804
void next_trigger()
Definition: sc_module.cc:540
bool sc_end_of_simulation_invoked()
Definition: sc_module.cc:854
void at_posedge(const sc_signal_in_if< bool > &s)
Definition: sc_module.cc:786
sc_port_base * port() const
Definition: sc_module.hh:94
virtual const char * kind() const
Definition: sc_module.hh:111
Bitfield< 26 > halt
Definition: dt_constants.hh:46
virtual void before_end_of_elaboration()
Definition: sc_module.hh:250
bool timed_out()
Definition: sc_module.cc:628

Generated on Fri Feb 28 2020 16:27:03 for gem5 by doxygen 1.8.13