sc_module.cc revision 13303
1/* 2 * Copyright 2018 Google, Inc. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer; 8 * redistributions in binary form must reproduce the above copyright 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution; 11 * neither the name of the copyright holders nor the names of its 12 * contributors may be used to endorse or promote products derived from 13 * this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 * Authors: Gabe Black 28 */ 29 30#include <memory> 31#include <string> 32#include <vector> 33 34#include "base/logging.hh" 35#include "systemc/core/event.hh" 36#include "systemc/core/kernel.hh" 37#include "systemc/core/module.hh" 38#include "systemc/core/object.hh" 39#include "systemc/core/port.hh" 40#include "systemc/core/process_types.hh" 41#include "systemc/core/sensitivity.hh" 42#include "systemc/ext/channel/sc_in.hh" 43#include "systemc/ext/channel/sc_inout.hh" 44#include "systemc/ext/channel/sc_out.hh" 45#include "systemc/ext/channel/sc_signal_in_if.hh" 46#include "systemc/ext/core/sc_module.hh" 47#include "systemc/ext/core/sc_module_name.hh" 48#include "systemc/ext/dt/bit/sc_logic.hh" 49#include "systemc/ext/utils/sc_report_handler.hh" 50 51namespace sc_gem5 52{ 53 54Process * 55newMethodProcess(const char *name, ProcessFuncWrapper *func) 56{ 57 Method *p = new Method(name, func); 58 if (::sc_core::sc_is_running()) { 59 std::string name = p->name(); 60 delete p; 61 SC_REPORT_ERROR("(E541) call to SC_METHOD in sc_module while " 62 "simulation running", name.c_str()); 63 return nullptr; 64 } 65 scheduler.reg(p); 66 return p; 67} 68 69Process * 70newThreadProcess(const char *name, ProcessFuncWrapper *func) 71{ 72 Thread *p = new Thread(name, func); 73 if (::sc_core::sc_is_running()) { 74 std::string name = p->name(); 75 delete p; 76 SC_REPORT_ERROR("(E542) call to SC_THREAD in sc_module while " 77 "simulation running", name.c_str()); 78 return nullptr; 79 } 80 scheduler.reg(p); 81 return p; 82} 83 84Process * 85newCThreadProcess(const char *name, ProcessFuncWrapper *func) 86{ 87 CThread *p = new CThread(name, func); 88 if (::sc_core::sc_is_running()) { 89 std::string name = p->name(); 90 delete p; 91 SC_REPORT_ERROR("(E543) call to SC_CTHREAD in sc_module while " 92 "simulation running", name.c_str()); 93 return nullptr; 94 } 95 scheduler.reg(p); 96 p->dontInitialize(true); 97 return p; 98} 99 100} // namespace sc_gem5 101 102namespace sc_core 103{ 104 105sc_bind_proxy::sc_bind_proxy(sc_interface &_interface) : 106 _interface(&_interface), _port(nullptr) 107{} 108 109sc_bind_proxy::sc_bind_proxy(sc_port_base &_port) : 110 _interface(nullptr), _port(&_port) 111{} 112 113const sc_bind_proxy SC_BIND_PROXY_NUL(*(sc_port_base *)nullptr); 114 115sc_module::~sc_module() { delete _gem5_module; } 116 117const sc_bind_proxy SC_BIND_PROXY_NIL(*(sc_port_base *)nullptr); 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("(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