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