sc_module.cc revision 13785
12SN/A/* 21762SN/A * Copyright 2018 Google, Inc. 32SN/A * 42SN/A * Redistribution and use in source and binary forms, with or without 52SN/A * modification, are permitted provided that the following conditions are 62SN/A * met: redistributions of source code must retain the above copyright 72SN/A * notice, this list of conditions and the following disclaimer; 82SN/A * redistributions in binary form must reproduce the above copyright 92SN/A * notice, this list of conditions and the following disclaimer in the 102SN/A * documentation and/or other materials provided with the distribution; 112SN/A * neither the name of the copyright holders nor the names of its 122SN/A * contributors may be used to endorse or promote products derived from 132SN/A * this software without specific prior written permission. 142SN/A * 152SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 162SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 172SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 182SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 192SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 202SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 212SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 252SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262SN/A * 272665SN/A * Authors: Gabe Black 282665SN/A */ 292665SN/A 302665SN/A#include <memory> 312665SN/A#include <string> 322SN/A#include <vector> 332SN/A 341722SN/A#include "base/logging.hh" 355480Snate@binkert.org#include "systemc/core/event.hh" 362SN/A#include "systemc/core/kernel.hh" 372SN/A#include "systemc/core/module.hh" 38146SN/A#include "systemc/core/object.hh" 392SN/A#include "systemc/core/port.hh" 402SN/A#include "systemc/core/process_types.hh" 412158SN/A#include "systemc/core/sensitivity.hh" 42146SN/A#include "systemc/ext/channel/sc_in.hh" 431805SN/A#include "systemc/ext/channel/sc_inout.hh" 44146SN/A#include "systemc/ext/channel/sc_out.hh" 451717SN/A#include "systemc/ext/channel/sc_signal_in_if.hh" 462680SN/A#include "systemc/ext/core/messages.hh" 478232Snate@binkert.org#include "systemc/ext/core/sc_module.hh" 485480Snate@binkert.org#include "systemc/ext/core/sc_module_name.hh" 492521SN/A#include "systemc/ext/dt/bit/sc_logic.hh" 5056SN/A#include "systemc/ext/utils/sc_report_handler.hh" 515478SN/A 523348SN/Anamespace sc_gem5 533348SN/A{ 542521SN/A 555480Snate@binkert.orgProcess * 561805SN/AnewMethodProcess(const char *name, ProcessFuncWrapper *func) 572SN/A{ 582SN/A Method *p = new Method(name, func); 592107SN/A if (::sc_core::sc_is_running()) { 602SN/A std::string name = p->name(); 615480Snate@binkert.org delete p; 625478SN/A SC_REPORT_ERROR(sc_core::SC_ID_MODULE_METHOD_AFTER_START_, 634762SN/A name.c_str()); 642SN/A return nullptr; 65545SN/A } 662521SN/A scheduler.reg(p); 672521SN/A return p; 682521SN/A} 692521SN/A 702SN/AProcess * 712SN/AnewThreadProcess(const char *name, ProcessFuncWrapper *func) 722SN/A{ 73926SN/A Thread *p = new Thread(name, func); 74926SN/A if (::sc_core::sc_is_running()) { 75926SN/A std::string name = p->name(); 76926SN/A delete p; 77926SN/A SC_REPORT_ERROR(sc_core::SC_ID_MODULE_THREAD_AFTER_START_, 78926SN/A name.c_str()); 79926SN/A return nullptr; 804395SN/A } 811805SN/A scheduler.reg(p); 822SN/A return p; 832SN/A} 841634SN/A 855480Snate@binkert.orgProcess * 861634SN/AnewCThreadProcess(const char *name, ProcessFuncWrapper *func) 872549SN/A{ 885714Shsul@eecs.umich.edu CThread *p = new CThread(name, func); 891634SN/A if (::sc_core::sc_is_running()) { 901634SN/A std::string name = p->name(); 911634SN/A delete p; 921634SN/A SC_REPORT_ERROR(sc_core::SC_ID_MODULE_CTHREAD_AFTER_START_, 931634SN/A name.c_str()); 942521SN/A return nullptr; 951634SN/A } 961634SN/A scheduler.reg(p); 972512SN/A p->dontInitialize(true); 985480Snate@binkert.org return p; 992SN/A} 1002SN/A 1012512SN/A} // namespace sc_gem5 1022512SN/A 1032512SN/Anamespace sc_core 1042512SN/A{ 105540SN/A 1062641SN/Asc_bind_proxy::sc_bind_proxy() : _interface(nullptr), _port(nullptr) {} 1072522SN/A 1082641SN/Asc_bind_proxy::sc_bind_proxy(sc_interface &_interface) : 1092512SN/A _interface(&_interface), _port(nullptr) 1102630SN/A{} 1114986SN/A 1122521SN/Asc_bind_proxy::sc_bind_proxy(sc_port_base &_port) : 1132641SN/A _interface(nullptr), _port(&_port) 114873SN/A{} 115873SN/A 116873SN/Aconst sc_bind_proxy SC_BIND_PROXY_NIL; 117873SN/A 118873SN/A::Port & 1192630SN/Asc_module::gem5_getPort(const std::string &if_name, int idx) 120873SN/A{ 121873SN/A fatal("%s does not have any port named %s\n", name(), if_name); 1222630SN/A} 123873SN/A 124873SN/Asc_module::~sc_module() { delete _gem5_module; } 1252630SN/A 126873SN/Avoid 127873SN/Asc_module::operator () (const sc_bind_proxy &p001, 1282630SN/A const sc_bind_proxy &p002, 129873SN/A const sc_bind_proxy &p003, 130873SN/A const sc_bind_proxy &p004, 1312512SN/A const sc_bind_proxy &p005, 1322512SN/A const sc_bind_proxy &p006, 1332512SN/A const sc_bind_proxy &p007, 1344870SN/A const sc_bind_proxy &p008, 135873SN/A const sc_bind_proxy &p009, 1365480Snate@binkert.org const sc_bind_proxy &p010, 1372630SN/A const sc_bind_proxy &p011, 138873SN/A const sc_bind_proxy &p012, 139873SN/A const sc_bind_proxy &p013, 140873SN/A const sc_bind_proxy &p014, 141873SN/A const sc_bind_proxy &p015, 142873SN/A const sc_bind_proxy &p016, 1435478SN/A const sc_bind_proxy &p017, 144873SN/A const sc_bind_proxy &p018, 145873SN/A const sc_bind_proxy &p019, 1462630SN/A const sc_bind_proxy &p020, 147873SN/A const sc_bind_proxy &p021, 148873SN/A const sc_bind_proxy &p022, 1492630SN/A const sc_bind_proxy &p023, 150873SN/A const sc_bind_proxy &p024, 151873SN/A const sc_bind_proxy &p025, 1522630SN/A const sc_bind_proxy &p026, 153873SN/A const sc_bind_proxy &p027, 154873SN/A const sc_bind_proxy &p028, 1552630SN/A const sc_bind_proxy &p029, 156873SN/A const sc_bind_proxy &p030, 157873SN/A const sc_bind_proxy &p031, 1582630SN/A const sc_bind_proxy &p032, 159873SN/A const sc_bind_proxy &p033, 160873SN/A const sc_bind_proxy &p034, 1612630SN/A const sc_bind_proxy &p035, 162873SN/A const sc_bind_proxy &p036, 163873SN/A const sc_bind_proxy &p037, 1642630SN/A const sc_bind_proxy &p038, 165873SN/A const sc_bind_proxy &p039, 166873SN/A const sc_bind_proxy &p040, 1672630SN/A const sc_bind_proxy &p041, 168873SN/A const sc_bind_proxy &p042, 169873SN/A const sc_bind_proxy &p043, 1702630SN/A const sc_bind_proxy &p044, 171873SN/A const sc_bind_proxy &p045, 172873SN/A const sc_bind_proxy &p046, 1732630SN/A const sc_bind_proxy &p047, 174873SN/A const sc_bind_proxy &p048, 175873SN/A const sc_bind_proxy &p049, 1762630SN/A const sc_bind_proxy &p050, 177873SN/A const sc_bind_proxy &p051, 178873SN/A const sc_bind_proxy &p052, 1792114SN/A const sc_bind_proxy &p053, 1802114SN/A const sc_bind_proxy &p054, 1812114SN/A const sc_bind_proxy &p055, 1822114SN/A const sc_bind_proxy &p056, 1832630SN/A const sc_bind_proxy &p057, 1842114SN/A const sc_bind_proxy &p058, 1852114SN/A const sc_bind_proxy &p059, 186873SN/A const sc_bind_proxy &p060, 1875480Snate@binkert.org const sc_bind_proxy &p061, 1882630SN/A const sc_bind_proxy &p062, 189873SN/A const sc_bind_proxy &p063, 190873SN/A const sc_bind_proxy &p064) 1914870SN/A{ 1922SN/A std::vector<const ::sc_core::sc_bind_proxy *> proxies; 1932512SN/A auto insert = [&proxies](const ::sc_core::sc_bind_proxy &p) -> bool { 1942SN/A if (!p.port() && !p.interface()) 1952SN/A return false; 1962512SN/A proxies.push_back(&p); 1975480Snate@binkert.org return true; 1982SN/A }; 1992641SN/A insert(p001) && insert(p002) && insert(p003) && insert(p004) && 2002641SN/A insert(p005) && insert(p006) && insert(p007) && insert(p008) && 201430SN/A insert(p009) && insert(p010) && insert(p011) && insert(p012) && 2022630SN/A insert(p013) && insert(p014) && insert(p015) && insert(p016) && 2032641SN/A insert(p017) && insert(p018) && insert(p019) && insert(p020) && 2042SN/A insert(p021) && insert(p022) && insert(p023) && insert(p024) && 205430SN/A insert(p025) && insert(p026) && insert(p027) && insert(p028) && 206430SN/A insert(p029) && insert(p030) && insert(p031) && insert(p032) && 2072SN/A insert(p033) && insert(p034) && insert(p035) && insert(p036) && 208430SN/A insert(p037) && insert(p038) && insert(p039) && insert(p040) && 2092SN/A insert(p041) && insert(p042) && insert(p043) && insert(p044) && 210430SN/A insert(p045) && insert(p046) && insert(p047) && insert(p048) && 2112SN/A insert(p049) && insert(p050) && insert(p051) && insert(p052) && 212430SN/A insert(p053) && insert(p054) && insert(p055) && insert(p056) && 2132SN/A insert(p057) && insert(p058) && insert(p059) && insert(p060) && 214430SN/A insert(p061) && insert(p062) && insert(p063) && insert(p064); 2152SN/A _gem5_module->bindPorts(proxies); 216430SN/A} 2172SN/A 218430SN/Asc_module & 2192SN/Asc_module::operator << (sc_interface &iface) 220430SN/A{ 2212SN/A (*this)(iface); 222430SN/A return *this; 2232SN/A} 2242SN/A 2252SN/Asc_module & 2262SN/Asc_module::operator << (sc_port_base &pb) 2272SN/A{ 2282SN/A (*this)(pb); 229430SN/A return *this; 2302SN/A} 231430SN/A 2325478SN/Asc_module & 233430SN/Asc_module::operator , (sc_interface &iface) 2342SN/A{ 235430SN/A (*this)(iface); 2362114SN/A return *this; 2372114SN/A} 2387823Ssteve.reinhardt@amd.com 2392114SN/Asc_module & 2402114SN/Asc_module::operator , (sc_port_base &pb) 2412114SN/A{ 2422114SN/A (*this)(pb); 2432114SN/A return *this; 2442SN/A} 2452SN/A 2464870SN/Aconst std::vector<sc_object *> & 2472SN/Asc_module::get_child_objects() const 2482512SN/A{ 249545SN/A return _gem5_module->obj()->get_child_objects(); 250545SN/A} 2512SN/A 2525480Snate@binkert.orgconst std::vector<sc_event *> & 2532SN/Asc_module::get_child_events() const 254222SN/A{ 255222SN/A return _gem5_module->obj()->get_child_events(); 256222SN/A} 257222SN/A 258222SN/Asc_module::sc_module() : 259222SN/A sc_object(sc_gem5::newModuleChecked()->name()), 260222SN/A _gem5_module(sc_gem5::currentModule()) 261222SN/A{ 262222SN/A if (sc_is_running()) 263222SN/A SC_REPORT_ERROR(SC_ID_INSERT_MODULE_, "simulation running"); 264222SN/A if (::sc_gem5::scheduler.elaborationDone()) 265222SN/A SC_REPORT_ERROR(SC_ID_INSERT_MODULE_, "elaboration done"); 266222SN/A} 267222SN/A 268222SN/Asc_module::sc_module(const sc_module_name &) : sc_module() {} 269430SN/Asc_module::sc_module(const char *_name) : sc_module(sc_module_name(_name)) 2702114SN/A{ 2712SN/A _gem5_module->deprecatedConstructor(); 2722SN/A SC_REPORT_WARNING(SC_ID_BAD_SC_MODULE_CONSTRUCTOR_, _name); 2732SN/A} 2745480Snate@binkert.orgsc_module::sc_module(const std::string &_name) : 2752SN/A sc_module(sc_module_name(_name.c_str())) 276222SN/A{ 277222SN/A _gem5_module->deprecatedConstructor(); 278222SN/A SC_REPORT_WARNING(SC_ID_BAD_SC_MODULE_CONSTRUCTOR_, _name.c_str()); 279222SN/A} 280222SN/A 281222SN/Avoid 282222SN/Asc_module::end_module() 283222SN/A{ 284222SN/A _gem5_module->endModule(); 285222SN/A} 286222SN/A 287222SN/Avoid 288222SN/Asc_module::reset_signal_is(const sc_in<bool> &port, bool val) 289222SN/A{ 290222SN/A ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), true, val); 291430SN/A} 2922114SN/A 293217SN/Avoid 2942SN/Asc_module::reset_signal_is(const sc_inout<bool> &port, bool val) 295217SN/A{ 2965480Snate@binkert.org ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), true, val); 297217SN/A} 298217SN/A 299217SN/Avoid 300217SN/Asc_module::reset_signal_is(const sc_out<bool> &port, bool val) 301217SN/A{ 3025480Snate@binkert.org ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), true, val); 303217SN/A} 304237SN/A 3052SN/Avoid 3062SN/Asc_module::reset_signal_is(const sc_signal_in_if<bool> &signal, bool val) 3075480Snate@binkert.org{ 3085480Snate@binkert.org ::sc_gem5::newReset(&signal, ::sc_gem5::Process::newest(), true, val); 3092SN/A} 3105480Snate@binkert.org 3112SN/A 312void 313sc_module::async_reset_signal_is(const sc_in<bool> &port, bool val) 314{ 315 ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), false, val); 316} 317 318void 319sc_module::async_reset_signal_is(const sc_inout<bool> &port, bool val) 320{ 321 ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), false, val); 322} 323 324void 325sc_module::async_reset_signal_is(const sc_out<bool> &port, bool val) 326{ 327 ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), false, val); 328} 329 330void 331sc_module::async_reset_signal_is(const sc_signal_in_if<bool> &signal, bool val) 332{ 333 ::sc_gem5::newReset(&signal, ::sc_gem5::Process::newest(), false, val); 334} 335 336 337void 338sc_module::dont_initialize() 339{ 340 ::sc_gem5::Process *p = ::sc_gem5::Process::newest(); 341 if (p->procKind() == SC_CTHREAD_PROC_) 342 SC_REPORT_WARNING(SC_ID_DONT_INITIALIZE_, ""); 343 p->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(SC_ID_WAIT_NOT_ALLOWED_, 646 "\n in SC_METHODs use next_trigger() instead"); 647 return true; 648 } 649 return false; 650} 651 652} // anonymous namespace 653 654void 655wait() 656{ 657 sc_gem5::Process *p = sc_gem5::scheduler.current(); 658 if (waitErrorCheck(p)) 659 return; 660 p->cancelTimeout(); 661 p->clearDynamic(); 662 sc_gem5::scheduler.yield(); 663} 664 665void 666wait(int n) 667{ 668 if (n <= 0) { 669 std::string msg = csprintf("n = %d", n); 670 SC_REPORT_ERROR(SC_ID_WAIT_N_INVALID_, msg.c_str()); 671 } 672 sc_gem5::Process *p = sc_gem5::scheduler.current(); 673 p->waitCount(n - 1); 674 wait(); 675} 676 677void 678wait(const sc_event &e) 679{ 680 sc_gem5::Process *p = sc_gem5::scheduler.current(); 681 if (waitErrorCheck(p)) 682 return; 683 p->cancelTimeout(); 684 ::sc_gem5::newDynamicSensitivityEvent(p, &e); 685 sc_gem5::scheduler.yield(); 686} 687 688void 689wait(const sc_event_or_list &eol) 690{ 691 sc_gem5::Process *p = sc_gem5::scheduler.current(); 692 if (waitErrorCheck(p)) 693 return; 694 p->cancelTimeout(); 695 ::sc_gem5::newDynamicSensitivityEventOrList(p, &eol); 696 sc_gem5::scheduler.yield(); 697} 698 699void 700wait(const sc_event_and_list &eal) 701{ 702 sc_gem5::Process *p = sc_gem5::scheduler.current(); 703 if (waitErrorCheck(p)) 704 return; 705 p->cancelTimeout(); 706 ::sc_gem5::newDynamicSensitivityEventAndList(p, &eal); 707 sc_gem5::scheduler.yield(); 708} 709 710void 711wait(const sc_time &t) 712{ 713 sc_gem5::Process *p = sc_gem5::scheduler.current(); 714 if (waitErrorCheck(p)) 715 return; 716 p->setTimeout(t); 717 p->clearDynamic(); 718 sc_gem5::scheduler.yield(); 719} 720 721void 722wait(double d, sc_time_unit u) 723{ 724 wait(sc_time(d, u)); 725} 726 727void 728wait(const sc_time &t, const sc_event &e) 729{ 730 sc_gem5::Process *p = sc_gem5::scheduler.current(); 731 if (waitErrorCheck(p)) 732 return; 733 p->setTimeout(t); 734 ::sc_gem5::newDynamicSensitivityEvent(p, &e); 735 sc_gem5::scheduler.yield(); 736} 737 738void 739wait(double d, sc_time_unit u, const sc_event &e) 740{ 741 wait(sc_time(d, u), e); 742} 743 744void 745wait(const sc_time &t, const sc_event_or_list &eol) 746{ 747 sc_gem5::Process *p = sc_gem5::scheduler.current(); 748 if (waitErrorCheck(p)) 749 return; 750 p->setTimeout(t); 751 ::sc_gem5::newDynamicSensitivityEventOrList(p, &eol); 752 sc_gem5::scheduler.yield(); 753} 754 755void 756wait(double d, sc_time_unit u, const sc_event_or_list &eol) 757{ 758 wait(sc_time(d, u), eol); 759} 760 761void 762wait(const sc_time &t, const sc_event_and_list &eal) 763{ 764 sc_gem5::Process *p = sc_gem5::scheduler.current(); 765 if (waitErrorCheck(p)) 766 return; 767 p->setTimeout(t); 768 ::sc_gem5::newDynamicSensitivityEventAndList(p, &eal); 769 sc_gem5::scheduler.yield(); 770} 771 772void 773wait(double d, sc_time_unit u, const sc_event_and_list &eal) 774{ 775 wait(sc_time(d, u), eal); 776} 777 778void 779halt() 780{ 781 ::sc_core::wait(); 782 throw ::sc_gem5::ScHalt(); 783} 784 785void 786at_posedge(const sc_signal_in_if<bool> &s) 787{ 788 while (s.read()) 789 wait(); 790 while (!s.read()) 791 wait(); 792} 793 794void 795at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &s) 796{ 797 while (s.read() == sc_dt::Log_1) 798 wait(); 799 while (s.read() == sc_dt::Log_0) 800 wait(); 801} 802 803void 804at_negedge(const sc_signal_in_if<bool> &s) 805{ 806 while (!s.read()) 807 wait(); 808 while (s.read()) 809 wait(); 810} 811 812void 813at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &s) 814{ 815 while (s.read() == sc_dt::Log_0) 816 wait(); 817 while (s.read() == sc_dt::Log_1) 818 wait(); 819} 820 821const char * 822sc_gen_unique_name(const char *seed) 823{ 824 if (!seed || seed[0] == '\0') { 825 SC_REPORT_ERROR(SC_ID_GEN_UNIQUE_NAME_, ""); 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