sc_module.cc revision 13284:db01c2acd23f
112855Sgabeblack@google.com/*
212855Sgabeblack@google.com * Copyright 2018 Google, Inc.
312855Sgabeblack@google.com *
412855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
512855Sgabeblack@google.com * modification, are permitted provided that the following conditions are
612855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
712855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
812855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
912855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1012855Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1112855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1212855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1312855Sgabeblack@google.com * this software without specific prior written permission.
1412855Sgabeblack@google.com *
1512855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1612855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1712855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1812855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1912855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2012855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2112855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2212855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2312855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2412855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2512855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2612855Sgabeblack@google.com *
2712855Sgabeblack@google.com * Authors: Gabe Black
2812855Sgabeblack@google.com */
2912855Sgabeblack@google.com
3012855Sgabeblack@google.com#include <memory>
3112855Sgabeblack@google.com#include <string>
3212855Sgabeblack@google.com#include <vector>
3312855Sgabeblack@google.com
3412855Sgabeblack@google.com#include "base/logging.hh"
3512855Sgabeblack@google.com#include "systemc/core/event.hh"
3612855Sgabeblack@google.com#include "systemc/core/kernel.hh"
3712855Sgabeblack@google.com#include "systemc/core/module.hh"
3812855Sgabeblack@google.com#include "systemc/core/object.hh"
3912855Sgabeblack@google.com#include "systemc/core/process_types.hh"
4012855Sgabeblack@google.com#include "systemc/core/sensitivity.hh"
4112855Sgabeblack@google.com#include "systemc/ext/channel/sc_signal_in_if.hh"
4212855Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh"
4312855Sgabeblack@google.com#include "systemc/ext/core/sc_module_name.hh"
4412855Sgabeblack@google.com#include "systemc/ext/dt/bit/sc_logic.hh"
4512855Sgabeblack@google.com#include "systemc/ext/utils/sc_report_handler.hh"
4612855Sgabeblack@google.com
4712855Sgabeblack@google.comnamespace sc_gem5
4812855Sgabeblack@google.com{
4912855Sgabeblack@google.com
5012855Sgabeblack@google.comProcess *
5112855Sgabeblack@google.comnewMethodProcess(const char *name, ProcessFuncWrapper *func)
5212855Sgabeblack@google.com{
5312855Sgabeblack@google.com    Method *p = new Method(name, func);
5412855Sgabeblack@google.com    if (::sc_core::sc_is_running()) {
5512855Sgabeblack@google.com        std::string name = p->name();
5612855Sgabeblack@google.com        delete p;
5712855Sgabeblack@google.com        SC_REPORT_ERROR("(E541) call to SC_METHOD in sc_module while "
5812855Sgabeblack@google.com                "simulation running", name.c_str());
5912855Sgabeblack@google.com        return nullptr;
6012855Sgabeblack@google.com    }
6112855Sgabeblack@google.com    scheduler.reg(p);
6212855Sgabeblack@google.com    return p;
6312855Sgabeblack@google.com}
6412855Sgabeblack@google.com
6512855Sgabeblack@google.comProcess *
6612855Sgabeblack@google.comnewThreadProcess(const char *name, ProcessFuncWrapper *func)
6712855Sgabeblack@google.com{
6812855Sgabeblack@google.com    Thread *p = new Thread(name, func);
6912855Sgabeblack@google.com    if (::sc_core::sc_is_running()) {
7012855Sgabeblack@google.com        std::string name = p->name();
7112855Sgabeblack@google.com        delete p;
7212855Sgabeblack@google.com        SC_REPORT_ERROR("(E542) call to SC_THREAD in sc_module while "
7312855Sgabeblack@google.com                "simulation running", name.c_str());
7412855Sgabeblack@google.com        return nullptr;
7512855Sgabeblack@google.com    }
7612855Sgabeblack@google.com    scheduler.reg(p);
7712855Sgabeblack@google.com    return p;
7812855Sgabeblack@google.com}
7912855Sgabeblack@google.com
8012855Sgabeblack@google.comProcess *
8112855Sgabeblack@google.comnewCThreadProcess(const char *name, ProcessFuncWrapper *func)
8212855Sgabeblack@google.com{
8312855Sgabeblack@google.com    CThread *p = new CThread(name, func);
8412855Sgabeblack@google.com    if (::sc_core::sc_is_running()) {
8512855Sgabeblack@google.com        std::string name = p->name();
8612855Sgabeblack@google.com        delete p;
8712855Sgabeblack@google.com        SC_REPORT_ERROR("(E543) call to SC_CTHREAD in sc_module while "
8812855Sgabeblack@google.com                "simulation running", name.c_str());
8912855Sgabeblack@google.com        return nullptr;
9012855Sgabeblack@google.com    }
9112855Sgabeblack@google.com    scheduler.reg(p);
9212855Sgabeblack@google.com    p->dontInitialize(true);
9312855Sgabeblack@google.com    return p;
9412855Sgabeblack@google.com}
9512855Sgabeblack@google.com
9612855Sgabeblack@google.comUniqueNameGen nameGen;
9712855Sgabeblack@google.com
9812855Sgabeblack@google.com} // namespace sc_gem5
9912855Sgabeblack@google.com
10012855Sgabeblack@google.comnamespace sc_core
10112855Sgabeblack@google.com{
10212855Sgabeblack@google.com
10312855Sgabeblack@google.comsc_bind_proxy::sc_bind_proxy(sc_interface &_interface) :
10412855Sgabeblack@google.com    _interface(&_interface), _port(nullptr)
10512855Sgabeblack@google.com{}
10612855Sgabeblack@google.com
10712855Sgabeblack@google.comsc_bind_proxy::sc_bind_proxy(sc_port_base &_port) :
10812855Sgabeblack@google.com    _interface(nullptr), _port(&_port)
10912855Sgabeblack@google.com{}
11012855Sgabeblack@google.com
11112855Sgabeblack@google.comconst sc_bind_proxy SC_BIND_PROXY_NUL(*(sc_port_base *)nullptr);
11212855Sgabeblack@google.com
11312855Sgabeblack@google.comsc_module::~sc_module() { delete _gem5_module; }
11412855Sgabeblack@google.com
11512855Sgabeblack@google.comconst sc_bind_proxy SC_BIND_PROXY_NIL(*(sc_port_base *)nullptr);
11612855Sgabeblack@google.com
11712855Sgabeblack@google.comvoid
11812855Sgabeblack@google.comsc_module::operator () (const sc_bind_proxy &p001,
11912855Sgabeblack@google.com                        const sc_bind_proxy &p002,
12012855Sgabeblack@google.com                        const sc_bind_proxy &p003,
12112855Sgabeblack@google.com                        const sc_bind_proxy &p004,
12212855Sgabeblack@google.com                        const sc_bind_proxy &p005,
12312855Sgabeblack@google.com                        const sc_bind_proxy &p006,
12412855Sgabeblack@google.com                        const sc_bind_proxy &p007,
12512855Sgabeblack@google.com                        const sc_bind_proxy &p008,
12612855Sgabeblack@google.com                        const sc_bind_proxy &p009,
12712855Sgabeblack@google.com                        const sc_bind_proxy &p010,
12812855Sgabeblack@google.com                        const sc_bind_proxy &p011,
12912855Sgabeblack@google.com                        const sc_bind_proxy &p012,
13012855Sgabeblack@google.com                        const sc_bind_proxy &p013,
13112855Sgabeblack@google.com                        const sc_bind_proxy &p014,
13212855Sgabeblack@google.com                        const sc_bind_proxy &p015,
13312855Sgabeblack@google.com                        const sc_bind_proxy &p016,
13412855Sgabeblack@google.com                        const sc_bind_proxy &p017,
13512855Sgabeblack@google.com                        const sc_bind_proxy &p018,
13612855Sgabeblack@google.com                        const sc_bind_proxy &p019,
13712855Sgabeblack@google.com                        const sc_bind_proxy &p020,
13812855Sgabeblack@google.com                        const sc_bind_proxy &p021,
13912855Sgabeblack@google.com                        const sc_bind_proxy &p022,
14012855Sgabeblack@google.com                        const sc_bind_proxy &p023,
14112855Sgabeblack@google.com                        const sc_bind_proxy &p024,
14212855Sgabeblack@google.com                        const sc_bind_proxy &p025,
14312855Sgabeblack@google.com                        const sc_bind_proxy &p026,
14412855Sgabeblack@google.com                        const sc_bind_proxy &p027,
14512855Sgabeblack@google.com                        const sc_bind_proxy &p028,
14612855Sgabeblack@google.com                        const sc_bind_proxy &p029,
14712855Sgabeblack@google.com                        const sc_bind_proxy &p030,
14812855Sgabeblack@google.com                        const sc_bind_proxy &p031,
14912855Sgabeblack@google.com                        const sc_bind_proxy &p032,
15012855Sgabeblack@google.com                        const sc_bind_proxy &p033,
15112855Sgabeblack@google.com                        const sc_bind_proxy &p034,
15212855Sgabeblack@google.com                        const sc_bind_proxy &p035,
15312855Sgabeblack@google.com                        const sc_bind_proxy &p036,
15412855Sgabeblack@google.com                        const sc_bind_proxy &p037,
15512855Sgabeblack@google.com                        const sc_bind_proxy &p038,
15612855Sgabeblack@google.com                        const sc_bind_proxy &p039,
15712855Sgabeblack@google.com                        const sc_bind_proxy &p040,
15812855Sgabeblack@google.com                        const sc_bind_proxy &p041,
15912855Sgabeblack@google.com                        const sc_bind_proxy &p042,
16012855Sgabeblack@google.com                        const sc_bind_proxy &p043,
16112855Sgabeblack@google.com                        const sc_bind_proxy &p044,
16212855Sgabeblack@google.com                        const sc_bind_proxy &p045,
16312855Sgabeblack@google.com                        const sc_bind_proxy &p046,
16412855Sgabeblack@google.com                        const sc_bind_proxy &p047,
16512855Sgabeblack@google.com                        const sc_bind_proxy &p048,
16612855Sgabeblack@google.com                        const sc_bind_proxy &p049,
16712855Sgabeblack@google.com                        const sc_bind_proxy &p050,
16812855Sgabeblack@google.com                        const sc_bind_proxy &p051,
16912855Sgabeblack@google.com                        const sc_bind_proxy &p052,
17012855Sgabeblack@google.com                        const sc_bind_proxy &p053,
17112855Sgabeblack@google.com                        const sc_bind_proxy &p054,
17212855Sgabeblack@google.com                        const sc_bind_proxy &p055,
17312855Sgabeblack@google.com                        const sc_bind_proxy &p056,
17412855Sgabeblack@google.com                        const sc_bind_proxy &p057,
17512855Sgabeblack@google.com                        const sc_bind_proxy &p058,
17612855Sgabeblack@google.com                        const sc_bind_proxy &p059,
17712855Sgabeblack@google.com                        const sc_bind_proxy &p060,
17812855Sgabeblack@google.com                        const sc_bind_proxy &p061,
17912855Sgabeblack@google.com                        const sc_bind_proxy &p062,
18012855Sgabeblack@google.com                        const sc_bind_proxy &p063,
18112855Sgabeblack@google.com                        const sc_bind_proxy &p064)
18212855Sgabeblack@google.com{
18312855Sgabeblack@google.com    std::vector<const ::sc_core::sc_bind_proxy *> proxies;
18412855Sgabeblack@google.com    auto insert = [&proxies](const ::sc_core::sc_bind_proxy &p) -> bool {
18512855Sgabeblack@google.com        if (!p.port() && !p.interface())
18612855Sgabeblack@google.com            return false;
18712855Sgabeblack@google.com        proxies.push_back(&p);
18812855Sgabeblack@google.com        return true;
18912855Sgabeblack@google.com    };
19012855Sgabeblack@google.com    insert(p001) && insert(p002) && insert(p003) && insert(p004) &&
19112855Sgabeblack@google.com    insert(p005) && insert(p006) && insert(p007) && insert(p008) &&
19212855Sgabeblack@google.com    insert(p009) && insert(p010) && insert(p011) && insert(p012) &&
19312855Sgabeblack@google.com    insert(p013) && insert(p014) && insert(p015) && insert(p016) &&
19412855Sgabeblack@google.com    insert(p017) && insert(p018) && insert(p019) && insert(p020) &&
19512855Sgabeblack@google.com    insert(p021) && insert(p022) && insert(p023) && insert(p024) &&
19612855Sgabeblack@google.com    insert(p025) && insert(p026) && insert(p027) && insert(p028) &&
19712855Sgabeblack@google.com    insert(p029) && insert(p030) && insert(p031) && insert(p032) &&
19812855Sgabeblack@google.com    insert(p033) && insert(p034) && insert(p035) && insert(p036) &&
19912855Sgabeblack@google.com    insert(p037) && insert(p038) && insert(p039) && insert(p040) &&
20012855Sgabeblack@google.com    insert(p041) && insert(p042) && insert(p043) && insert(p044) &&
20112855Sgabeblack@google.com    insert(p045) && insert(p046) && insert(p047) && insert(p048) &&
20212855Sgabeblack@google.com    insert(p049) && insert(p050) && insert(p051) && insert(p052) &&
20312855Sgabeblack@google.com    insert(p053) && insert(p054) && insert(p055) && insert(p056) &&
20412855Sgabeblack@google.com    insert(p057) && insert(p058) && insert(p059) && insert(p060) &&
20512855Sgabeblack@google.com    insert(p061) && insert(p062) && insert(p063) && insert(p064);
20612855Sgabeblack@google.com    _gem5_module->bindPorts(proxies);
20712855Sgabeblack@google.com}
20812855Sgabeblack@google.com
20912855Sgabeblack@google.comconst std::vector<sc_object *> &
21012855Sgabeblack@google.comsc_module::get_child_objects() const
21112855Sgabeblack@google.com{
21212855Sgabeblack@google.com    return _gem5_module->obj()->get_child_objects();
21312855Sgabeblack@google.com}
21412855Sgabeblack@google.com
21512855Sgabeblack@google.comconst std::vector<sc_event *> &
21612855Sgabeblack@google.comsc_module::get_child_events() const
21712855Sgabeblack@google.com{
21812855Sgabeblack@google.com    return _gem5_module->obj()->get_child_events();
21912855Sgabeblack@google.com}
22012855Sgabeblack@google.com
22112855Sgabeblack@google.comsc_module::sc_module() :
22212855Sgabeblack@google.com    sc_object(sc_gem5::newModuleChecked()->name()),
22312855Sgabeblack@google.com    _gem5_module(sc_gem5::currentModule())
22412855Sgabeblack@google.com{
22512855Sgabeblack@google.com    if (sc_is_running()) {
22612855Sgabeblack@google.com        SC_REPORT_ERROR("(E529) insert module failed", "simulation running");
22712855Sgabeblack@google.com        std::cout << "Running!\n";
22812855Sgabeblack@google.com    }
22912855Sgabeblack@google.com    if (::sc_gem5::scheduler.elaborationDone()) {
23012855Sgabeblack@google.com        SC_REPORT_ERROR("(E529) insert module failed", "elaboration done");
23112855Sgabeblack@google.com        std::cout << "Elaboration done!\n";
23212855Sgabeblack@google.com    }
23312855Sgabeblack@google.com}
23412855Sgabeblack@google.com
23512855Sgabeblack@google.comsc_module::sc_module(const sc_module_name &) : sc_module() {}
23612855Sgabeblack@google.comsc_module::sc_module(const char *_name) : sc_module(sc_module_name(_name))
23712855Sgabeblack@google.com{
23812855Sgabeblack@google.com    _gem5_module->deprecatedConstructor();
23912855Sgabeblack@google.com    SC_REPORT_WARNING("(W569) sc_module(const char*), "
24012855Sgabeblack@google.com            "sc_module(const std::string&) have been deprecated, use "
24112855Sgabeblack@google.com            "sc_module(const sc_module_name&)", _name);
24212855Sgabeblack@google.com}
24312855Sgabeblack@google.comsc_module::sc_module(const std::string &_name) :
24412855Sgabeblack@google.com    sc_module(sc_module_name(_name.c_str()))
24512855Sgabeblack@google.com{
24612855Sgabeblack@google.com    _gem5_module->deprecatedConstructor();
24712855Sgabeblack@google.com    SC_REPORT_WARNING("(W569) sc_module(const char*), "
24812855Sgabeblack@google.com            "sc_module(const std::string&) have been deprecated, use "
24912855Sgabeblack@google.com            "sc_module(const sc_module_name&)", _name.c_str());
25012855Sgabeblack@google.com}
25112855Sgabeblack@google.com
25212855Sgabeblack@google.comvoid
25312855Sgabeblack@google.comsc_module::end_module()
25412855Sgabeblack@google.com{
25512855Sgabeblack@google.com    _gem5_module->endModule();
25612855Sgabeblack@google.com}
25712855Sgabeblack@google.com
25812855Sgabeblack@google.comvoid
25912855Sgabeblack@google.comsc_module::reset_signal_is(const sc_in<bool> &port, bool val)
26012855Sgabeblack@google.com{
26112855Sgabeblack@google.com    sc_gem5::newResetSensitivityPort(
26212855Sgabeblack@google.com            ::sc_gem5::Process::newest(), &port, val, true);
26312855Sgabeblack@google.com}
26412855Sgabeblack@google.com
26512855Sgabeblack@google.comvoid
26612855Sgabeblack@google.comsc_module::reset_signal_is(const sc_inout<bool> &port, bool val)
26712855Sgabeblack@google.com{
26812855Sgabeblack@google.com    sc_gem5::newResetSensitivityPort(
26912855Sgabeblack@google.com            ::sc_gem5::Process::newest(), &port, val, true);
27012855Sgabeblack@google.com}
27112855Sgabeblack@google.com
27212855Sgabeblack@google.comvoid
27312855Sgabeblack@google.comsc_module::reset_signal_is(const sc_out<bool> &port, bool val)
27412855Sgabeblack@google.com{
27512855Sgabeblack@google.com    sc_gem5::newResetSensitivityPort(
27612855Sgabeblack@google.com            ::sc_gem5::Process::newest(), &port, val, true);
27712855Sgabeblack@google.com}
27812855Sgabeblack@google.com
27912855Sgabeblack@google.comvoid
28012855Sgabeblack@google.comsc_module::reset_signal_is(const sc_signal_in_if<bool> &signal, bool val)
28112855Sgabeblack@google.com{
28212855Sgabeblack@google.com    sc_gem5::newResetSensitivitySignal(
28312855Sgabeblack@google.com            ::sc_gem5::Process::newest(), &signal, val, true);
28412855Sgabeblack@google.com}
28512855Sgabeblack@google.com
28612855Sgabeblack@google.com
28712855Sgabeblack@google.comvoid
28812855Sgabeblack@google.comsc_module::async_reset_signal_is(const sc_in<bool> &port, bool val)
28912855Sgabeblack@google.com{
29012855Sgabeblack@google.com    sc_gem5::newResetSensitivityPort(
29112855Sgabeblack@google.com            ::sc_gem5::Process::newest(), &port, val, false);
29212855Sgabeblack@google.com}
29312855Sgabeblack@google.com
29412855Sgabeblack@google.comvoid
29512855Sgabeblack@google.comsc_module::async_reset_signal_is(const sc_inout<bool> &port, bool val)
29612855Sgabeblack@google.com{
29712855Sgabeblack@google.com    sc_gem5::newResetSensitivityPort(
29812855Sgabeblack@google.com            ::sc_gem5::Process::newest(), &port, val, false);
29912855Sgabeblack@google.com}
30012855Sgabeblack@google.com
30112855Sgabeblack@google.comvoid
30212855Sgabeblack@google.comsc_module::async_reset_signal_is(const sc_out<bool> &port, bool val)
30312855Sgabeblack@google.com{
30412855Sgabeblack@google.com    sc_gem5::newResetSensitivityPort(
30512855Sgabeblack@google.com            ::sc_gem5::Process::newest(), &port, val, false);
30612855Sgabeblack@google.com}
30712855Sgabeblack@google.com
30812855Sgabeblack@google.comvoid
30912855Sgabeblack@google.comsc_module::async_reset_signal_is(const sc_signal_in_if<bool> &signal, bool val)
31012855Sgabeblack@google.com{
31112855Sgabeblack@google.com    sc_gem5::newResetSensitivitySignal(
31212855Sgabeblack@google.com            ::sc_gem5::Process::newest(), &signal, val, false);
31312855Sgabeblack@google.com}
31412855Sgabeblack@google.com
31512855Sgabeblack@google.com
31612855Sgabeblack@google.comvoid
31712855Sgabeblack@google.comsc_module::dont_initialize()
31812855Sgabeblack@google.com{
31912855Sgabeblack@google.com    ::sc_gem5::Process::newest()->dontInitialize(true);
32012855Sgabeblack@google.com}
32112855Sgabeblack@google.com
32212855Sgabeblack@google.comvoid
32312855Sgabeblack@google.comsc_module::set_stack_size(size_t size)
32412855Sgabeblack@google.com{
32512855Sgabeblack@google.com    ::sc_gem5::Process::newest()->setStackSize(size);
32612855Sgabeblack@google.com}
32712855Sgabeblack@google.com
32812855Sgabeblack@google.com
32912855Sgabeblack@google.comvoid sc_module::next_trigger() { ::sc_core::next_trigger(); }
33012855Sgabeblack@google.com
33112855Sgabeblack@google.comvoid
33212855Sgabeblack@google.comsc_module::next_trigger(const sc_event &e)
33312855Sgabeblack@google.com{
33412855Sgabeblack@google.com    ::sc_core::next_trigger(e);
33512855Sgabeblack@google.com}
33612855Sgabeblack@google.com
33712855Sgabeblack@google.comvoid
33812855Sgabeblack@google.comsc_module::next_trigger(const sc_event_or_list &eol)
33912855Sgabeblack@google.com{
34012855Sgabeblack@google.com    ::sc_core::next_trigger(eol);
34112855Sgabeblack@google.com}
34212855Sgabeblack@google.com
34312855Sgabeblack@google.comvoid
34412855Sgabeblack@google.comsc_module::next_trigger(const sc_event_and_list &eal)
34512855Sgabeblack@google.com{
34612855Sgabeblack@google.com    ::sc_core::next_trigger(eal);
34712855Sgabeblack@google.com}
34812855Sgabeblack@google.com
34912855Sgabeblack@google.comvoid
35012855Sgabeblack@google.comsc_module::next_trigger(const sc_time &t)
35112855Sgabeblack@google.com{
35212855Sgabeblack@google.com    ::sc_core::next_trigger(t);
35312855Sgabeblack@google.com}
35412855Sgabeblack@google.com
35512855Sgabeblack@google.comvoid
35612855Sgabeblack@google.comsc_module::next_trigger(double d, sc_time_unit u)
35712855Sgabeblack@google.com{
35812855Sgabeblack@google.com    ::sc_core::next_trigger(d, u);
35912855Sgabeblack@google.com}
36012855Sgabeblack@google.com
36112855Sgabeblack@google.comvoid
36212855Sgabeblack@google.comsc_module::next_trigger(const sc_time &t, const sc_event &e)
36312855Sgabeblack@google.com{
36412855Sgabeblack@google.com    ::sc_core::next_trigger(t, e);
36512855Sgabeblack@google.com}
36612855Sgabeblack@google.com
36712855Sgabeblack@google.comvoid
36812855Sgabeblack@google.comsc_module::next_trigger(double d, sc_time_unit u, const sc_event &e)
36912855Sgabeblack@google.com{
37012855Sgabeblack@google.com    ::sc_core::next_trigger(d, u, e);
37112855Sgabeblack@google.com}
37212855Sgabeblack@google.com
37312855Sgabeblack@google.comvoid
37412855Sgabeblack@google.comsc_module::next_trigger(const sc_time &t, const sc_event_or_list &eol)
37512855Sgabeblack@google.com{
37612855Sgabeblack@google.com    ::sc_core::next_trigger(t, eol);
37712855Sgabeblack@google.com}
37812855Sgabeblack@google.com
37912855Sgabeblack@google.comvoid
38012855Sgabeblack@google.comsc_module::next_trigger(double d, sc_time_unit u, const sc_event_or_list &eol)
38112855Sgabeblack@google.com{
38212855Sgabeblack@google.com    ::sc_core::next_trigger(d, u, eol);
38312855Sgabeblack@google.com}
38412855Sgabeblack@google.com
38512855Sgabeblack@google.comvoid
38612855Sgabeblack@google.comsc_module::next_trigger(const sc_time &t, const sc_event_and_list &eal)
38712855Sgabeblack@google.com{
38812855Sgabeblack@google.com    ::sc_core::next_trigger(t, eal);
38912855Sgabeblack@google.com}
39012855Sgabeblack@google.com
39112855Sgabeblack@google.comvoid
39212855Sgabeblack@google.comsc_module::next_trigger(double d, sc_time_unit u, const sc_event_and_list &eal)
39312855Sgabeblack@google.com{
39412855Sgabeblack@google.com    ::sc_core::next_trigger(d, u, eal);
39512855Sgabeblack@google.com}
39612855Sgabeblack@google.com
39712855Sgabeblack@google.com
39812855Sgabeblack@google.combool
39912855Sgabeblack@google.comsc_module::timed_out()
40012855Sgabeblack@google.com{
40112855Sgabeblack@google.com    return ::sc_core::timed_out();
40212855Sgabeblack@google.com}
40312855Sgabeblack@google.com
40412855Sgabeblack@google.com
40512855Sgabeblack@google.comvoid
40612855Sgabeblack@google.comsc_module::wait()
40712855Sgabeblack@google.com{
40812855Sgabeblack@google.com    ::sc_core::wait();
40912855Sgabeblack@google.com}
41012855Sgabeblack@google.com
41112855Sgabeblack@google.comvoid
41212855Sgabeblack@google.comsc_module::wait(int i)
41312855Sgabeblack@google.com{
41412855Sgabeblack@google.com    ::sc_core::wait(i);
41512855Sgabeblack@google.com}
41612855Sgabeblack@google.com
41712855Sgabeblack@google.comvoid
41812855Sgabeblack@google.comsc_module::wait(const sc_event &e)
41912855Sgabeblack@google.com{
42012855Sgabeblack@google.com    ::sc_core::wait(e);
42112855Sgabeblack@google.com}
42212855Sgabeblack@google.com
42312855Sgabeblack@google.comvoid
42412855Sgabeblack@google.comsc_module::wait(const sc_event_or_list &eol)
42512855Sgabeblack@google.com{
42612855Sgabeblack@google.com    ::sc_core::wait(eol);
42712855Sgabeblack@google.com}
42812855Sgabeblack@google.com
42912855Sgabeblack@google.comvoid
43012855Sgabeblack@google.comsc_module::wait(const sc_event_and_list &eal)
43112855Sgabeblack@google.com{
43212855Sgabeblack@google.com    ::sc_core::wait(eal);
43312855Sgabeblack@google.com}
43412855Sgabeblack@google.com
43512855Sgabeblack@google.comvoid
43612855Sgabeblack@google.comsc_module::wait(const sc_time &t)
43712855Sgabeblack@google.com{
43812855Sgabeblack@google.com    ::sc_core::wait(t);
43912855Sgabeblack@google.com}
44012855Sgabeblack@google.com
44112855Sgabeblack@google.comvoid
44212855Sgabeblack@google.comsc_module::wait(double d, sc_time_unit u)
44312855Sgabeblack@google.com{
44412855Sgabeblack@google.com    ::sc_core::wait(d, u);
44512855Sgabeblack@google.com}
44612855Sgabeblack@google.com
44712855Sgabeblack@google.comvoid
44812855Sgabeblack@google.comsc_module::wait(const sc_time &t, const sc_event &e)
44912855Sgabeblack@google.com{
45012855Sgabeblack@google.com    ::sc_core::wait(t, e);
45112855Sgabeblack@google.com}
45212855Sgabeblack@google.com
45312855Sgabeblack@google.comvoid
45412855Sgabeblack@google.comsc_module::wait(double d, sc_time_unit u, const sc_event &e)
45512855Sgabeblack@google.com{
45612855Sgabeblack@google.com    ::sc_core::wait(d, u, e);
457}
458
459void
460sc_module::wait(const sc_time &t, const sc_event_or_list &eol)
461{
462    ::sc_core::wait(t, eol);
463}
464
465void
466sc_module::wait(double d, sc_time_unit u, const sc_event_or_list &eol)
467{
468    ::sc_core::wait(d, u, eol);
469}
470
471void
472sc_module::wait(const sc_time &t, const sc_event_and_list &eal)
473{
474    ::sc_core::wait(t, eal);
475}
476
477void
478sc_module::wait(double d, sc_time_unit u, const sc_event_and_list &eal)
479{
480    ::sc_core::wait(d, u, eal);
481}
482
483
484void
485sc_module::halt()
486{
487    ::sc_core::halt();
488}
489
490void
491sc_module::at_posedge(const sc_signal_in_if<bool> &s)
492{
493    ::sc_core::at_posedge(s);
494}
495
496void
497sc_module::at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &s)
498{
499    ::sc_core::at_posedge(s);
500}
501
502void
503sc_module::at_negedge(const sc_signal_in_if<bool> &s)
504{
505    ::sc_core::at_negedge(s);
506}
507
508void
509sc_module::at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &s)
510{
511    ::sc_core::at_negedge(s);
512}
513
514
515void
516next_trigger()
517{
518    sc_gem5::Process *p = sc_gem5::scheduler.current();
519    p->cancelTimeout();
520    p->clearDynamic();
521}
522
523void
524next_trigger(const sc_event &e)
525{
526    sc_gem5::Process *p = sc_gem5::scheduler.current();
527    p->cancelTimeout();
528    ::sc_gem5::newDynamicSensitivityEvent(p, &e);
529}
530
531void
532next_trigger(const sc_event_or_list &eol)
533{
534    sc_gem5::Process *p = sc_gem5::scheduler.current();
535    p->cancelTimeout();
536    ::sc_gem5::newDynamicSensitivityEventOrList(p, &eol);
537}
538
539void
540next_trigger(const sc_event_and_list &eal)
541{
542    sc_gem5::Process *p = sc_gem5::scheduler.current();
543    p->cancelTimeout();
544    ::sc_gem5::newDynamicSensitivityEventAndList(p, &eal);
545}
546
547void
548next_trigger(const sc_time &t)
549{
550    sc_gem5::Process *p = sc_gem5::scheduler.current();
551    p->setTimeout(t);
552    p->clearDynamic();
553}
554
555void
556next_trigger(double d, sc_time_unit u)
557{
558    next_trigger(sc_time(d, u));
559}
560
561void
562next_trigger(const sc_time &t, const sc_event &e)
563{
564    sc_gem5::Process *p = sc_gem5::scheduler.current();
565    p->setTimeout(t);
566    ::sc_gem5::newDynamicSensitivityEvent(p, &e);
567}
568
569void
570next_trigger(double d, sc_time_unit u, const sc_event &e)
571{
572    next_trigger(sc_time(d, u), e);
573}
574
575void
576next_trigger(const sc_time &t, const sc_event_or_list &eol)
577{
578    sc_gem5::Process *p = sc_gem5::scheduler.current();
579    p->setTimeout(t);
580    ::sc_gem5::newDynamicSensitivityEventOrList(p, &eol);
581}
582
583void
584next_trigger(double d, sc_time_unit u, const sc_event_or_list &eol)
585{
586    next_trigger(sc_time(d, u), eol);
587}
588
589void
590next_trigger(const sc_time &t, const sc_event_and_list &eal)
591{
592    sc_gem5::Process *p = sc_gem5::scheduler.current();
593    p->setTimeout(t);
594    ::sc_gem5::newDynamicSensitivityEventAndList(p, &eal);
595}
596
597void
598next_trigger(double d, sc_time_unit u, const sc_event_and_list &eal)
599{
600    next_trigger(sc_time(d, u), eal);
601}
602
603bool
604timed_out()
605{
606    ::sc_gem5::Process *p = sc_gem5::scheduler.current();
607    if (!p)
608        return false;
609    else
610        return p->timedOut();
611}
612
613
614namespace
615{
616
617bool
618waitErrorCheck(sc_gem5::Process *p)
619{
620    if (p->procKind() == SC_METHOD_PROC_) {
621        SC_REPORT_ERROR(
622                "(E519) wait() is only allowed in SC_THREADs and SC_CTHREADs",
623                "\n        in SC_METHODs use next_trigger() instead");
624        return true;
625    }
626    return false;
627}
628
629} // anonymous namespace
630
631void
632wait()
633{
634    sc_gem5::Process *p = sc_gem5::scheduler.current();
635    if (waitErrorCheck(p))
636        return;
637    p->cancelTimeout();
638    p->clearDynamic();
639    sc_gem5::scheduler.yield();
640}
641
642void
643wait(int n)
644{
645    if (n <= 0) {
646        std::string msg = csprintf("n = %d", n);
647        SC_REPORT_ERROR("(E525) wait(n) is only valid for n > 0", msg.c_str());
648    }
649    sc_gem5::Process *p = sc_gem5::scheduler.current();
650    p->waitCount(n - 1);
651    wait();
652}
653
654void
655wait(const sc_event &e)
656{
657    sc_gem5::Process *p = sc_gem5::scheduler.current();
658    if (waitErrorCheck(p))
659        return;
660    p->cancelTimeout();
661    ::sc_gem5::newDynamicSensitivityEvent(p, &e);
662    sc_gem5::scheduler.yield();
663}
664
665void
666wait(const sc_event_or_list &eol)
667{
668    sc_gem5::Process *p = sc_gem5::scheduler.current();
669    if (waitErrorCheck(p))
670        return;
671    p->cancelTimeout();
672    ::sc_gem5::newDynamicSensitivityEventOrList(p, &eol);
673    sc_gem5::scheduler.yield();
674}
675
676void
677wait(const sc_event_and_list &eal)
678{
679    sc_gem5::Process *p = sc_gem5::scheduler.current();
680    if (waitErrorCheck(p))
681        return;
682    p->cancelTimeout();
683    ::sc_gem5::newDynamicSensitivityEventAndList(p, &eal);
684    sc_gem5::scheduler.yield();
685}
686
687void
688wait(const sc_time &t)
689{
690    sc_gem5::Process *p = sc_gem5::scheduler.current();
691    if (waitErrorCheck(p))
692        return;
693    p->setTimeout(t);
694    p->clearDynamic();
695    sc_gem5::scheduler.yield();
696}
697
698void
699wait(double d, sc_time_unit u)
700{
701    wait(sc_time(d, u));
702}
703
704void
705wait(const sc_time &t, const sc_event &e)
706{
707    sc_gem5::Process *p = sc_gem5::scheduler.current();
708    if (waitErrorCheck(p))
709        return;
710    p->setTimeout(t);
711    ::sc_gem5::newDynamicSensitivityEvent(p, &e);
712    sc_gem5::scheduler.yield();
713}
714
715void
716wait(double d, sc_time_unit u, const sc_event &e)
717{
718    wait(sc_time(d, u), e);
719}
720
721void
722wait(const sc_time &t, const sc_event_or_list &eol)
723{
724    sc_gem5::Process *p = sc_gem5::scheduler.current();
725    if (waitErrorCheck(p))
726        return;
727    p->setTimeout(t);
728    ::sc_gem5::newDynamicSensitivityEventOrList(p, &eol);
729    sc_gem5::scheduler.yield();
730}
731
732void
733wait(double d, sc_time_unit u, const sc_event_or_list &eol)
734{
735    wait(sc_time(d, u), eol);
736}
737
738void
739wait(const sc_time &t, const sc_event_and_list &eal)
740{
741    sc_gem5::Process *p = sc_gem5::scheduler.current();
742    if (waitErrorCheck(p))
743        return;
744    p->setTimeout(t);
745    ::sc_gem5::newDynamicSensitivityEventAndList(p, &eal);
746    sc_gem5::scheduler.yield();
747}
748
749void
750wait(double d, sc_time_unit u, const sc_event_and_list &eal)
751{
752    wait(sc_time(d, u), eal);
753}
754
755void
756halt()
757{
758    ::sc_core::wait();
759    throw ::sc_gem5::ScHalt();
760}
761
762void
763at_posedge(const sc_signal_in_if<bool> &s)
764{
765    while (s.read())
766        wait();
767    while (!s.read())
768        wait();
769}
770
771void
772at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &s)
773{
774    while (s.read() == sc_dt::Log_1)
775        wait();
776    while (s.read() == sc_dt::Log_0)
777        wait();
778}
779
780void
781at_negedge(const sc_signal_in_if<bool> &s)
782{
783    while (!s.read())
784        wait();
785    while (s.read())
786        wait();
787}
788
789void
790at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &s)
791{
792    while (s.read() == sc_dt::Log_0)
793        wait();
794    while (s.read() == sc_dt::Log_1)
795        wait();
796}
797
798const char *
799sc_gen_unique_name(const char *seed)
800{
801    auto mod = sc_gem5::pickParentModule();
802    return mod ? mod->uniqueName(seed) :
803        ::sc_gem5::nameGen.gen(seed);
804}
805
806bool
807sc_hierarchical_name_exists(const char *name)
808{
809    return sc_gem5::findEvent(name) != sc_gem5::allEvents.end() ||
810        ::sc_gem5::findObject(name, sc_gem5::allObjects);
811}
812
813bool
814sc_start_of_simulation_invoked()
815{
816    return ::sc_gem5::kernel->startOfSimulationComplete();
817}
818
819bool
820sc_end_of_simulation_invoked()
821{
822    return ::sc_gem5::kernel->endOfSimulationComplete();
823}
824
825sc_module *
826sc_module_sc_new(sc_module *mod)
827{
828    static std::vector<std::unique_ptr<sc_module> > modules;
829    modules.emplace_back(mod);
830    return mod;
831}
832
833} // namespace sc_core
834