sc_module.cc (13146:3539fe351218) sc_module.cc (13155:4e77f1d0cdc3)
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#include <memory>
31#include <string>
32#include <vector>
33
34#include "base/logging.hh"
35#include "systemc/core/kernel.hh"
36#include "systemc/core/module.hh"
37#include "systemc/core/process_types.hh"
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#include <memory>
31#include <string>
32#include <vector>
33
34#include "base/logging.hh"
35#include "systemc/core/kernel.hh"
36#include "systemc/core/module.hh"
37#include "systemc/core/process_types.hh"
38#include "systemc/ext/channel/sc_signal_in_if.hh"
38#include "systemc/ext/core/sc_module.hh"
39#include "systemc/ext/core/sc_module_name.hh"
39#include "systemc/ext/core/sc_module.hh"
40#include "systemc/ext/core/sc_module_name.hh"
41#include "systemc/ext/dt/bit/sc_logic.hh"
40#include "systemc/ext/utils/sc_report_handler.hh"
41
42namespace sc_gem5
43{
44
45Process *
46newMethodProcess(const char *name, ProcessFuncWrapper *func)
47{
48 Method *p = new Method(name, func);
49 if (::sc_core::sc_is_running()) {
50 std::string name = p->name();
51 delete p;
52 SC_REPORT_ERROR("(E541) call to SC_METHOD in sc_module while "
53 "simulation running", name.c_str());
54 return nullptr;
55 }
56 scheduler.reg(p);
57 return p;
58}
59
60Process *
61newThreadProcess(const char *name, ProcessFuncWrapper *func)
62{
63 Thread *p = new Thread(name, func);
64 if (::sc_core::sc_is_running()) {
65 std::string name = p->name();
66 delete p;
67 SC_REPORT_ERROR("(E542) call to SC_THREAD in sc_module while "
68 "simulation running", name.c_str());
69 return nullptr;
70 }
71 scheduler.reg(p);
72 return p;
73}
74
75Process *
76newCThreadProcess(const char *name, ProcessFuncWrapper *func)
77{
78 CThread *p = new CThread(name, func);
79 if (::sc_core::sc_is_running()) {
80 std::string name = p->name();
81 delete p;
82 SC_REPORT_ERROR("(E543) call to SC_CTHREAD in sc_module while "
83 "simulation running", name.c_str());
84 return nullptr;
85 }
86 scheduler.reg(p);
87 p->dontInitialize();
88 return p;
89}
90
91UniqueNameGen nameGen;
92
93} // namespace sc_gem5
94
95namespace sc_core
96{
97
98sc_bind_proxy::sc_bind_proxy(sc_interface &_interface) :
99 _interface(&_interface), _port(nullptr)
100{}
101
102sc_bind_proxy::sc_bind_proxy(sc_port_base &_port) :
103 _interface(nullptr), _port(&_port)
104{}
105
106const sc_bind_proxy SC_BIND_PROXY_NUL(*(sc_port_base *)nullptr);
107
108sc_module::~sc_module() { delete _gem5_module; }
109
110const sc_bind_proxy SC_BIND_PROXY_NIL(*(sc_port_base *)nullptr);
111
112void
113sc_module::operator () (const sc_bind_proxy &p001,
114 const sc_bind_proxy &p002,
115 const sc_bind_proxy &p003,
116 const sc_bind_proxy &p004,
117 const sc_bind_proxy &p005,
118 const sc_bind_proxy &p006,
119 const sc_bind_proxy &p007,
120 const sc_bind_proxy &p008,
121 const sc_bind_proxy &p009,
122 const sc_bind_proxy &p010,
123 const sc_bind_proxy &p011,
124 const sc_bind_proxy &p012,
125 const sc_bind_proxy &p013,
126 const sc_bind_proxy &p014,
127 const sc_bind_proxy &p015,
128 const sc_bind_proxy &p016,
129 const sc_bind_proxy &p017,
130 const sc_bind_proxy &p018,
131 const sc_bind_proxy &p019,
132 const sc_bind_proxy &p020,
133 const sc_bind_proxy &p021,
134 const sc_bind_proxy &p022,
135 const sc_bind_proxy &p023,
136 const sc_bind_proxy &p024,
137 const sc_bind_proxy &p025,
138 const sc_bind_proxy &p026,
139 const sc_bind_proxy &p027,
140 const sc_bind_proxy &p028,
141 const sc_bind_proxy &p029,
142 const sc_bind_proxy &p030,
143 const sc_bind_proxy &p031,
144 const sc_bind_proxy &p032,
145 const sc_bind_proxy &p033,
146 const sc_bind_proxy &p034,
147 const sc_bind_proxy &p035,
148 const sc_bind_proxy &p036,
149 const sc_bind_proxy &p037,
150 const sc_bind_proxy &p038,
151 const sc_bind_proxy &p039,
152 const sc_bind_proxy &p040,
153 const sc_bind_proxy &p041,
154 const sc_bind_proxy &p042,
155 const sc_bind_proxy &p043,
156 const sc_bind_proxy &p044,
157 const sc_bind_proxy &p045,
158 const sc_bind_proxy &p046,
159 const sc_bind_proxy &p047,
160 const sc_bind_proxy &p048,
161 const sc_bind_proxy &p049,
162 const sc_bind_proxy &p050,
163 const sc_bind_proxy &p051,
164 const sc_bind_proxy &p052,
165 const sc_bind_proxy &p053,
166 const sc_bind_proxy &p054,
167 const sc_bind_proxy &p055,
168 const sc_bind_proxy &p056,
169 const sc_bind_proxy &p057,
170 const sc_bind_proxy &p058,
171 const sc_bind_proxy &p059,
172 const sc_bind_proxy &p060,
173 const sc_bind_proxy &p061,
174 const sc_bind_proxy &p062,
175 const sc_bind_proxy &p063,
176 const sc_bind_proxy &p064)
177{
178 std::vector<const ::sc_core::sc_bind_proxy *> proxies;
179 auto insert = [&proxies](const ::sc_core::sc_bind_proxy &p) -> bool {
180 if (!p.port() && !p.interface())
181 return false;
182 proxies.push_back(&p);
183 return true;
184 };
185 insert(p001) && insert(p002) && insert(p003) && insert(p004) &&
186 insert(p005) && insert(p006) && insert(p007) && insert(p008) &&
187 insert(p009) && insert(p010) && insert(p011) && insert(p012) &&
188 insert(p013) && insert(p014) && insert(p015) && insert(p016) &&
189 insert(p017) && insert(p018) && insert(p019) && insert(p020) &&
190 insert(p021) && insert(p022) && insert(p023) && insert(p024) &&
191 insert(p025) && insert(p026) && insert(p027) && insert(p028) &&
192 insert(p029) && insert(p030) && insert(p031) && insert(p032) &&
193 insert(p033) && insert(p034) && insert(p035) && insert(p036) &&
194 insert(p037) && insert(p038) && insert(p039) && insert(p040) &&
195 insert(p041) && insert(p042) && insert(p043) && insert(p044) &&
196 insert(p045) && insert(p046) && insert(p047) && insert(p048) &&
197 insert(p049) && insert(p050) && insert(p051) && insert(p052) &&
198 insert(p053) && insert(p054) && insert(p055) && insert(p056) &&
199 insert(p057) && insert(p058) && insert(p059) && insert(p060) &&
200 insert(p061) && insert(p062) && insert(p063) && insert(p064);
201 _gem5_module->bindPorts(proxies);
202}
203
204const std::vector<sc_object *> &
205sc_module::get_child_objects() const
206{
207 return _gem5_module->obj()->get_child_objects();
208}
209
210const std::vector<sc_event *> &
211sc_module::get_child_events() const
212{
213 return _gem5_module->obj()->get_child_events();
214}
215
216sc_module::sc_module() :
217 sc_object(sc_gem5::newModuleChecked()->name()),
218 _gem5_module(sc_gem5::currentModule())
219{}
220
221sc_module::sc_module(const sc_module_name &) : sc_module() {}
222sc_module::sc_module(const char *_name) : sc_module(sc_module_name(_name)) {}
223sc_module::sc_module(const std::string &_name) :
224 sc_module(sc_module_name(_name.c_str()))
225{}
226
227void
228sc_module::reset_signal_is(const sc_in<bool> &, bool)
229{
230 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
231}
232
233void
234sc_module::reset_signal_is(const sc_inout<bool> &, bool)
235{
236 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
237}
238
239void
240sc_module::reset_signal_is(const sc_out<bool> &, bool)
241{
242 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
243}
244
245void
246sc_module::reset_signal_is(const sc_signal_in_if<bool> &, bool)
247{
248 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
249}
250
251
252void
253sc_module::async_reset_signal_is(const sc_in<bool> &, bool)
254{
255 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
256}
257
258void
259sc_module::async_reset_signal_is(const sc_inout<bool> &, bool)
260{
261 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
262}
263
264void
265sc_module::async_reset_signal_is(const sc_out<bool> &, bool)
266{
267 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
268}
269
270void
271sc_module::async_reset_signal_is(const sc_signal_in_if<bool> &, bool)
272{
273 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
274}
275
276
277void
278sc_module::dont_initialize()
279{
280 ::sc_gem5::Process::newest()->dontInitialize();
281}
282
283void
284sc_module::set_stack_size(size_t size)
285{
286 ::sc_gem5::Process::newest()->setStackSize(size);
287}
288
289
290void sc_module::next_trigger() { ::sc_core::next_trigger(); }
291
292void
293sc_module::next_trigger(const sc_event &e)
294{
295 ::sc_core::next_trigger(e);
296}
297
298void
299sc_module::next_trigger(const sc_event_or_list &eol)
300{
301 ::sc_core::next_trigger(eol);
302}
303
304void
305sc_module::next_trigger(const sc_event_and_list &eal)
306{
307 ::sc_core::next_trigger(eal);
308}
309
310void
311sc_module::next_trigger(const sc_time &t)
312{
313 ::sc_core::next_trigger(t);
314}
315
316void
317sc_module::next_trigger(double d, sc_time_unit u)
318{
319 ::sc_core::next_trigger(d, u);
320}
321
322void
323sc_module::next_trigger(const sc_time &t, const sc_event &e)
324{
325 ::sc_core::next_trigger(t, e);
326}
327
328void
329sc_module::next_trigger(double d, sc_time_unit u, const sc_event &e)
330{
331 ::sc_core::next_trigger(d, u, e);
332}
333
334void
335sc_module::next_trigger(const sc_time &t, const sc_event_or_list &eol)
336{
337 ::sc_core::next_trigger(t, eol);
338}
339
340void
341sc_module::next_trigger(double d, sc_time_unit u, const sc_event_or_list &eol)
342{
343 ::sc_core::next_trigger(d, u, eol);
344}
345
346void
347sc_module::next_trigger(const sc_time &t, const sc_event_and_list &eal)
348{
349 ::sc_core::next_trigger(t, eal);
350}
351
352void
353sc_module::next_trigger(double d, sc_time_unit u, const sc_event_and_list &eal)
354{
355 ::sc_core::next_trigger(d, u, eal);
356}
357
358
359bool
360sc_module::timed_out()
361{
362 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
363 return false;
364}
365
366
367void
368sc_module::wait()
369{
370 ::sc_core::wait();
371}
372
373void
374sc_module::wait(int i)
375{
376 ::sc_core::wait(i);
377}
378
379void
380sc_module::wait(const sc_event &e)
381{
382 ::sc_core::wait(e);
383}
384
385void
386sc_module::wait(const sc_event_or_list &eol)
387{
388 ::sc_core::wait(eol);
389}
390
391void
392sc_module::wait(const sc_event_and_list &eal)
393{
394 ::sc_core::wait(eal);
395}
396
397void
398sc_module::wait(const sc_time &t)
399{
400 ::sc_core::wait(t);
401}
402
403void
404sc_module::wait(double d, sc_time_unit u)
405{
406 ::sc_core::wait(d, u);
407}
408
409void
410sc_module::wait(const sc_time &t, const sc_event &e)
411{
412 ::sc_core::wait(t, e);
413}
414
415void
416sc_module::wait(double d, sc_time_unit u, const sc_event &e)
417{
418 ::sc_core::wait(d, u, e);
419}
420
421void
422sc_module::wait(const sc_time &t, const sc_event_or_list &eol)
423{
424 ::sc_core::wait(t, eol);
425}
426
427void
428sc_module::wait(double d, sc_time_unit u, const sc_event_or_list &eol)
429{
430 ::sc_core::wait(d, u, eol);
431}
432
433void
434sc_module::wait(const sc_time &t, const sc_event_and_list &eal)
435{
436 ::sc_core::wait(t, eal);
437}
438
439void
440sc_module::wait(double d, sc_time_unit u, const sc_event_and_list &eal)
441{
442 ::sc_core::wait(d, u, eal);
443}
444
445
446void
447sc_module::halt()
448{
449 ::sc_core::halt();
450}
451
452void
453sc_module::at_posedge(const sc_signal_in_if<bool> &s)
454{
455 ::sc_core::at_posedge(s);
456}
457
458void
459sc_module::at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &s)
460{
461 ::sc_core::at_posedge(s);
462}
463
464void
465sc_module::at_negedge(const sc_signal_in_if<bool> &s)
466{
467 ::sc_core::at_negedge(s);
468}
469
470void
471sc_module::at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &s)
472{
473 ::sc_core::at_negedge(s);
474}
475
476
477void
478next_trigger()
479{
480 sc_gem5::Process *p = sc_gem5::scheduler.current();
481 p->setDynamic(nullptr);
482}
483
484void
485next_trigger(const sc_event &e)
486{
487 sc_gem5::Process *p = sc_gem5::scheduler.current();
488 p->setDynamic(new ::sc_gem5::SensitivityEvent(p, &e));
489}
490
491void
492next_trigger(const sc_event_or_list &eol)
493{
494 sc_gem5::Process *p = sc_gem5::scheduler.current();
495 p->setDynamic(new ::sc_gem5::SensitivityEventOrList(p, &eol));
496}
497
498void
499next_trigger(const sc_event_and_list &eal)
500{
501 sc_gem5::Process *p = sc_gem5::scheduler.current();
502 p->setDynamic(new ::sc_gem5::SensitivityEventAndList(p, &eal));
503}
504
505void
506next_trigger(const sc_time &t)
507{
508 sc_gem5::Process *p = sc_gem5::scheduler.current();
509 p->setDynamic(new ::sc_gem5::SensitivityTimeout(p, t));
510}
511
512void
513next_trigger(double d, sc_time_unit u)
514{
515 next_trigger(sc_time(d, u));
516}
517
518void
519next_trigger(const sc_time &t, const sc_event &e)
520{
521 sc_gem5::Process *p = sc_gem5::scheduler.current();
522 p->setDynamic(new ::sc_gem5::SensitivityTimeoutAndEvent(p, t, &e));
523}
524
525void
526next_trigger(double d, sc_time_unit u, const sc_event &e)
527{
528 next_trigger(sc_time(d, u), e);
529}
530
531void
532next_trigger(const sc_time &t, const sc_event_or_list &eol)
533{
534 sc_gem5::Process *p = sc_gem5::scheduler.current();
535 p->setDynamic(
536 new ::sc_gem5::SensitivityTimeoutAndEventOrList(p, t, &eol));
537}
538
539void
540next_trigger(double d, sc_time_unit u, const sc_event_or_list &eol)
541{
542 next_trigger(sc_time(d, u), eol);
543}
544
545void
546next_trigger(const sc_time &t, const sc_event_and_list &eal)
547{
548 sc_gem5::Process *p = sc_gem5::scheduler.current();
549 p->setDynamic(
550 new ::sc_gem5::SensitivityTimeoutAndEventAndList(p, t, &eal));
551}
552
553void
554next_trigger(double d, sc_time_unit u, const sc_event_and_list &eal)
555{
556 next_trigger(sc_time(d, u), eal);
557}
558
559bool
560timed_out()
561{
562 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
563 return false;
564}
565
566
567void
568wait()
569{
570 sc_gem5::Process *p = sc_gem5::scheduler.current();
571 p->setDynamic(nullptr);
572 sc_gem5::scheduler.yield();
573}
574
575void
576wait(int n)
577{
578 if (n <= 0) {
579 std::string msg = csprintf("n = %d", n);
580 SC_REPORT_ERROR("(E525) wait(n) is only valid for n > 0", msg.c_str());
581 }
582 for (int i = 0; i < n; i++)
583 wait();
584}
585
586void
587wait(const sc_event &e)
588{
589 sc_gem5::Process *p = sc_gem5::scheduler.current();
590 p->setDynamic(new ::sc_gem5::SensitivityEvent(p, &e));
591 sc_gem5::scheduler.yield();
592}
593
594void
595wait(const sc_event_or_list &eol)
596{
597 sc_gem5::Process *p = sc_gem5::scheduler.current();
598 p->setDynamic(new ::sc_gem5::SensitivityEventOrList(p, &eol));
599 sc_gem5::scheduler.yield();
600}
601
602void
603wait(const sc_event_and_list &eal)
604{
605 sc_gem5::Process *p = sc_gem5::scheduler.current();
606 p->setDynamic(new ::sc_gem5::SensitivityEventAndList(p, &eal));
607 sc_gem5::scheduler.yield();
608}
609
610void
611wait(const sc_time &t)
612{
613 sc_gem5::Process *p = sc_gem5::scheduler.current();
614 p->setDynamic(new ::sc_gem5::SensitivityTimeout(p, t));
615 sc_gem5::scheduler.yield();
616}
617
618void
619wait(double d, sc_time_unit u)
620{
621 wait(sc_time(d, u));
622}
623
624void
625wait(const sc_time &t, const sc_event &e)
626{
627 sc_gem5::Process *p = sc_gem5::scheduler.current();
628 p->setDynamic(new ::sc_gem5::SensitivityTimeoutAndEvent(p, t, &e));
629 sc_gem5::scheduler.yield();
630}
631
632void
633wait(double d, sc_time_unit u, const sc_event &e)
634{
635 wait(sc_time(d, u), e);
636}
637
638void
639wait(const sc_time &t, const sc_event_or_list &eol)
640{
641 sc_gem5::Process *p = sc_gem5::scheduler.current();
642 p->setDynamic(
643 new ::sc_gem5::SensitivityTimeoutAndEventOrList(p, t, &eol));
644 sc_gem5::scheduler.yield();
645}
646
647void
648wait(double d, sc_time_unit u, const sc_event_or_list &eol)
649{
650 wait(sc_time(d, u), eol);
651}
652
653void
654wait(const sc_time &t, const sc_event_and_list &eal)
655{
656 sc_gem5::Process *p = sc_gem5::scheduler.current();
657 p->setDynamic(
658 new ::sc_gem5::SensitivityTimeoutAndEventAndList(p, t, &eal));
659 sc_gem5::scheduler.yield();
660}
661
662void
663wait(double d, sc_time_unit u, const sc_event_and_list &eal)
664{
665 wait(sc_time(d, u), eal);
666}
667
668void
669halt()
670{
671 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
672}
673
674void
42#include "systemc/ext/utils/sc_report_handler.hh"
43
44namespace sc_gem5
45{
46
47Process *
48newMethodProcess(const char *name, ProcessFuncWrapper *func)
49{
50 Method *p = new Method(name, func);
51 if (::sc_core::sc_is_running()) {
52 std::string name = p->name();
53 delete p;
54 SC_REPORT_ERROR("(E541) call to SC_METHOD in sc_module while "
55 "simulation running", name.c_str());
56 return nullptr;
57 }
58 scheduler.reg(p);
59 return p;
60}
61
62Process *
63newThreadProcess(const char *name, ProcessFuncWrapper *func)
64{
65 Thread *p = new Thread(name, func);
66 if (::sc_core::sc_is_running()) {
67 std::string name = p->name();
68 delete p;
69 SC_REPORT_ERROR("(E542) call to SC_THREAD in sc_module while "
70 "simulation running", name.c_str());
71 return nullptr;
72 }
73 scheduler.reg(p);
74 return p;
75}
76
77Process *
78newCThreadProcess(const char *name, ProcessFuncWrapper *func)
79{
80 CThread *p = new CThread(name, func);
81 if (::sc_core::sc_is_running()) {
82 std::string name = p->name();
83 delete p;
84 SC_REPORT_ERROR("(E543) call to SC_CTHREAD in sc_module while "
85 "simulation running", name.c_str());
86 return nullptr;
87 }
88 scheduler.reg(p);
89 p->dontInitialize();
90 return p;
91}
92
93UniqueNameGen nameGen;
94
95} // namespace sc_gem5
96
97namespace sc_core
98{
99
100sc_bind_proxy::sc_bind_proxy(sc_interface &_interface) :
101 _interface(&_interface), _port(nullptr)
102{}
103
104sc_bind_proxy::sc_bind_proxy(sc_port_base &_port) :
105 _interface(nullptr), _port(&_port)
106{}
107
108const sc_bind_proxy SC_BIND_PROXY_NUL(*(sc_port_base *)nullptr);
109
110sc_module::~sc_module() { delete _gem5_module; }
111
112const sc_bind_proxy SC_BIND_PROXY_NIL(*(sc_port_base *)nullptr);
113
114void
115sc_module::operator () (const sc_bind_proxy &p001,
116 const sc_bind_proxy &p002,
117 const sc_bind_proxy &p003,
118 const sc_bind_proxy &p004,
119 const sc_bind_proxy &p005,
120 const sc_bind_proxy &p006,
121 const sc_bind_proxy &p007,
122 const sc_bind_proxy &p008,
123 const sc_bind_proxy &p009,
124 const sc_bind_proxy &p010,
125 const sc_bind_proxy &p011,
126 const sc_bind_proxy &p012,
127 const sc_bind_proxy &p013,
128 const sc_bind_proxy &p014,
129 const sc_bind_proxy &p015,
130 const sc_bind_proxy &p016,
131 const sc_bind_proxy &p017,
132 const sc_bind_proxy &p018,
133 const sc_bind_proxy &p019,
134 const sc_bind_proxy &p020,
135 const sc_bind_proxy &p021,
136 const sc_bind_proxy &p022,
137 const sc_bind_proxy &p023,
138 const sc_bind_proxy &p024,
139 const sc_bind_proxy &p025,
140 const sc_bind_proxy &p026,
141 const sc_bind_proxy &p027,
142 const sc_bind_proxy &p028,
143 const sc_bind_proxy &p029,
144 const sc_bind_proxy &p030,
145 const sc_bind_proxy &p031,
146 const sc_bind_proxy &p032,
147 const sc_bind_proxy &p033,
148 const sc_bind_proxy &p034,
149 const sc_bind_proxy &p035,
150 const sc_bind_proxy &p036,
151 const sc_bind_proxy &p037,
152 const sc_bind_proxy &p038,
153 const sc_bind_proxy &p039,
154 const sc_bind_proxy &p040,
155 const sc_bind_proxy &p041,
156 const sc_bind_proxy &p042,
157 const sc_bind_proxy &p043,
158 const sc_bind_proxy &p044,
159 const sc_bind_proxy &p045,
160 const sc_bind_proxy &p046,
161 const sc_bind_proxy &p047,
162 const sc_bind_proxy &p048,
163 const sc_bind_proxy &p049,
164 const sc_bind_proxy &p050,
165 const sc_bind_proxy &p051,
166 const sc_bind_proxy &p052,
167 const sc_bind_proxy &p053,
168 const sc_bind_proxy &p054,
169 const sc_bind_proxy &p055,
170 const sc_bind_proxy &p056,
171 const sc_bind_proxy &p057,
172 const sc_bind_proxy &p058,
173 const sc_bind_proxy &p059,
174 const sc_bind_proxy &p060,
175 const sc_bind_proxy &p061,
176 const sc_bind_proxy &p062,
177 const sc_bind_proxy &p063,
178 const sc_bind_proxy &p064)
179{
180 std::vector<const ::sc_core::sc_bind_proxy *> proxies;
181 auto insert = [&proxies](const ::sc_core::sc_bind_proxy &p) -> bool {
182 if (!p.port() && !p.interface())
183 return false;
184 proxies.push_back(&p);
185 return true;
186 };
187 insert(p001) && insert(p002) && insert(p003) && insert(p004) &&
188 insert(p005) && insert(p006) && insert(p007) && insert(p008) &&
189 insert(p009) && insert(p010) && insert(p011) && insert(p012) &&
190 insert(p013) && insert(p014) && insert(p015) && insert(p016) &&
191 insert(p017) && insert(p018) && insert(p019) && insert(p020) &&
192 insert(p021) && insert(p022) && insert(p023) && insert(p024) &&
193 insert(p025) && insert(p026) && insert(p027) && insert(p028) &&
194 insert(p029) && insert(p030) && insert(p031) && insert(p032) &&
195 insert(p033) && insert(p034) && insert(p035) && insert(p036) &&
196 insert(p037) && insert(p038) && insert(p039) && insert(p040) &&
197 insert(p041) && insert(p042) && insert(p043) && insert(p044) &&
198 insert(p045) && insert(p046) && insert(p047) && insert(p048) &&
199 insert(p049) && insert(p050) && insert(p051) && insert(p052) &&
200 insert(p053) && insert(p054) && insert(p055) && insert(p056) &&
201 insert(p057) && insert(p058) && insert(p059) && insert(p060) &&
202 insert(p061) && insert(p062) && insert(p063) && insert(p064);
203 _gem5_module->bindPorts(proxies);
204}
205
206const std::vector<sc_object *> &
207sc_module::get_child_objects() const
208{
209 return _gem5_module->obj()->get_child_objects();
210}
211
212const std::vector<sc_event *> &
213sc_module::get_child_events() const
214{
215 return _gem5_module->obj()->get_child_events();
216}
217
218sc_module::sc_module() :
219 sc_object(sc_gem5::newModuleChecked()->name()),
220 _gem5_module(sc_gem5::currentModule())
221{}
222
223sc_module::sc_module(const sc_module_name &) : sc_module() {}
224sc_module::sc_module(const char *_name) : sc_module(sc_module_name(_name)) {}
225sc_module::sc_module(const std::string &_name) :
226 sc_module(sc_module_name(_name.c_str()))
227{}
228
229void
230sc_module::reset_signal_is(const sc_in<bool> &, bool)
231{
232 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
233}
234
235void
236sc_module::reset_signal_is(const sc_inout<bool> &, bool)
237{
238 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
239}
240
241void
242sc_module::reset_signal_is(const sc_out<bool> &, bool)
243{
244 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
245}
246
247void
248sc_module::reset_signal_is(const sc_signal_in_if<bool> &, bool)
249{
250 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
251}
252
253
254void
255sc_module::async_reset_signal_is(const sc_in<bool> &, bool)
256{
257 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
258}
259
260void
261sc_module::async_reset_signal_is(const sc_inout<bool> &, bool)
262{
263 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
264}
265
266void
267sc_module::async_reset_signal_is(const sc_out<bool> &, bool)
268{
269 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
270}
271
272void
273sc_module::async_reset_signal_is(const sc_signal_in_if<bool> &, bool)
274{
275 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
276}
277
278
279void
280sc_module::dont_initialize()
281{
282 ::sc_gem5::Process::newest()->dontInitialize();
283}
284
285void
286sc_module::set_stack_size(size_t size)
287{
288 ::sc_gem5::Process::newest()->setStackSize(size);
289}
290
291
292void sc_module::next_trigger() { ::sc_core::next_trigger(); }
293
294void
295sc_module::next_trigger(const sc_event &e)
296{
297 ::sc_core::next_trigger(e);
298}
299
300void
301sc_module::next_trigger(const sc_event_or_list &eol)
302{
303 ::sc_core::next_trigger(eol);
304}
305
306void
307sc_module::next_trigger(const sc_event_and_list &eal)
308{
309 ::sc_core::next_trigger(eal);
310}
311
312void
313sc_module::next_trigger(const sc_time &t)
314{
315 ::sc_core::next_trigger(t);
316}
317
318void
319sc_module::next_trigger(double d, sc_time_unit u)
320{
321 ::sc_core::next_trigger(d, u);
322}
323
324void
325sc_module::next_trigger(const sc_time &t, const sc_event &e)
326{
327 ::sc_core::next_trigger(t, e);
328}
329
330void
331sc_module::next_trigger(double d, sc_time_unit u, const sc_event &e)
332{
333 ::sc_core::next_trigger(d, u, e);
334}
335
336void
337sc_module::next_trigger(const sc_time &t, const sc_event_or_list &eol)
338{
339 ::sc_core::next_trigger(t, eol);
340}
341
342void
343sc_module::next_trigger(double d, sc_time_unit u, const sc_event_or_list &eol)
344{
345 ::sc_core::next_trigger(d, u, eol);
346}
347
348void
349sc_module::next_trigger(const sc_time &t, const sc_event_and_list &eal)
350{
351 ::sc_core::next_trigger(t, eal);
352}
353
354void
355sc_module::next_trigger(double d, sc_time_unit u, const sc_event_and_list &eal)
356{
357 ::sc_core::next_trigger(d, u, eal);
358}
359
360
361bool
362sc_module::timed_out()
363{
364 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
365 return false;
366}
367
368
369void
370sc_module::wait()
371{
372 ::sc_core::wait();
373}
374
375void
376sc_module::wait(int i)
377{
378 ::sc_core::wait(i);
379}
380
381void
382sc_module::wait(const sc_event &e)
383{
384 ::sc_core::wait(e);
385}
386
387void
388sc_module::wait(const sc_event_or_list &eol)
389{
390 ::sc_core::wait(eol);
391}
392
393void
394sc_module::wait(const sc_event_and_list &eal)
395{
396 ::sc_core::wait(eal);
397}
398
399void
400sc_module::wait(const sc_time &t)
401{
402 ::sc_core::wait(t);
403}
404
405void
406sc_module::wait(double d, sc_time_unit u)
407{
408 ::sc_core::wait(d, u);
409}
410
411void
412sc_module::wait(const sc_time &t, const sc_event &e)
413{
414 ::sc_core::wait(t, e);
415}
416
417void
418sc_module::wait(double d, sc_time_unit u, const sc_event &e)
419{
420 ::sc_core::wait(d, u, e);
421}
422
423void
424sc_module::wait(const sc_time &t, const sc_event_or_list &eol)
425{
426 ::sc_core::wait(t, eol);
427}
428
429void
430sc_module::wait(double d, sc_time_unit u, const sc_event_or_list &eol)
431{
432 ::sc_core::wait(d, u, eol);
433}
434
435void
436sc_module::wait(const sc_time &t, const sc_event_and_list &eal)
437{
438 ::sc_core::wait(t, eal);
439}
440
441void
442sc_module::wait(double d, sc_time_unit u, const sc_event_and_list &eal)
443{
444 ::sc_core::wait(d, u, eal);
445}
446
447
448void
449sc_module::halt()
450{
451 ::sc_core::halt();
452}
453
454void
455sc_module::at_posedge(const sc_signal_in_if<bool> &s)
456{
457 ::sc_core::at_posedge(s);
458}
459
460void
461sc_module::at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &s)
462{
463 ::sc_core::at_posedge(s);
464}
465
466void
467sc_module::at_negedge(const sc_signal_in_if<bool> &s)
468{
469 ::sc_core::at_negedge(s);
470}
471
472void
473sc_module::at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &s)
474{
475 ::sc_core::at_negedge(s);
476}
477
478
479void
480next_trigger()
481{
482 sc_gem5::Process *p = sc_gem5::scheduler.current();
483 p->setDynamic(nullptr);
484}
485
486void
487next_trigger(const sc_event &e)
488{
489 sc_gem5::Process *p = sc_gem5::scheduler.current();
490 p->setDynamic(new ::sc_gem5::SensitivityEvent(p, &e));
491}
492
493void
494next_trigger(const sc_event_or_list &eol)
495{
496 sc_gem5::Process *p = sc_gem5::scheduler.current();
497 p->setDynamic(new ::sc_gem5::SensitivityEventOrList(p, &eol));
498}
499
500void
501next_trigger(const sc_event_and_list &eal)
502{
503 sc_gem5::Process *p = sc_gem5::scheduler.current();
504 p->setDynamic(new ::sc_gem5::SensitivityEventAndList(p, &eal));
505}
506
507void
508next_trigger(const sc_time &t)
509{
510 sc_gem5::Process *p = sc_gem5::scheduler.current();
511 p->setDynamic(new ::sc_gem5::SensitivityTimeout(p, t));
512}
513
514void
515next_trigger(double d, sc_time_unit u)
516{
517 next_trigger(sc_time(d, u));
518}
519
520void
521next_trigger(const sc_time &t, const sc_event &e)
522{
523 sc_gem5::Process *p = sc_gem5::scheduler.current();
524 p->setDynamic(new ::sc_gem5::SensitivityTimeoutAndEvent(p, t, &e));
525}
526
527void
528next_trigger(double d, sc_time_unit u, const sc_event &e)
529{
530 next_trigger(sc_time(d, u), e);
531}
532
533void
534next_trigger(const sc_time &t, const sc_event_or_list &eol)
535{
536 sc_gem5::Process *p = sc_gem5::scheduler.current();
537 p->setDynamic(
538 new ::sc_gem5::SensitivityTimeoutAndEventOrList(p, t, &eol));
539}
540
541void
542next_trigger(double d, sc_time_unit u, const sc_event_or_list &eol)
543{
544 next_trigger(sc_time(d, u), eol);
545}
546
547void
548next_trigger(const sc_time &t, const sc_event_and_list &eal)
549{
550 sc_gem5::Process *p = sc_gem5::scheduler.current();
551 p->setDynamic(
552 new ::sc_gem5::SensitivityTimeoutAndEventAndList(p, t, &eal));
553}
554
555void
556next_trigger(double d, sc_time_unit u, const sc_event_and_list &eal)
557{
558 next_trigger(sc_time(d, u), eal);
559}
560
561bool
562timed_out()
563{
564 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
565 return false;
566}
567
568
569void
570wait()
571{
572 sc_gem5::Process *p = sc_gem5::scheduler.current();
573 p->setDynamic(nullptr);
574 sc_gem5::scheduler.yield();
575}
576
577void
578wait(int n)
579{
580 if (n <= 0) {
581 std::string msg = csprintf("n = %d", n);
582 SC_REPORT_ERROR("(E525) wait(n) is only valid for n > 0", msg.c_str());
583 }
584 for (int i = 0; i < n; i++)
585 wait();
586}
587
588void
589wait(const sc_event &e)
590{
591 sc_gem5::Process *p = sc_gem5::scheduler.current();
592 p->setDynamic(new ::sc_gem5::SensitivityEvent(p, &e));
593 sc_gem5::scheduler.yield();
594}
595
596void
597wait(const sc_event_or_list &eol)
598{
599 sc_gem5::Process *p = sc_gem5::scheduler.current();
600 p->setDynamic(new ::sc_gem5::SensitivityEventOrList(p, &eol));
601 sc_gem5::scheduler.yield();
602}
603
604void
605wait(const sc_event_and_list &eal)
606{
607 sc_gem5::Process *p = sc_gem5::scheduler.current();
608 p->setDynamic(new ::sc_gem5::SensitivityEventAndList(p, &eal));
609 sc_gem5::scheduler.yield();
610}
611
612void
613wait(const sc_time &t)
614{
615 sc_gem5::Process *p = sc_gem5::scheduler.current();
616 p->setDynamic(new ::sc_gem5::SensitivityTimeout(p, t));
617 sc_gem5::scheduler.yield();
618}
619
620void
621wait(double d, sc_time_unit u)
622{
623 wait(sc_time(d, u));
624}
625
626void
627wait(const sc_time &t, const sc_event &e)
628{
629 sc_gem5::Process *p = sc_gem5::scheduler.current();
630 p->setDynamic(new ::sc_gem5::SensitivityTimeoutAndEvent(p, t, &e));
631 sc_gem5::scheduler.yield();
632}
633
634void
635wait(double d, sc_time_unit u, const sc_event &e)
636{
637 wait(sc_time(d, u), e);
638}
639
640void
641wait(const sc_time &t, const sc_event_or_list &eol)
642{
643 sc_gem5::Process *p = sc_gem5::scheduler.current();
644 p->setDynamic(
645 new ::sc_gem5::SensitivityTimeoutAndEventOrList(p, t, &eol));
646 sc_gem5::scheduler.yield();
647}
648
649void
650wait(double d, sc_time_unit u, const sc_event_or_list &eol)
651{
652 wait(sc_time(d, u), eol);
653}
654
655void
656wait(const sc_time &t, const sc_event_and_list &eal)
657{
658 sc_gem5::Process *p = sc_gem5::scheduler.current();
659 p->setDynamic(
660 new ::sc_gem5::SensitivityTimeoutAndEventAndList(p, t, &eal));
661 sc_gem5::scheduler.yield();
662}
663
664void
665wait(double d, sc_time_unit u, const sc_event_and_list &eal)
666{
667 wait(sc_time(d, u), eal);
668}
669
670void
671halt()
672{
673 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
674}
675
676void
675at_posedge(const sc_signal_in_if &)
677at_posedge(const sc_signal_in_if<bool> &s)
676{
678{
677 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
679 while (s.read())
680 wait();
681 while (!s.read())
682 wait();
678}
679
680void
683}
684
685void
681at_posedge(const sc_signal_in_if &)
686at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &s)
682{
687{
683 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
688 while (s.read() == sc_dt::Log_1)
689 wait();
690 while (s.read() == sc_dt::Log_0)
691 wait();
684}
685
686void
692}
693
694void
687at_negedge(const sc_signal_in_if &)
695at_negedge(const sc_signal_in_if<bool> &s)
688{
696{
689 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
697 while (!s.read())
698 wait();
699 while (s.read())
700 wait();
690}
691
692void
701}
702
703void
693at_negedge(const sc_signal_in_if &)
704at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &s)
694{
705{
695 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
706 while (s.read() == sc_dt::Log_0)
707 wait();
708 while (s.read() == sc_dt::Log_1)
709 wait();
696}
697
698const char *
699sc_gen_unique_name(const char *seed)
700{
701 ::sc_gem5::Module *mod = ::sc_gem5::currentModule();
702 return mod ? mod->uniqueName(seed) :
703 ::sc_gem5::nameGen.gen(seed);
704}
705
706bool
707sc_hierarchical_name_exists(const char *name)
708{
709 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
710 return false;
711}
712
713bool
714sc_start_of_simulation_invoked()
715{
716 return ::sc_gem5::kernel->startOfSimulationComplete();
717}
718
719bool
720sc_end_of_simulation_invoked()
721{
722 return ::sc_gem5::kernel->endOfSimulationComplete();
723}
724
725sc_module *
726sc_module_sc_new(sc_module *mod)
727{
728 static std::vector<std::unique_ptr<sc_module> > modules;
729 modules.emplace_back(mod);
730 return mod;
731}
732
733} // namespace sc_core
710}
711
712const char *
713sc_gen_unique_name(const char *seed)
714{
715 ::sc_gem5::Module *mod = ::sc_gem5::currentModule();
716 return mod ? mod->uniqueName(seed) :
717 ::sc_gem5::nameGen.gen(seed);
718}
719
720bool
721sc_hierarchical_name_exists(const char *name)
722{
723 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
724 return false;
725}
726
727bool
728sc_start_of_simulation_invoked()
729{
730 return ::sc_gem5::kernel->startOfSimulationComplete();
731}
732
733bool
734sc_end_of_simulation_invoked()
735{
736 return ::sc_gem5::kernel->endOfSimulationComplete();
737}
738
739sc_module *
740sc_module_sc_new(sc_module *mod)
741{
742 static std::vector<std::unique_ptr<sc_module> > modules;
743 modules.emplace_back(mod);
744 return mod;
745}
746
747} // namespace sc_core