sc_module.cc revision 13303
112839Sgabeblack@google.com/*
212839Sgabeblack@google.com * Copyright 2018 Google, Inc.
312839Sgabeblack@google.com *
412839Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
512839Sgabeblack@google.com * modification, are permitted provided that the following conditions are
612839Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
712839Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
812839Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
912839Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1012839Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1112839Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1212839Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1312839Sgabeblack@google.com * this software without specific prior written permission.
1412839Sgabeblack@google.com *
1512839Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1612839Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1712839Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1812839Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1912839Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2012839Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2112839Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2212839Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2312839Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2412839Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2512839Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2612839Sgabeblack@google.com *
2712839Sgabeblack@google.com * Authors: Gabe Black
2812839Sgabeblack@google.com */
2912839Sgabeblack@google.com
3012839Sgabeblack@google.com#include <memory>
3112993Sgabeblack@google.com#include <string>
3212993Sgabeblack@google.com#include <vector>
3312993Sgabeblack@google.com
3413288Sgabeblack@google.com#include "base/logging.hh"
3513288Sgabeblack@google.com#include "systemc/core/event.hh"
3613288Sgabeblack@google.com#include "systemc/core/kernel.hh"
3713288Sgabeblack@google.com#include "systemc/core/module.hh"
3813317Sgabeblack@google.com#include "systemc/core/object.hh"
3913129Sgabeblack@google.com#include "systemc/core/port.hh"
4012993Sgabeblack@google.com#include "systemc/core/process_types.hh"
4112839Sgabeblack@google.com#include "systemc/core/sensitivity.hh"
4212839Sgabeblack@google.com#include "systemc/ext/channel/sc_in.hh"
4312993Sgabeblack@google.com#include "systemc/ext/channel/sc_inout.hh"
4412993Sgabeblack@google.com#include "systemc/ext/channel/sc_out.hh"
4512993Sgabeblack@google.com#include "systemc/ext/channel/sc_signal_in_if.hh"
4612993Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh"
4712993Sgabeblack@google.com#include "systemc/ext/core/sc_module_name.hh"
4812993Sgabeblack@google.com#include "systemc/ext/dt/bit/sc_logic.hh"
4912993Sgabeblack@google.com#include "systemc/ext/utils/sc_report_handler.hh"
5012993Sgabeblack@google.com
5112993Sgabeblack@google.comnamespace sc_gem5
5212993Sgabeblack@google.com{
5312993Sgabeblack@google.com
5412993Sgabeblack@google.comProcess *
5512993Sgabeblack@google.comnewMethodProcess(const char *name, ProcessFuncWrapper *func)
5612993Sgabeblack@google.com{
5712993Sgabeblack@google.com    Method *p = new Method(name, func);
5812993Sgabeblack@google.com    if (::sc_core::sc_is_running()) {
5912993Sgabeblack@google.com        std::string name = p->name();
6012993Sgabeblack@google.com        delete p;
6112993Sgabeblack@google.com        SC_REPORT_ERROR("(E541) call to SC_METHOD in sc_module while "
6212993Sgabeblack@google.com                "simulation running", name.c_str());
6312993Sgabeblack@google.com        return nullptr;
6412993Sgabeblack@google.com    }
6512993Sgabeblack@google.com    scheduler.reg(p);
6612993Sgabeblack@google.com    return p;
6712993Sgabeblack@google.com}
6812993Sgabeblack@google.com
6912993Sgabeblack@google.comProcess *
7013131Sgabeblack@google.comnewThreadProcess(const char *name, ProcessFuncWrapper *func)
7112993Sgabeblack@google.com{
7213131Sgabeblack@google.com    Thread *p = new Thread(name, func);
7312993Sgabeblack@google.com    if (::sc_core::sc_is_running()) {
7413194Sgabeblack@google.com        std::string name = p->name();
7513194Sgabeblack@google.com        delete p;
7612993Sgabeblack@google.com        SC_REPORT_ERROR("(E542) call to SC_THREAD in sc_module while "
7712993Sgabeblack@google.com                "simulation running", name.c_str());
7813207Sgabeblack@google.com        return nullptr;
7912993Sgabeblack@google.com    }
8012993Sgabeblack@google.com    scheduler.reg(p);
8113207Sgabeblack@google.com    return p;
8212993Sgabeblack@google.com}
8312993Sgabeblack@google.com
8413207Sgabeblack@google.comProcess *
8512993Sgabeblack@google.comnewCThreadProcess(const char *name, ProcessFuncWrapper *func)
8612993Sgabeblack@google.com{
8713207Sgabeblack@google.com    CThread *p = new CThread(name, func);
8812993Sgabeblack@google.com    if (::sc_core::sc_is_running()) {
8912993Sgabeblack@google.com        std::string name = p->name();
9013207Sgabeblack@google.com        delete p;
9113260Sgabeblack@google.com        SC_REPORT_ERROR("(E543) call to SC_CTHREAD in sc_module while "
9213260Sgabeblack@google.com                "simulation running", name.c_str());
9313288Sgabeblack@google.com        return nullptr;
9413260Sgabeblack@google.com    }
9513260Sgabeblack@google.com    scheduler.reg(p);
9613288Sgabeblack@google.com    p->dontInitialize(true);
9713260Sgabeblack@google.com    return p;
9813260Sgabeblack@google.com}
9913288Sgabeblack@google.com
10013260Sgabeblack@google.com} // namespace sc_gem5
10113260Sgabeblack@google.com
10213288Sgabeblack@google.comnamespace sc_core
10312993Sgabeblack@google.com{
10412993Sgabeblack@google.com
10513180Sgabeblack@google.comsc_bind_proxy::sc_bind_proxy(sc_interface &_interface) :
10613180Sgabeblack@google.com    _interface(&_interface), _port(nullptr)
10713180Sgabeblack@google.com{}
10813180Sgabeblack@google.com
10913317Sgabeblack@google.comsc_bind_proxy::sc_bind_proxy(sc_port_base &_port) :
11013180Sgabeblack@google.com    _interface(nullptr), _port(&_port)
11113180Sgabeblack@google.com{}
11213180Sgabeblack@google.com
11312993Sgabeblack@google.comconst sc_bind_proxy SC_BIND_PROXY_NUL(*(sc_port_base *)nullptr);
11412993Sgabeblack@google.com
11512993Sgabeblack@google.comsc_module::~sc_module() { delete _gem5_module; }
11612993Sgabeblack@google.com
11712993Sgabeblack@google.comconst sc_bind_proxy SC_BIND_PROXY_NIL(*(sc_port_base *)nullptr);
11812993Sgabeblack@google.com
11912993Sgabeblack@google.comvoid
12012839Sgabeblack@google.comsc_module::operator () (const sc_bind_proxy &p001,
12112839Sgabeblack@google.com                        const sc_bind_proxy &p002,
12212839Sgabeblack@google.com                        const sc_bind_proxy &p003,
12312993Sgabeblack@google.com                        const sc_bind_proxy &p004,
12412993Sgabeblack@google.com                        const sc_bind_proxy &p005,
12512993Sgabeblack@google.com                        const sc_bind_proxy &p006,
12612839Sgabeblack@google.com                        const sc_bind_proxy &p007,
12712839Sgabeblack@google.com                        const sc_bind_proxy &p008,
12812839Sgabeblack@google.com                        const sc_bind_proxy &p009,
12912839Sgabeblack@google.com                        const sc_bind_proxy &p010,
13012839Sgabeblack@google.com                        const sc_bind_proxy &p011,
13112993Sgabeblack@google.com                        const sc_bind_proxy &p012,
13212839Sgabeblack@google.com                        const sc_bind_proxy &p013,
13312839Sgabeblack@google.com                        const sc_bind_proxy &p014,
13412839Sgabeblack@google.com                        const sc_bind_proxy &p015,
13512839Sgabeblack@google.com                        const sc_bind_proxy &p016,
13612839Sgabeblack@google.com                        const sc_bind_proxy &p017,
13712993Sgabeblack@google.com                        const sc_bind_proxy &p018,
13812839Sgabeblack@google.com                        const sc_bind_proxy &p019,
13912839Sgabeblack@google.com                        const sc_bind_proxy &p020,
14012839Sgabeblack@google.com                        const sc_bind_proxy &p021,
14112993Sgabeblack@google.com                        const sc_bind_proxy &p022,
14212839Sgabeblack@google.com                        const sc_bind_proxy &p023,
14312993Sgabeblack@google.com                        const sc_bind_proxy &p024,
14412839Sgabeblack@google.com                        const sc_bind_proxy &p025,
14512839Sgabeblack@google.com                        const sc_bind_proxy &p026,
14612839Sgabeblack@google.com                        const sc_bind_proxy &p027,
14712839Sgabeblack@google.com                        const sc_bind_proxy &p028,
14812993Sgabeblack@google.com                        const sc_bind_proxy &p029,
14912839Sgabeblack@google.com                        const sc_bind_proxy &p030,
15012993Sgabeblack@google.com                        const sc_bind_proxy &p031,
15112839Sgabeblack@google.com                        const sc_bind_proxy &p032,
15212839Sgabeblack@google.com                        const sc_bind_proxy &p033,
15312839Sgabeblack@google.com                        const sc_bind_proxy &p034,
15412993Sgabeblack@google.com                        const sc_bind_proxy &p035,
15512839Sgabeblack@google.com                        const sc_bind_proxy &p036,
15612993Sgabeblack@google.com                        const sc_bind_proxy &p037,
15712839Sgabeblack@google.com                        const sc_bind_proxy &p038,
15812839Sgabeblack@google.com                        const sc_bind_proxy &p039,
15912839Sgabeblack@google.com                        const sc_bind_proxy &p040,
16012993Sgabeblack@google.com                        const sc_bind_proxy &p041,
16112839Sgabeblack@google.com                        const sc_bind_proxy &p042,
16212993Sgabeblack@google.com                        const sc_bind_proxy &p043,
16312839Sgabeblack@google.com                        const sc_bind_proxy &p044,
16412839Sgabeblack@google.com                        const sc_bind_proxy &p045,
16512839Sgabeblack@google.com                        const sc_bind_proxy &p046,
16612993Sgabeblack@google.com                        const sc_bind_proxy &p047,
16712839Sgabeblack@google.com                        const sc_bind_proxy &p048,
16812993Sgabeblack@google.com                        const sc_bind_proxy &p049,
16912839Sgabeblack@google.com                        const sc_bind_proxy &p050,
17012839Sgabeblack@google.com                        const sc_bind_proxy &p051,
17112839Sgabeblack@google.com                        const sc_bind_proxy &p052,
17212993Sgabeblack@google.com                        const sc_bind_proxy &p053,
17312839Sgabeblack@google.com                        const sc_bind_proxy &p054,
17412993Sgabeblack@google.com                        const sc_bind_proxy &p055,
17512839Sgabeblack@google.com                        const sc_bind_proxy &p056,
17612839Sgabeblack@google.com                        const sc_bind_proxy &p057,
17712839Sgabeblack@google.com                        const sc_bind_proxy &p058,
17812839Sgabeblack@google.com                        const sc_bind_proxy &p059,
17913260Sgabeblack@google.com                        const sc_bind_proxy &p060,
18012839Sgabeblack@google.com                        const sc_bind_proxy &p061,
18113260Sgabeblack@google.com                        const sc_bind_proxy &p062,
18212839Sgabeblack@google.com                        const sc_bind_proxy &p063,
18312839Sgabeblack@google.com                        const sc_bind_proxy &p064)
18412839Sgabeblack@google.com{
18513260Sgabeblack@google.com    std::vector<const ::sc_core::sc_bind_proxy *> proxies;
18612839Sgabeblack@google.com    auto insert = [&proxies](const ::sc_core::sc_bind_proxy &p) -> bool {
18713260Sgabeblack@google.com        if (!p.port() && !p.interface())
18812839Sgabeblack@google.com            return false;
18912839Sgabeblack@google.com        proxies.push_back(&p);
19012839Sgabeblack@google.com        return true;
19113260Sgabeblack@google.com    };
19212839Sgabeblack@google.com    insert(p001) && insert(p002) && insert(p003) && insert(p004) &&
19313260Sgabeblack@google.com    insert(p005) && insert(p006) && insert(p007) && insert(p008) &&
19412839Sgabeblack@google.com    insert(p009) && insert(p010) && insert(p011) && insert(p012) &&
19512839Sgabeblack@google.com    insert(p013) && insert(p014) && insert(p015) && insert(p016) &&
19612839Sgabeblack@google.com    insert(p017) && insert(p018) && insert(p019) && insert(p020) &&
19713260Sgabeblack@google.com    insert(p021) && insert(p022) && insert(p023) && insert(p024) &&
19813260Sgabeblack@google.com    insert(p025) && insert(p026) && insert(p027) && insert(p028) &&
19912839Sgabeblack@google.com    insert(p029) && insert(p030) && insert(p031) && insert(p032) &&
20013260Sgabeblack@google.com    insert(p033) && insert(p034) && insert(p035) && insert(p036) &&
20112839Sgabeblack@google.com    insert(p037) && insert(p038) && insert(p039) && insert(p040) &&
20212839Sgabeblack@google.com    insert(p041) && insert(p042) && insert(p043) && insert(p044) &&
20312839Sgabeblack@google.com    insert(p045) && insert(p046) && insert(p047) && insert(p048) &&
20412839Sgabeblack@google.com    insert(p049) && insert(p050) && insert(p051) && insert(p052) &&
20513260Sgabeblack@google.com    insert(p053) && insert(p054) && insert(p055) && insert(p056) &&
20612839Sgabeblack@google.com    insert(p057) && insert(p058) && insert(p059) && insert(p060) &&
20713260Sgabeblack@google.com    insert(p061) && insert(p062) && insert(p063) && insert(p064);
20812839Sgabeblack@google.com    _gem5_module->bindPorts(proxies);
20912839Sgabeblack@google.com}
21012839Sgabeblack@google.com
21113260Sgabeblack@google.comsc_module &
21212839Sgabeblack@google.comsc_module::operator << (sc_interface &iface)
21313260Sgabeblack@google.com{
21412839Sgabeblack@google.com    (*this)(iface);
21512839Sgabeblack@google.com    return *this;
21612839Sgabeblack@google.com}
21713260Sgabeblack@google.com
21812839Sgabeblack@google.comsc_module &
21913260Sgabeblack@google.comsc_module::operator << (sc_port_base &pb)
22012839Sgabeblack@google.com{
22112839Sgabeblack@google.com    (*this)(pb);
22212839Sgabeblack@google.com    return *this;
22313260Sgabeblack@google.com}
22413260Sgabeblack@google.com
22512839Sgabeblack@google.comsc_module &
22613260Sgabeblack@google.comsc_module::operator , (sc_interface &iface)
22712839Sgabeblack@google.com{
22812839Sgabeblack@google.com    (*this)(iface);
22912839Sgabeblack@google.com    return *this;
230}
231
232sc_module &
233sc_module::operator , (sc_port_base &pb)
234{
235    (*this)(pb);
236    return *this;
237}
238
239const std::vector<sc_object *> &
240sc_module::get_child_objects() const
241{
242    return _gem5_module->obj()->get_child_objects();
243}
244
245const std::vector<sc_event *> &
246sc_module::get_child_events() const
247{
248    return _gem5_module->obj()->get_child_events();
249}
250
251sc_module::sc_module() :
252    sc_object(sc_gem5::newModuleChecked()->name()),
253    _gem5_module(sc_gem5::currentModule())
254{
255    if (sc_is_running()) {
256        SC_REPORT_ERROR("(E529) insert module failed", "simulation running");
257        std::cout << "Running!\n";
258    }
259    if (::sc_gem5::scheduler.elaborationDone()) {
260        SC_REPORT_ERROR("(E529) insert module failed", "elaboration done");
261        std::cout << "Elaboration done!\n";
262    }
263}
264
265sc_module::sc_module(const sc_module_name &) : sc_module() {}
266sc_module::sc_module(const char *_name) : sc_module(sc_module_name(_name))
267{
268    _gem5_module->deprecatedConstructor();
269    SC_REPORT_WARNING("(W569) sc_module(const char*), "
270            "sc_module(const std::string&) have been deprecated, use "
271            "sc_module(const sc_module_name&)", _name);
272}
273sc_module::sc_module(const std::string &_name) :
274    sc_module(sc_module_name(_name.c_str()))
275{
276    _gem5_module->deprecatedConstructor();
277    SC_REPORT_WARNING("(W569) sc_module(const char*), "
278            "sc_module(const std::string&) have been deprecated, use "
279            "sc_module(const sc_module_name&)", _name.c_str());
280}
281
282void
283sc_module::end_module()
284{
285    _gem5_module->endModule();
286}
287
288void
289sc_module::reset_signal_is(const sc_in<bool> &port, bool val)
290{
291    ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), true, val);
292}
293
294void
295sc_module::reset_signal_is(const sc_inout<bool> &port, bool val)
296{
297    ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), true, val);
298}
299
300void
301sc_module::reset_signal_is(const sc_out<bool> &port, bool val)
302{
303    ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), true, val);
304}
305
306void
307sc_module::reset_signal_is(const sc_signal_in_if<bool> &signal, bool val)
308{
309    ::sc_gem5::newReset(&signal, ::sc_gem5::Process::newest(), true, val);
310}
311
312
313void
314sc_module::async_reset_signal_is(const sc_in<bool> &port, bool val)
315{
316    ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), false, val);
317}
318
319void
320sc_module::async_reset_signal_is(const sc_inout<bool> &port, bool val)
321{
322    ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), false, val);
323}
324
325void
326sc_module::async_reset_signal_is(const sc_out<bool> &port, bool val)
327{
328    ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), false, val);
329}
330
331void
332sc_module::async_reset_signal_is(const sc_signal_in_if<bool> &signal, bool val)
333{
334    ::sc_gem5::newReset(&signal, ::sc_gem5::Process::newest(), false, val);
335}
336
337
338void
339sc_module::dont_initialize()
340{
341    ::sc_gem5::Process::newest()->dontInitialize(true);
342}
343
344void
345sc_module::set_stack_size(size_t size)
346{
347    ::sc_gem5::Process::newest()->setStackSize(size);
348}
349
350
351void sc_module::next_trigger() { ::sc_core::next_trigger(); }
352
353void
354sc_module::next_trigger(const sc_event &e)
355{
356    ::sc_core::next_trigger(e);
357}
358
359void
360sc_module::next_trigger(const sc_event_or_list &eol)
361{
362    ::sc_core::next_trigger(eol);
363}
364
365void
366sc_module::next_trigger(const sc_event_and_list &eal)
367{
368    ::sc_core::next_trigger(eal);
369}
370
371void
372sc_module::next_trigger(const sc_time &t)
373{
374    ::sc_core::next_trigger(t);
375}
376
377void
378sc_module::next_trigger(double d, sc_time_unit u)
379{
380    ::sc_core::next_trigger(d, u);
381}
382
383void
384sc_module::next_trigger(const sc_time &t, const sc_event &e)
385{
386    ::sc_core::next_trigger(t, e);
387}
388
389void
390sc_module::next_trigger(double d, sc_time_unit u, const sc_event &e)
391{
392    ::sc_core::next_trigger(d, u, e);
393}
394
395void
396sc_module::next_trigger(const sc_time &t, const sc_event_or_list &eol)
397{
398    ::sc_core::next_trigger(t, eol);
399}
400
401void
402sc_module::next_trigger(double d, sc_time_unit u, const sc_event_or_list &eol)
403{
404    ::sc_core::next_trigger(d, u, eol);
405}
406
407void
408sc_module::next_trigger(const sc_time &t, const sc_event_and_list &eal)
409{
410    ::sc_core::next_trigger(t, eal);
411}
412
413void
414sc_module::next_trigger(double d, sc_time_unit u, const sc_event_and_list &eal)
415{
416    ::sc_core::next_trigger(d, u, eal);
417}
418
419
420bool
421sc_module::timed_out()
422{
423    return ::sc_core::timed_out();
424}
425
426
427void
428sc_module::wait()
429{
430    ::sc_core::wait();
431}
432
433void
434sc_module::wait(int i)
435{
436    ::sc_core::wait(i);
437}
438
439void
440sc_module::wait(const sc_event &e)
441{
442    ::sc_core::wait(e);
443}
444
445void
446sc_module::wait(const sc_event_or_list &eol)
447{
448    ::sc_core::wait(eol);
449}
450
451void
452sc_module::wait(const sc_event_and_list &eal)
453{
454    ::sc_core::wait(eal);
455}
456
457void
458sc_module::wait(const sc_time &t)
459{
460    ::sc_core::wait(t);
461}
462
463void
464sc_module::wait(double d, sc_time_unit u)
465{
466    ::sc_core::wait(d, u);
467}
468
469void
470sc_module::wait(const sc_time &t, const sc_event &e)
471{
472    ::sc_core::wait(t, e);
473}
474
475void
476sc_module::wait(double d, sc_time_unit u, const sc_event &e)
477{
478    ::sc_core::wait(d, u, e);
479}
480
481void
482sc_module::wait(const sc_time &t, const sc_event_or_list &eol)
483{
484    ::sc_core::wait(t, eol);
485}
486
487void
488sc_module::wait(double d, sc_time_unit u, const sc_event_or_list &eol)
489{
490    ::sc_core::wait(d, u, eol);
491}
492
493void
494sc_module::wait(const sc_time &t, const sc_event_and_list &eal)
495{
496    ::sc_core::wait(t, eal);
497}
498
499void
500sc_module::wait(double d, sc_time_unit u, const sc_event_and_list &eal)
501{
502    ::sc_core::wait(d, u, eal);
503}
504
505
506void
507sc_module::halt()
508{
509    ::sc_core::halt();
510}
511
512void
513sc_module::at_posedge(const sc_signal_in_if<bool> &s)
514{
515    ::sc_core::at_posedge(s);
516}
517
518void
519sc_module::at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &s)
520{
521    ::sc_core::at_posedge(s);
522}
523
524void
525sc_module::at_negedge(const sc_signal_in_if<bool> &s)
526{
527    ::sc_core::at_negedge(s);
528}
529
530void
531sc_module::at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &s)
532{
533    ::sc_core::at_negedge(s);
534}
535
536
537void
538next_trigger()
539{
540    sc_gem5::Process *p = sc_gem5::scheduler.current();
541    p->cancelTimeout();
542    p->clearDynamic();
543}
544
545void
546next_trigger(const sc_event &e)
547{
548    sc_gem5::Process *p = sc_gem5::scheduler.current();
549    p->cancelTimeout();
550    ::sc_gem5::newDynamicSensitivityEvent(p, &e);
551}
552
553void
554next_trigger(const sc_event_or_list &eol)
555{
556    sc_gem5::Process *p = sc_gem5::scheduler.current();
557    p->cancelTimeout();
558    ::sc_gem5::newDynamicSensitivityEventOrList(p, &eol);
559}
560
561void
562next_trigger(const sc_event_and_list &eal)
563{
564    sc_gem5::Process *p = sc_gem5::scheduler.current();
565    p->cancelTimeout();
566    ::sc_gem5::newDynamicSensitivityEventAndList(p, &eal);
567}
568
569void
570next_trigger(const sc_time &t)
571{
572    sc_gem5::Process *p = sc_gem5::scheduler.current();
573    p->setTimeout(t);
574    p->clearDynamic();
575}
576
577void
578next_trigger(double d, sc_time_unit u)
579{
580    next_trigger(sc_time(d, u));
581}
582
583void
584next_trigger(const sc_time &t, const sc_event &e)
585{
586    sc_gem5::Process *p = sc_gem5::scheduler.current();
587    p->setTimeout(t);
588    ::sc_gem5::newDynamicSensitivityEvent(p, &e);
589}
590
591void
592next_trigger(double d, sc_time_unit u, const sc_event &e)
593{
594    next_trigger(sc_time(d, u), e);
595}
596
597void
598next_trigger(const sc_time &t, const sc_event_or_list &eol)
599{
600    sc_gem5::Process *p = sc_gem5::scheduler.current();
601    p->setTimeout(t);
602    ::sc_gem5::newDynamicSensitivityEventOrList(p, &eol);
603}
604
605void
606next_trigger(double d, sc_time_unit u, const sc_event_or_list &eol)
607{
608    next_trigger(sc_time(d, u), eol);
609}
610
611void
612next_trigger(const sc_time &t, const sc_event_and_list &eal)
613{
614    sc_gem5::Process *p = sc_gem5::scheduler.current();
615    p->setTimeout(t);
616    ::sc_gem5::newDynamicSensitivityEventAndList(p, &eal);
617}
618
619void
620next_trigger(double d, sc_time_unit u, const sc_event_and_list &eal)
621{
622    next_trigger(sc_time(d, u), eal);
623}
624
625bool
626timed_out()
627{
628    ::sc_gem5::Process *p = sc_gem5::scheduler.current();
629    if (!p)
630        return false;
631    else
632        return p->timedOut();
633}
634
635
636namespace
637{
638
639bool
640waitErrorCheck(sc_gem5::Process *p)
641{
642    if (p->procKind() == SC_METHOD_PROC_) {
643        SC_REPORT_ERROR(
644                "(E519) wait() is only allowed in SC_THREADs and SC_CTHREADs",
645                "\n        in SC_METHODs use next_trigger() instead");
646        return true;
647    }
648    return false;
649}
650
651} // anonymous namespace
652
653void
654wait()
655{
656    sc_gem5::Process *p = sc_gem5::scheduler.current();
657    if (waitErrorCheck(p))
658        return;
659    p->cancelTimeout();
660    p->clearDynamic();
661    sc_gem5::scheduler.yield();
662}
663
664void
665wait(int n)
666{
667    if (n <= 0) {
668        std::string msg = csprintf("n = %d", n);
669        SC_REPORT_ERROR("(E525) wait(n) is only valid for n > 0", msg.c_str());
670    }
671    sc_gem5::Process *p = sc_gem5::scheduler.current();
672    p->waitCount(n - 1);
673    wait();
674}
675
676void
677wait(const sc_event &e)
678{
679    sc_gem5::Process *p = sc_gem5::scheduler.current();
680    if (waitErrorCheck(p))
681        return;
682    p->cancelTimeout();
683    ::sc_gem5::newDynamicSensitivityEvent(p, &e);
684    sc_gem5::scheduler.yield();
685}
686
687void
688wait(const sc_event_or_list &eol)
689{
690    sc_gem5::Process *p = sc_gem5::scheduler.current();
691    if (waitErrorCheck(p))
692        return;
693    p->cancelTimeout();
694    ::sc_gem5::newDynamicSensitivityEventOrList(p, &eol);
695    sc_gem5::scheduler.yield();
696}
697
698void
699wait(const sc_event_and_list &eal)
700{
701    sc_gem5::Process *p = sc_gem5::scheduler.current();
702    if (waitErrorCheck(p))
703        return;
704    p->cancelTimeout();
705    ::sc_gem5::newDynamicSensitivityEventAndList(p, &eal);
706    sc_gem5::scheduler.yield();
707}
708
709void
710wait(const sc_time &t)
711{
712    sc_gem5::Process *p = sc_gem5::scheduler.current();
713    if (waitErrorCheck(p))
714        return;
715    p->setTimeout(t);
716    p->clearDynamic();
717    sc_gem5::scheduler.yield();
718}
719
720void
721wait(double d, sc_time_unit u)
722{
723    wait(sc_time(d, u));
724}
725
726void
727wait(const sc_time &t, const sc_event &e)
728{
729    sc_gem5::Process *p = sc_gem5::scheduler.current();
730    if (waitErrorCheck(p))
731        return;
732    p->setTimeout(t);
733    ::sc_gem5::newDynamicSensitivityEvent(p, &e);
734    sc_gem5::scheduler.yield();
735}
736
737void
738wait(double d, sc_time_unit u, const sc_event &e)
739{
740    wait(sc_time(d, u), e);
741}
742
743void
744wait(const sc_time &t, const sc_event_or_list &eol)
745{
746    sc_gem5::Process *p = sc_gem5::scheduler.current();
747    if (waitErrorCheck(p))
748        return;
749    p->setTimeout(t);
750    ::sc_gem5::newDynamicSensitivityEventOrList(p, &eol);
751    sc_gem5::scheduler.yield();
752}
753
754void
755wait(double d, sc_time_unit u, const sc_event_or_list &eol)
756{
757    wait(sc_time(d, u), eol);
758}
759
760void
761wait(const sc_time &t, const sc_event_and_list &eal)
762{
763    sc_gem5::Process *p = sc_gem5::scheduler.current();
764    if (waitErrorCheck(p))
765        return;
766    p->setTimeout(t);
767    ::sc_gem5::newDynamicSensitivityEventAndList(p, &eal);
768    sc_gem5::scheduler.yield();
769}
770
771void
772wait(double d, sc_time_unit u, const sc_event_and_list &eal)
773{
774    wait(sc_time(d, u), eal);
775}
776
777void
778halt()
779{
780    ::sc_core::wait();
781    throw ::sc_gem5::ScHalt();
782}
783
784void
785at_posedge(const sc_signal_in_if<bool> &s)
786{
787    while (s.read())
788        wait();
789    while (!s.read())
790        wait();
791}
792
793void
794at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &s)
795{
796    while (s.read() == sc_dt::Log_1)
797        wait();
798    while (s.read() == sc_dt::Log_0)
799        wait();
800}
801
802void
803at_negedge(const sc_signal_in_if<bool> &s)
804{
805    while (!s.read())
806        wait();
807    while (s.read())
808        wait();
809}
810
811void
812at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &s)
813{
814    while (s.read() == sc_dt::Log_0)
815        wait();
816    while (s.read() == sc_dt::Log_1)
817        wait();
818}
819
820const char *
821sc_gen_unique_name(const char *seed)
822{
823    if (!seed || seed[0] == '\0') {
824        SC_REPORT_ERROR(
825                "(E532) cannot generate unique name from null string", "");
826        seed = "unnamed";
827    }
828
829    auto mod = sc_gem5::pickParentModule();
830    if (mod)
831        return mod->uniqueName(seed);
832
833    sc_gem5::Process *p = sc_gem5::scheduler.current();
834    if (p)
835        return p->uniqueName(seed);
836
837    return ::sc_gem5::globalNameGen.gen(seed);
838}
839
840bool
841sc_hierarchical_name_exists(const char *name)
842{
843    return sc_gem5::findEvent(name) != sc_gem5::allEvents.end() ||
844        ::sc_gem5::findObject(name, sc_gem5::allObjects);
845}
846
847bool
848sc_start_of_simulation_invoked()
849{
850    return ::sc_gem5::kernel->startOfSimulationComplete();
851}
852
853bool
854sc_end_of_simulation_invoked()
855{
856    return ::sc_gem5::kernel->endOfSimulationComplete();
857}
858
859sc_module *
860sc_module_sc_new(sc_module *mod)
861{
862    static std::vector<std::unique_ptr<sc_module> > modules;
863    modules.emplace_back(mod);
864    return mod;
865}
866
867} // namespace sc_core
868