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