sc_module.cc revision 13315
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 *p = ::sc_gem5::Process::newest(); 342 if (p->procKind() == SC_CTHREAD_PROC_) { 343 SC_REPORT_WARNING("(W524) dont_initialize() has no effect for " 344 "SC_CTHREADs", ""); 345 } 346 p->dontInitialize(true); 347} 348 349void 350sc_module::set_stack_size(size_t size) 351{ 352 ::sc_gem5::Process::newest()->setStackSize(size); 353} 354 355 356void sc_module::next_trigger() { ::sc_core::next_trigger(); } 357 358void 359sc_module::next_trigger(const sc_event &e) 360{ 361 ::sc_core::next_trigger(e); 362} 363 364void 365sc_module::next_trigger(const sc_event_or_list &eol) 366{ 367 ::sc_core::next_trigger(eol); 368} 369 370void 371sc_module::next_trigger(const sc_event_and_list &eal) 372{ 373 ::sc_core::next_trigger(eal); 374} 375 376void 377sc_module::next_trigger(const sc_time &t) 378{ 379 ::sc_core::next_trigger(t); 380} 381 382void 383sc_module::next_trigger(double d, sc_time_unit u) 384{ 385 ::sc_core::next_trigger(d, u); 386} 387 388void 389sc_module::next_trigger(const sc_time &t, const sc_event &e) 390{ 391 ::sc_core::next_trigger(t, e); 392} 393 394void 395sc_module::next_trigger(double d, sc_time_unit u, const sc_event &e) 396{ 397 ::sc_core::next_trigger(d, u, e); 398} 399 400void 401sc_module::next_trigger(const sc_time &t, const sc_event_or_list &eol) 402{ 403 ::sc_core::next_trigger(t, eol); 404} 405 406void 407sc_module::next_trigger(double d, sc_time_unit u, const sc_event_or_list &eol) 408{ 409 ::sc_core::next_trigger(d, u, eol); 410} 411 412void 413sc_module::next_trigger(const sc_time &t, const sc_event_and_list &eal) 414{ 415 ::sc_core::next_trigger(t, eal); 416} 417 418void 419sc_module::next_trigger(double d, sc_time_unit u, const sc_event_and_list &eal) 420{ 421 ::sc_core::next_trigger(d, u, eal); 422} 423 424 425bool 426sc_module::timed_out() 427{ 428 return ::sc_core::timed_out(); 429} 430 431 432void 433sc_module::wait() 434{ 435 ::sc_core::wait(); 436} 437 438void 439sc_module::wait(int i) 440{ 441 ::sc_core::wait(i); 442} 443 444void 445sc_module::wait(const sc_event &e) 446{ 447 ::sc_core::wait(e); 448} 449 450void 451sc_module::wait(const sc_event_or_list &eol) 452{ 453 ::sc_core::wait(eol); 454} 455 456void 457sc_module::wait(const sc_event_and_list &eal) 458{ 459 ::sc_core::wait(eal); 460} 461 462void 463sc_module::wait(const sc_time &t) 464{ 465 ::sc_core::wait(t); 466} 467 468void 469sc_module::wait(double d, sc_time_unit u) 470{ 471 ::sc_core::wait(d, u); 472} 473 474void 475sc_module::wait(const sc_time &t, const sc_event &e) 476{ 477 ::sc_core::wait(t, e); 478} 479 480void 481sc_module::wait(double d, sc_time_unit u, const sc_event &e) 482{ 483 ::sc_core::wait(d, u, e); 484} 485 486void 487sc_module::wait(const sc_time &t, const sc_event_or_list &eol) 488{ 489 ::sc_core::wait(t, eol); 490} 491 492void 493sc_module::wait(double d, sc_time_unit u, const sc_event_or_list &eol) 494{ 495 ::sc_core::wait(d, u, eol); 496} 497 498void 499sc_module::wait(const sc_time &t, const sc_event_and_list &eal) 500{ 501 ::sc_core::wait(t, eal); 502} 503 504void 505sc_module::wait(double d, sc_time_unit u, const sc_event_and_list &eal) 506{ 507 ::sc_core::wait(d, u, eal); 508} 509 510 511void 512sc_module::halt() 513{ 514 ::sc_core::halt(); 515} 516 517void 518sc_module::at_posedge(const sc_signal_in_if<bool> &s) 519{ 520 ::sc_core::at_posedge(s); 521} 522 523void 524sc_module::at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &s) 525{ 526 ::sc_core::at_posedge(s); 527} 528 529void 530sc_module::at_negedge(const sc_signal_in_if<bool> &s) 531{ 532 ::sc_core::at_negedge(s); 533} 534 535void 536sc_module::at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &s) 537{ 538 ::sc_core::at_negedge(s); 539} 540 541 542void 543next_trigger() 544{ 545 sc_gem5::Process *p = sc_gem5::scheduler.current(); 546 p->cancelTimeout(); 547 p->clearDynamic(); 548} 549 550void 551next_trigger(const sc_event &e) 552{ 553 sc_gem5::Process *p = sc_gem5::scheduler.current(); 554 p->cancelTimeout(); 555 ::sc_gem5::newDynamicSensitivityEvent(p, &e); 556} 557 558void 559next_trigger(const sc_event_or_list &eol) 560{ 561 sc_gem5::Process *p = sc_gem5::scheduler.current(); 562 p->cancelTimeout(); 563 ::sc_gem5::newDynamicSensitivityEventOrList(p, &eol); 564} 565 566void 567next_trigger(const sc_event_and_list &eal) 568{ 569 sc_gem5::Process *p = sc_gem5::scheduler.current(); 570 p->cancelTimeout(); 571 ::sc_gem5::newDynamicSensitivityEventAndList(p, &eal); 572} 573 574void 575next_trigger(const sc_time &t) 576{ 577 sc_gem5::Process *p = sc_gem5::scheduler.current(); 578 p->setTimeout(t); 579 p->clearDynamic(); 580} 581 582void 583next_trigger(double d, sc_time_unit u) 584{ 585 next_trigger(sc_time(d, u)); 586} 587 588void 589next_trigger(const sc_time &t, const sc_event &e) 590{ 591 sc_gem5::Process *p = sc_gem5::scheduler.current(); 592 p->setTimeout(t); 593 ::sc_gem5::newDynamicSensitivityEvent(p, &e); 594} 595 596void 597next_trigger(double d, sc_time_unit u, const sc_event &e) 598{ 599 next_trigger(sc_time(d, u), e); 600} 601 602void 603next_trigger(const sc_time &t, const sc_event_or_list &eol) 604{ 605 sc_gem5::Process *p = sc_gem5::scheduler.current(); 606 p->setTimeout(t); 607 ::sc_gem5::newDynamicSensitivityEventOrList(p, &eol); 608} 609 610void 611next_trigger(double d, sc_time_unit u, const sc_event_or_list &eol) 612{ 613 next_trigger(sc_time(d, u), eol); 614} 615 616void 617next_trigger(const sc_time &t, const sc_event_and_list &eal) 618{ 619 sc_gem5::Process *p = sc_gem5::scheduler.current(); 620 p->setTimeout(t); 621 ::sc_gem5::newDynamicSensitivityEventAndList(p, &eal); 622} 623 624void 625next_trigger(double d, sc_time_unit u, const sc_event_and_list &eal) 626{ 627 next_trigger(sc_time(d, u), eal); 628} 629 630bool 631timed_out() 632{ 633 ::sc_gem5::Process *p = sc_gem5::scheduler.current(); 634 if (!p) 635 return false; 636 else 637 return p->timedOut(); 638} 639 640 641namespace 642{ 643 644bool 645waitErrorCheck(sc_gem5::Process *p) 646{ 647 if (p->procKind() == SC_METHOD_PROC_) { 648 SC_REPORT_ERROR( 649 "(E519) wait() is only allowed in SC_THREADs and SC_CTHREADs", 650 "\n in SC_METHODs use next_trigger() instead"); 651 return true; 652 } 653 return false; 654} 655 656} // anonymous namespace 657 658void 659wait() 660{ 661 sc_gem5::Process *p = sc_gem5::scheduler.current(); 662 if (waitErrorCheck(p)) 663 return; 664 p->cancelTimeout(); 665 p->clearDynamic(); 666 sc_gem5::scheduler.yield(); 667} 668 669void 670wait(int n) 671{ 672 if (n <= 0) { 673 std::string msg = csprintf("n = %d", n); 674 SC_REPORT_ERROR("(E525) wait(n) is only valid for n > 0", msg.c_str()); 675 } 676 sc_gem5::Process *p = sc_gem5::scheduler.current(); 677 p->waitCount(n - 1); 678 wait(); 679} 680 681void 682wait(const sc_event &e) 683{ 684 sc_gem5::Process *p = sc_gem5::scheduler.current(); 685 if (waitErrorCheck(p)) 686 return; 687 p->cancelTimeout(); 688 ::sc_gem5::newDynamicSensitivityEvent(p, &e); 689 sc_gem5::scheduler.yield(); 690} 691 692void 693wait(const sc_event_or_list &eol) 694{ 695 sc_gem5::Process *p = sc_gem5::scheduler.current(); 696 if (waitErrorCheck(p)) 697 return; 698 p->cancelTimeout(); 699 ::sc_gem5::newDynamicSensitivityEventOrList(p, &eol); 700 sc_gem5::scheduler.yield(); 701} 702 703void 704wait(const sc_event_and_list &eal) 705{ 706 sc_gem5::Process *p = sc_gem5::scheduler.current(); 707 if (waitErrorCheck(p)) 708 return; 709 p->cancelTimeout(); 710 ::sc_gem5::newDynamicSensitivityEventAndList(p, &eal); 711 sc_gem5::scheduler.yield(); 712} 713 714void 715wait(const sc_time &t) 716{ 717 sc_gem5::Process *p = sc_gem5::scheduler.current(); 718 if (waitErrorCheck(p)) 719 return; 720 p->setTimeout(t); 721 p->clearDynamic(); 722 sc_gem5::scheduler.yield(); 723} 724 725void 726wait(double d, sc_time_unit u) 727{ 728 wait(sc_time(d, u)); 729} 730 731void 732wait(const sc_time &t, const sc_event &e) 733{ 734 sc_gem5::Process *p = sc_gem5::scheduler.current(); 735 if (waitErrorCheck(p)) 736 return; 737 p->setTimeout(t); 738 ::sc_gem5::newDynamicSensitivityEvent(p, &e); 739 sc_gem5::scheduler.yield(); 740} 741 742void 743wait(double d, sc_time_unit u, const sc_event &e) 744{ 745 wait(sc_time(d, u), e); 746} 747 748void 749wait(const sc_time &t, const sc_event_or_list &eol) 750{ 751 sc_gem5::Process *p = sc_gem5::scheduler.current(); 752 if (waitErrorCheck(p)) 753 return; 754 p->setTimeout(t); 755 ::sc_gem5::newDynamicSensitivityEventOrList(p, &eol); 756 sc_gem5::scheduler.yield(); 757} 758 759void 760wait(double d, sc_time_unit u, const sc_event_or_list &eol) 761{ 762 wait(sc_time(d, u), eol); 763} 764 765void 766wait(const sc_time &t, const sc_event_and_list &eal) 767{ 768 sc_gem5::Process *p = sc_gem5::scheduler.current(); 769 if (waitErrorCheck(p)) 770 return; 771 p->setTimeout(t); 772 ::sc_gem5::newDynamicSensitivityEventAndList(p, &eal); 773 sc_gem5::scheduler.yield(); 774} 775 776void 777wait(double d, sc_time_unit u, const sc_event_and_list &eal) 778{ 779 wait(sc_time(d, u), eal); 780} 781 782void 783halt() 784{ 785 ::sc_core::wait(); 786 throw ::sc_gem5::ScHalt(); 787} 788 789void 790at_posedge(const sc_signal_in_if<bool> &s) 791{ 792 while (s.read()) 793 wait(); 794 while (!s.read()) 795 wait(); 796} 797 798void 799at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &s) 800{ 801 while (s.read() == sc_dt::Log_1) 802 wait(); 803 while (s.read() == sc_dt::Log_0) 804 wait(); 805} 806 807void 808at_negedge(const sc_signal_in_if<bool> &s) 809{ 810 while (!s.read()) 811 wait(); 812 while (s.read()) 813 wait(); 814} 815 816void 817at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &s) 818{ 819 while (s.read() == sc_dt::Log_0) 820 wait(); 821 while (s.read() == sc_dt::Log_1) 822 wait(); 823} 824 825const char * 826sc_gen_unique_name(const char *seed) 827{ 828 if (!seed || seed[0] == '\0') { 829 SC_REPORT_ERROR( 830 "(E532) cannot generate unique name from null string", ""); 831 seed = "unnamed"; 832 } 833 834 auto mod = sc_gem5::pickParentModule(); 835 if (mod) 836 return mod->uniqueName(seed); 837 838 sc_gem5::Process *p = sc_gem5::scheduler.current(); 839 if (p) 840 return p->uniqueName(seed); 841 842 return ::sc_gem5::globalNameGen.gen(seed); 843} 844 845bool 846sc_hierarchical_name_exists(const char *name) 847{ 848 return sc_gem5::findEvent(name) != sc_gem5::allEvents.end() || 849 ::sc_gem5::findObject(name, sc_gem5::allObjects); 850} 851 852bool 853sc_start_of_simulation_invoked() 854{ 855 return ::sc_gem5::kernel->startOfSimulationComplete(); 856} 857 858bool 859sc_end_of_simulation_invoked() 860{ 861 return ::sc_gem5::kernel->endOfSimulationComplete(); 862} 863 864sc_module * 865sc_module_sc_new(sc_module *mod) 866{ 867 static std::vector<std::unique_ptr<sc_module> > modules; 868 modules.emplace_back(mod); 869 return mod; 870} 871 872} // namespace sc_core 873