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/messages.hh" 47#include "systemc/ext/core/sc_module.hh" 48#include "systemc/ext/core/sc_module_name.hh" 49#include "systemc/ext/dt/bit/sc_logic.hh" 50#include "systemc/ext/utils/sc_report_handler.hh" 51 52namespace sc_gem5 53{ 54 55Process * 56newMethodProcess(const char *name, ProcessFuncWrapper *func) 57{ 58 Method *p = new Method(name, func); 59 if (::sc_core::sc_is_running()) { 60 std::string name = p->name(); 61 delete p; 62 SC_REPORT_ERROR(sc_core::SC_ID_MODULE_METHOD_AFTER_START_, 63 name.c_str()); 64 return nullptr; 65 } 66 scheduler.reg(p); 67 return p; 68} 69 70Process * 71newThreadProcess(const char *name, ProcessFuncWrapper *func) 72{ 73 Thread *p = new Thread(name, func); 74 if (::sc_core::sc_is_running()) { 75 std::string name = p->name(); 76 delete p; 77 SC_REPORT_ERROR(sc_core::SC_ID_MODULE_THREAD_AFTER_START_, 78 name.c_str()); 79 return nullptr; 80 } 81 scheduler.reg(p); 82 return p; 83} 84 85Process * 86newCThreadProcess(const char *name, ProcessFuncWrapper *func) 87{ 88 CThread *p = new CThread(name, func); 89 if (::sc_core::sc_is_running()) { 90 std::string name = p->name(); 91 delete p; 92 SC_REPORT_ERROR(sc_core::SC_ID_MODULE_CTHREAD_AFTER_START_, 93 name.c_str()); 94 return nullptr; 95 } 96 scheduler.reg(p); 97 p->dontInitialize(true); 98 return p; 99} 100 101} // namespace sc_gem5 102 103namespace sc_core 104{ 105 106sc_bind_proxy::sc_bind_proxy() : _interface(nullptr), _port(nullptr) {} 107 108sc_bind_proxy::sc_bind_proxy(sc_interface &_interface) : 109 _interface(&_interface), _port(nullptr) 110{} 111 112sc_bind_proxy::sc_bind_proxy(sc_port_base &_port) : 113 _interface(nullptr), _port(&_port) 114{} 115 116const sc_bind_proxy SC_BIND_PROXY_NIL; 117 118::Port & 119sc_module::gem5_getPort(const std::string &if_name, int idx) 120{ 121 fatal("%s does not have any port named %s\n", name(), if_name); 122} 123 124sc_module::~sc_module() { delete _gem5_module; } 125 126void 127sc_module::operator () (const sc_bind_proxy &p001, 128 const sc_bind_proxy &p002, 129 const sc_bind_proxy &p003, 130 const sc_bind_proxy &p004, 131 const sc_bind_proxy &p005, 132 const sc_bind_proxy &p006, 133 const sc_bind_proxy &p007, 134 const sc_bind_proxy &p008, 135 const sc_bind_proxy &p009, 136 const sc_bind_proxy &p010, 137 const sc_bind_proxy &p011, 138 const sc_bind_proxy &p012, 139 const sc_bind_proxy &p013, 140 const sc_bind_proxy &p014, 141 const sc_bind_proxy &p015, 142 const sc_bind_proxy &p016, 143 const sc_bind_proxy &p017, 144 const sc_bind_proxy &p018, 145 const sc_bind_proxy &p019, 146 const sc_bind_proxy &p020, 147 const sc_bind_proxy &p021, 148 const sc_bind_proxy &p022, 149 const sc_bind_proxy &p023, 150 const sc_bind_proxy &p024, 151 const sc_bind_proxy &p025, 152 const sc_bind_proxy &p026, 153 const sc_bind_proxy &p027, 154 const sc_bind_proxy &p028, 155 const sc_bind_proxy &p029, 156 const sc_bind_proxy &p030, 157 const sc_bind_proxy &p031, 158 const sc_bind_proxy &p032, 159 const sc_bind_proxy &p033, 160 const sc_bind_proxy &p034, 161 const sc_bind_proxy &p035, 162 const sc_bind_proxy &p036, 163 const sc_bind_proxy &p037, 164 const sc_bind_proxy &p038, 165 const sc_bind_proxy &p039, 166 const sc_bind_proxy &p040, 167 const sc_bind_proxy &p041, 168 const sc_bind_proxy &p042, 169 const sc_bind_proxy &p043, 170 const sc_bind_proxy &p044, 171 const sc_bind_proxy &p045, 172 const sc_bind_proxy &p046, 173 const sc_bind_proxy &p047, 174 const sc_bind_proxy &p048, 175 const sc_bind_proxy &p049, 176 const sc_bind_proxy &p050, 177 const sc_bind_proxy &p051, 178 const sc_bind_proxy &p052, 179 const sc_bind_proxy &p053, 180 const sc_bind_proxy &p054, 181 const sc_bind_proxy &p055, 182 const sc_bind_proxy &p056, 183 const sc_bind_proxy &p057, 184 const sc_bind_proxy &p058, 185 const sc_bind_proxy &p059, 186 const sc_bind_proxy &p060, 187 const sc_bind_proxy &p061, 188 const sc_bind_proxy &p062, 189 const sc_bind_proxy &p063, 190 const sc_bind_proxy &p064) 191{ 192 std::vector<const ::sc_core::sc_bind_proxy *> proxies; 193 auto insert = [&proxies](const ::sc_core::sc_bind_proxy &p) -> bool { 194 if (!p.port() && !p.interface()) 195 return false; 196 proxies.push_back(&p); 197 return true; 198 }; 199 insert(p001) && insert(p002) && insert(p003) && insert(p004) && 200 insert(p005) && insert(p006) && insert(p007) && insert(p008) && 201 insert(p009) && insert(p010) && insert(p011) && insert(p012) && 202 insert(p013) && insert(p014) && insert(p015) && insert(p016) && 203 insert(p017) && insert(p018) && insert(p019) && insert(p020) && 204 insert(p021) && insert(p022) && insert(p023) && insert(p024) && 205 insert(p025) && insert(p026) && insert(p027) && insert(p028) && 206 insert(p029) && insert(p030) && insert(p031) && insert(p032) && 207 insert(p033) && insert(p034) && insert(p035) && insert(p036) && 208 insert(p037) && insert(p038) && insert(p039) && insert(p040) && 209 insert(p041) && insert(p042) && insert(p043) && insert(p044) && 210 insert(p045) && insert(p046) && insert(p047) && insert(p048) && 211 insert(p049) && insert(p050) && insert(p051) && insert(p052) && 212 insert(p053) && insert(p054) && insert(p055) && insert(p056) && 213 insert(p057) && insert(p058) && insert(p059) && insert(p060) && 214 insert(p061) && insert(p062) && insert(p063) && insert(p064); 215 _gem5_module->bindPorts(proxies); 216} 217 218sc_module & 219sc_module::operator << (sc_interface &iface) 220{ 221 (*this)(iface); 222 return *this; 223} 224 225sc_module & 226sc_module::operator << (sc_port_base &pb) 227{ 228 (*this)(pb); 229 return *this; 230} 231 232sc_module & 233sc_module::operator , (sc_interface &iface) 234{ 235 (*this)(iface); 236 return *this; 237} 238 239sc_module & 240sc_module::operator , (sc_port_base &pb) 241{ 242 (*this)(pb); 243 return *this; 244} 245 246const std::vector<sc_object *> & 247sc_module::get_child_objects() const 248{ 249 return _gem5_module->obj()->get_child_objects(); 250} 251 252const std::vector<sc_event *> & 253sc_module::get_child_events() const 254{ 255 return _gem5_module->obj()->get_child_events(); 256} 257 258sc_module::sc_module() : 259 sc_object(sc_gem5::newModuleChecked()->name()), 260 _gem5_module(sc_gem5::currentModule()) 261{ 262 if (sc_is_running()) 263 SC_REPORT_ERROR(SC_ID_INSERT_MODULE_, "simulation running"); 264 if (::sc_gem5::scheduler.elaborationDone()) 265 SC_REPORT_ERROR(SC_ID_INSERT_MODULE_, "elaboration done"); 266} 267 268sc_module::sc_module(const sc_module_name &) : sc_module() {} 269sc_module::sc_module(const char *_name) : sc_module(sc_module_name(_name)) 270{ 271 _gem5_module->deprecatedConstructor(); 272 SC_REPORT_WARNING(SC_ID_BAD_SC_MODULE_CONSTRUCTOR_, _name); 273} 274sc_module::sc_module(const std::string &_name) : 275 sc_module(sc_module_name(_name.c_str())) 276{ 277 _gem5_module->deprecatedConstructor(); 278 SC_REPORT_WARNING(SC_ID_BAD_SC_MODULE_CONSTRUCTOR_, _name.c_str()); 279} 280 281void 282sc_module::end_module() 283{ 284 _gem5_module->endModule(); 285} 286 287void 288sc_module::reset_signal_is(const sc_in<bool> &port, bool val) 289{ 290 ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), true, val); 291} 292 293void 294sc_module::reset_signal_is(const sc_inout<bool> &port, bool val) 295{ 296 ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), true, val); 297} 298 299void 300sc_module::reset_signal_is(const sc_out<bool> &port, bool val) 301{ 302 ::sc_gem5::newReset(&port, ::sc_gem5::Process::newest(), true, val); 303} 304 305void 306sc_module::reset_signal_is(const sc_signal_in_if<bool> &signal, bool val) 307{ 308 ::sc_gem5::newReset(&signal, ::sc_gem5::Process::newest(), true, val); 309} 310 311 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