gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
28#ifndef __SYSTEMC_CORE_EXT_SC_MODULE_HH__
29#define __SYSTEMC_CORE_EXT_SC_MODULE_HH__
30
31#include <string>
32#include <vector>
33
34#include "sc_object.hh"
35#include "sc_process_handle.hh"
36#include "sc_sensitive.hh"
37#include "sc_time.hh"
38
39namespace sc_dt
40{
41
42class sc_logic;
43
44} // namespace sc_dt
45
46namespace sc_gem5
47{
48
49class Kernel;
50class Module;
51class Process;
52struct ProcessFuncWrapper;
53
54Process *newMethodProcess(const char *name, ProcessFuncWrapper *func);
55Process *newThreadProcess(const char *name, ProcessFuncWrapper *func);
56Process *newCThreadProcess(const char *name, ProcessFuncWrapper *func);
57
58} // namespace sc_gem5
59
60namespace gem5
61{
62
63class Port;
64
65} // namespace gem5
66
67namespace sc_core
68{
69
70template <class T>
71class sc_in;
72template <class T>
73class sc_out;
74template <class T>
75class sc_inout;
76template <class T>
77class sc_signal_in_if;
78
79class sc_event;
80class sc_event_and_list;
81class sc_event_or_list;
82class sc_module_name;
83
98
99extern const sc_bind_proxy SC_BIND_PROXY_NIL;
100
101class sc_module : public sc_object
102{
103 public:
104 // Gem5 specific extensions
105 virtual gem5::Port &gem5_getPort(const std::string &if_name, int idx=-1);
106
107 public:
108 friend class ::sc_gem5::Kernel;
109 friend class ::sc_gem5::Module;
110
111 virtual ~sc_module();
112
113 virtual const char *kind() const { return "sc_module"; }
114
115 void operator () (const sc_bind_proxy &p001,
116 const sc_bind_proxy &p002 = SC_BIND_PROXY_NIL,
117 const sc_bind_proxy &p003 = SC_BIND_PROXY_NIL,
118 const sc_bind_proxy &p004 = SC_BIND_PROXY_NIL,
119 const sc_bind_proxy &p005 = SC_BIND_PROXY_NIL,
120 const sc_bind_proxy &p006 = SC_BIND_PROXY_NIL,
121 const sc_bind_proxy &p007 = SC_BIND_PROXY_NIL,
122 const sc_bind_proxy &p008 = SC_BIND_PROXY_NIL,
123 const sc_bind_proxy &p009 = SC_BIND_PROXY_NIL,
124 const sc_bind_proxy &p010 = SC_BIND_PROXY_NIL,
125 const sc_bind_proxy &p011 = SC_BIND_PROXY_NIL,
126 const sc_bind_proxy &p012 = SC_BIND_PROXY_NIL,
127 const sc_bind_proxy &p013 = SC_BIND_PROXY_NIL,
128 const sc_bind_proxy &p014 = SC_BIND_PROXY_NIL,
129 const sc_bind_proxy &p015 = SC_BIND_PROXY_NIL,
130 const sc_bind_proxy &p016 = SC_BIND_PROXY_NIL,
131 const sc_bind_proxy &p017 = SC_BIND_PROXY_NIL,
132 const sc_bind_proxy &p018 = SC_BIND_PROXY_NIL,
133 const sc_bind_proxy &p019 = SC_BIND_PROXY_NIL,
134 const sc_bind_proxy &p020 = SC_BIND_PROXY_NIL,
135 const sc_bind_proxy &p021 = SC_BIND_PROXY_NIL,
136 const sc_bind_proxy &p022 = SC_BIND_PROXY_NIL,
137 const sc_bind_proxy &p023 = SC_BIND_PROXY_NIL,
138 const sc_bind_proxy &p024 = SC_BIND_PROXY_NIL,
139 const sc_bind_proxy &p025 = SC_BIND_PROXY_NIL,
140 const sc_bind_proxy &p026 = SC_BIND_PROXY_NIL,
141 const sc_bind_proxy &p027 = SC_BIND_PROXY_NIL,
142 const sc_bind_proxy &p028 = SC_BIND_PROXY_NIL,
143 const sc_bind_proxy &p029 = SC_BIND_PROXY_NIL,
144 const sc_bind_proxy &p030 = SC_BIND_PROXY_NIL,
145 const sc_bind_proxy &p031 = SC_BIND_PROXY_NIL,
146 const sc_bind_proxy &p032 = SC_BIND_PROXY_NIL,
147 const sc_bind_proxy &p033 = SC_BIND_PROXY_NIL,
148 const sc_bind_proxy &p034 = SC_BIND_PROXY_NIL,
149 const sc_bind_proxy &p035 = SC_BIND_PROXY_NIL,
150 const sc_bind_proxy &p036 = SC_BIND_PROXY_NIL,
151 const sc_bind_proxy &p037 = SC_BIND_PROXY_NIL,
152 const sc_bind_proxy &p038 = SC_BIND_PROXY_NIL,
153 const sc_bind_proxy &p039 = SC_BIND_PROXY_NIL,
154 const sc_bind_proxy &p040 = SC_BIND_PROXY_NIL,
155 const sc_bind_proxy &p041 = SC_BIND_PROXY_NIL,
156 const sc_bind_proxy &p042 = SC_BIND_PROXY_NIL,
157 const sc_bind_proxy &p043 = SC_BIND_PROXY_NIL,
158 const sc_bind_proxy &p044 = SC_BIND_PROXY_NIL,
159 const sc_bind_proxy &p045 = SC_BIND_PROXY_NIL,
160 const sc_bind_proxy &p046 = SC_BIND_PROXY_NIL,
161 const sc_bind_proxy &p047 = SC_BIND_PROXY_NIL,
162 const sc_bind_proxy &p048 = SC_BIND_PROXY_NIL,
163 const sc_bind_proxy &p049 = SC_BIND_PROXY_NIL,
164 const sc_bind_proxy &p050 = SC_BIND_PROXY_NIL,
165 const sc_bind_proxy &p051 = SC_BIND_PROXY_NIL,
166 const sc_bind_proxy &p052 = SC_BIND_PROXY_NIL,
167 const sc_bind_proxy &p053 = SC_BIND_PROXY_NIL,
168 const sc_bind_proxy &p054 = SC_BIND_PROXY_NIL,
169 const sc_bind_proxy &p055 = SC_BIND_PROXY_NIL,
170 const sc_bind_proxy &p056 = SC_BIND_PROXY_NIL,
171 const sc_bind_proxy &p057 = SC_BIND_PROXY_NIL,
172 const sc_bind_proxy &p058 = SC_BIND_PROXY_NIL,
173 const sc_bind_proxy &p059 = SC_BIND_PROXY_NIL,
174 const sc_bind_proxy &p060 = SC_BIND_PROXY_NIL,
175 const sc_bind_proxy &p061 = SC_BIND_PROXY_NIL,
176 const sc_bind_proxy &p062 = SC_BIND_PROXY_NIL,
177 const sc_bind_proxy &p063 = SC_BIND_PROXY_NIL,
178 const sc_bind_proxy &p064 = SC_BIND_PROXY_NIL);
179
180 // Deprecated
185
186 virtual const std::vector<sc_object *> &get_child_objects() const;
187 virtual const std::vector<sc_event *> &get_child_events() const;
188
189 protected:
190 sc_module(const sc_module_name &);
191 sc_module();
192
193 // Deprecated
194 sc_module(const char *);
195 sc_module(const std::string &);
196
197 /* Deprecated, but used in the regression tests. */
198 void end_module();
199
200 void reset_signal_is(const sc_in<bool> &, bool);
201 void reset_signal_is(const sc_inout<bool> &, bool);
202 void reset_signal_is(const sc_out<bool> &, bool);
203 void reset_signal_is(const sc_signal_in_if<bool> &, bool);
204
205 void async_reset_signal_is(const sc_in<bool> &, bool);
206 void async_reset_signal_is(const sc_inout<bool> &, bool);
207 void async_reset_signal_is(const sc_out<bool> &, bool);
209
211
212 void dont_initialize();
213 void set_stack_size(size_t);
214
215 void next_trigger();
216 void next_trigger(const sc_event &);
217 void next_trigger(const sc_event_or_list &);
218 void next_trigger(const sc_event_and_list &);
219 void next_trigger(const sc_time &);
220 void next_trigger(double, sc_time_unit);
221 void next_trigger(const sc_time &, const sc_event &);
222 void next_trigger(double, sc_time_unit, const sc_event &);
223 void next_trigger(const sc_time &, const sc_event_or_list &);
224 void next_trigger(double, sc_time_unit, const sc_event_or_list &);
225 void next_trigger(const sc_time &, const sc_event_and_list &);
226 void next_trigger(double, sc_time_unit, const sc_event_and_list &);
227
228 // Nonstandard
229 bool timed_out();
230
231 void wait();
232 void wait(int);
233 void wait(const sc_event &);
234 void wait(const sc_event_or_list &);
235 void wait(const sc_event_and_list &);
236 void wait(const sc_time &);
237 void wait(double, sc_time_unit);
238 void wait(const sc_time &, const sc_event &);
239 void wait(double, sc_time_unit, const sc_event &);
240 void wait(const sc_time &, const sc_event_or_list &);
241 void wait(double, sc_time_unit, const sc_event_or_list &);
242 void wait(const sc_time &, const sc_event_and_list &);
243 void wait(double, sc_time_unit, const sc_event_and_list &);
244
245 // Nonstandard
246 void halt();
247 void at_posedge(const sc_signal_in_if<bool> &);
249 void at_negedge(const sc_signal_in_if<bool> &);
251
253 virtual void end_of_elaboration() {}
254 virtual void start_of_simulation() {}
255 virtual void end_of_simulation() {}
256
257 private:
259
260 // Disabled
262 sc_module &operator = (const sc_module &) { return *this; }
263};
264
265void next_trigger();
266void next_trigger(const sc_event &);
267void next_trigger(const sc_event_or_list &);
268void next_trigger(const sc_event_and_list &);
269void next_trigger(const sc_time &);
270void next_trigger(double, sc_time_unit);
271void next_trigger(const sc_time &, const sc_event &);
272void next_trigger(double, sc_time_unit, const sc_event &);
273void next_trigger(const sc_time &, const sc_event_or_list &);
274void next_trigger(double, sc_time_unit, const sc_event_or_list &);
275void next_trigger(const sc_time &, const sc_event_and_list &);
276void next_trigger(double, sc_time_unit, const sc_event_and_list &);
277
278void wait();
279void wait(int);
280void wait(const sc_event &);
281void wait(const sc_event_or_list &);
282void wait(const sc_event_and_list &);
283void wait(const sc_time &);
284void wait(double, sc_time_unit);
285void wait(const sc_time &, const sc_event &);
286void wait(double, sc_time_unit, const sc_event &);
287void wait(const sc_time &, const sc_event_or_list &);
288void wait(double, sc_time_unit, const sc_event_or_list &);
289void wait(const sc_time &, const sc_event_and_list &);
290void wait(double, sc_time_unit, const sc_event_and_list &);
291
292// Nonstandard
293bool timed_out();
294
295#define SC_MODULE(name) struct name : ::sc_core::sc_module
296
297#define SC_CTOR(name) \
298 typedef name SC_CURRENT_USER_MODULE; \
299 name(::sc_core::sc_module_name)
300
301#define SC_HAS_PROCESS(name) typedef name SC_CURRENT_USER_MODULE
302
303#define SC_METHOD(name) \
304 { \
305 ::sc_gem5::Process *p = \
306 ::sc_gem5::newMethodProcess( \
307 #name, new ::sc_gem5::ProcessMemberFuncWrapper< \
308 SC_CURRENT_USER_MODULE>(this, \
309 &SC_CURRENT_USER_MODULE::name)); \
310 if (p) \
311 this->sensitive << p; \
312 }
313#define SC_THREAD(name) \
314 { \
315 ::sc_gem5::Process *p = \
316 ::sc_gem5::newThreadProcess( \
317 #name, new ::sc_gem5::ProcessMemberFuncWrapper< \
318 SC_CURRENT_USER_MODULE>(this, \
319 &SC_CURRENT_USER_MODULE::name)); \
320 if (p) \
321 this->sensitive << p; \
322 }
323#define SC_CTHREAD(name, clk) \
324 { \
325 ::sc_gem5::Process *p = \
326 ::sc_gem5::newCThreadProcess( \
327 #name, new ::sc_gem5::ProcessMemberFuncWrapper< \
328 SC_CURRENT_USER_MODULE>(this, \
329 &SC_CURRENT_USER_MODULE::name)); \
330 if (p) \
331 this->sensitive(p, clk); \
332 }
333
334// Nonstandard
335// Documentation for this is very scarce, but it looks like it's supposed to
336// stop the currently executing cthread, or if a cthread isn't running report
337// an error.
338void halt();
339void at_posedge(const sc_signal_in_if<bool> &);
340void at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &);
341void at_negedge(const sc_signal_in_if<bool> &);
342void at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &);
343
344const char *sc_gen_unique_name(const char *);
345
346// Nonstandard
347bool sc_hierarchical_name_exists(const char *name);
348
351
354
355// Nonstandard
356// Allocates a module of type x and records a pointer to it so that it gets
357// destructed automatically at the end of the simulation.
359#define SC_NEW(x) ::sc_core::sc_module_sc_new(new x);
360
361// Nonstandard
362#define SC_WAIT() \
363 ::sc_core::sc_set_location(__FILE__, __LINE__); \
364 ::sc_core::wait(); \
365 ::sc_core::sc_set_location(NULL, 0)
366
367// Nonstandard
368#define SC_WAITN(n) \
369 ::sc_core::sc_set_location(__FILE__, __LINE__); \
370 ::sc_core::wait(n); \
371 ::sc_core::sc_set_location(NULL, 0)
372
373// Nonstandard
374#define SC_WAIT_UNTIL(expr) \
375 do { SC_WAIT(); } while (!(expr))
376
377} // namespace sc_core
378
379#endif //__SYSTEMC_EXT_CORE_SC_MODULE_HH__
Ports are used to interface objects to each other.
Definition port.hh:62
sc_interface * interface() const
Definition sc_module.hh:95
sc_port_base * _port
Definition sc_module.hh:88
sc_interface * _interface
Definition sc_module.hh:87
sc_port_base * port() const
Definition sc_module.hh:96
sc_module(const sc_module &)
Definition sc_module.hh:261
virtual ~sc_module()
Definition sc_module.cc:122
void operator()(const sc_bind_proxy &p001, const sc_bind_proxy &p002=SC_BIND_PROXY_NIL, const sc_bind_proxy &p003=SC_BIND_PROXY_NIL, const sc_bind_proxy &p004=SC_BIND_PROXY_NIL, const sc_bind_proxy &p005=SC_BIND_PROXY_NIL, const sc_bind_proxy &p006=SC_BIND_PROXY_NIL, const sc_bind_proxy &p007=SC_BIND_PROXY_NIL, const sc_bind_proxy &p008=SC_BIND_PROXY_NIL, const sc_bind_proxy &p009=SC_BIND_PROXY_NIL, const sc_bind_proxy &p010=SC_BIND_PROXY_NIL, const sc_bind_proxy &p011=SC_BIND_PROXY_NIL, const sc_bind_proxy &p012=SC_BIND_PROXY_NIL, const sc_bind_proxy &p013=SC_BIND_PROXY_NIL, const sc_bind_proxy &p014=SC_BIND_PROXY_NIL, const sc_bind_proxy &p015=SC_BIND_PROXY_NIL, const sc_bind_proxy &p016=SC_BIND_PROXY_NIL, const sc_bind_proxy &p017=SC_BIND_PROXY_NIL, const sc_bind_proxy &p018=SC_BIND_PROXY_NIL, const sc_bind_proxy &p019=SC_BIND_PROXY_NIL, const sc_bind_proxy &p020=SC_BIND_PROXY_NIL, const sc_bind_proxy &p021=SC_BIND_PROXY_NIL, const sc_bind_proxy &p022=SC_BIND_PROXY_NIL, const sc_bind_proxy &p023=SC_BIND_PROXY_NIL, const sc_bind_proxy &p024=SC_BIND_PROXY_NIL, const sc_bind_proxy &p025=SC_BIND_PROXY_NIL, const sc_bind_proxy &p026=SC_BIND_PROXY_NIL, const sc_bind_proxy &p027=SC_BIND_PROXY_NIL, const sc_bind_proxy &p028=SC_BIND_PROXY_NIL, const sc_bind_proxy &p029=SC_BIND_PROXY_NIL, const sc_bind_proxy &p030=SC_BIND_PROXY_NIL, const sc_bind_proxy &p031=SC_BIND_PROXY_NIL, const sc_bind_proxy &p032=SC_BIND_PROXY_NIL, const sc_bind_proxy &p033=SC_BIND_PROXY_NIL, const sc_bind_proxy &p034=SC_BIND_PROXY_NIL, const sc_bind_proxy &p035=SC_BIND_PROXY_NIL, const sc_bind_proxy &p036=SC_BIND_PROXY_NIL, const sc_bind_proxy &p037=SC_BIND_PROXY_NIL, const sc_bind_proxy &p038=SC_BIND_PROXY_NIL, const sc_bind_proxy &p039=SC_BIND_PROXY_NIL, const sc_bind_proxy &p040=SC_BIND_PROXY_NIL, const sc_bind_proxy &p041=SC_BIND_PROXY_NIL, const sc_bind_proxy &p042=SC_BIND_PROXY_NIL, const sc_bind_proxy &p043=SC_BIND_PROXY_NIL, const sc_bind_proxy &p044=SC_BIND_PROXY_NIL, const sc_bind_proxy &p045=SC_BIND_PROXY_NIL, const sc_bind_proxy &p046=SC_BIND_PROXY_NIL, const sc_bind_proxy &p047=SC_BIND_PROXY_NIL, const sc_bind_proxy &p048=SC_BIND_PROXY_NIL, const sc_bind_proxy &p049=SC_BIND_PROXY_NIL, const sc_bind_proxy &p050=SC_BIND_PROXY_NIL, const sc_bind_proxy &p051=SC_BIND_PROXY_NIL, const sc_bind_proxy &p052=SC_BIND_PROXY_NIL, const sc_bind_proxy &p053=SC_BIND_PROXY_NIL, const sc_bind_proxy &p054=SC_BIND_PROXY_NIL, const sc_bind_proxy &p055=SC_BIND_PROXY_NIL, const sc_bind_proxy &p056=SC_BIND_PROXY_NIL, const sc_bind_proxy &p057=SC_BIND_PROXY_NIL, const sc_bind_proxy &p058=SC_BIND_PROXY_NIL, const sc_bind_proxy &p059=SC_BIND_PROXY_NIL, const sc_bind_proxy &p060=SC_BIND_PROXY_NIL, const sc_bind_proxy &p061=SC_BIND_PROXY_NIL, const sc_bind_proxy &p062=SC_BIND_PROXY_NIL, const sc_bind_proxy &p063=SC_BIND_PROXY_NIL, const sc_bind_proxy &p064=SC_BIND_PROXY_NIL)
Definition sc_module.cc:125
sc_sensitive sensitive
Definition sc_module.hh:210
virtual const std::vector< sc_object * > & get_child_objects() const
Definition sc_module.cc:245
void async_reset_signal_is(const sc_in< bool > &, bool)
Definition sc_module.cc:311
virtual const std::vector< sc_event * > & get_child_events() const
Definition sc_module.cc:251
void set_stack_size(size_t)
Definition sc_module.cc:345
void reset_signal_is(const sc_in< bool > &, bool)
Definition sc_module.cc:286
void at_posedge(const sc_signal_in_if< bool > &)
Definition sc_module.cc:513
virtual void end_of_simulation()
Definition sc_module.hh:255
virtual void before_end_of_elaboration()
Definition sc_module.hh:252
virtual void start_of_simulation()
Definition sc_module.hh:254
sc_module & operator=(const sc_module &)
Definition sc_module.hh:262
sc_module & operator<<(sc_interface &)
Definition sc_module.cc:217
virtual const char * kind() const
Definition sc_module.hh:113
virtual void end_of_elaboration()
Definition sc_module.hh:253
sc_gem5::Module * _gem5_module
Definition sc_module.hh:258
virtual gem5::Port & gem5_getPort(const std::string &if_name, int idx=-1)
Definition sc_module.cc:117
sc_module & operator,(sc_interface &)
Definition sc_module.cc:231
void at_negedge(const sc_signal_in_if< bool > &)
Definition sc_module.cc:525
STL vector class.
Definition stl.hh:37
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
bool sc_start_of_simulation_invoked()
Definition sc_module.cc:846
const sc_bind_proxy SC_BIND_PROXY_NIL
Definition sc_module.cc:114
sc_module * sc_module_sc_new(sc_module *mod)
Definition sc_module.cc:858
sc_module sc_behavior
Definition sc_module.hh:349
void at_negedge(const sc_signal_in_if< bool > &s)
Definition sc_module.cc:802
bool sc_end_of_simulation_invoked()
Definition sc_module.cc:852
void next_trigger()
Definition sc_module.cc:538
bool timed_out()
Definition sc_module.cc:626
void halt()
Definition sc_module.cc:777
void at_posedge(const sc_signal_in_if< bool > &s)
Definition sc_module.cc:784
bool sc_hierarchical_name_exists(const char *name)
Definition sc_module.cc:839
sc_time_unit
Definition sc_time.hh:40
const char * sc_gen_unique_name(const char *seed)
Definition sc_module.cc:820
void wait()
Definition sc_module.cc:653
sc_module sc_channel
Definition sc_module.hh:350
Process * newCThreadProcess(const char *name, ProcessFuncWrapper *func)
Definition sc_module.cc:84
Process * newMethodProcess(const char *name, ProcessFuncWrapper *func)
Definition sc_module.cc:54
Process * newThreadProcess(const char *name, ProcessFuncWrapper *func)
Definition sc_module.cc:69
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0