sc_module.cc revision 13060
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 <vector> 32 33#include "base/logging.hh" 34#include "systemc/core/kernel.hh" 35#include "systemc/core/module.hh" 36#include "systemc/core/process_types.hh" 37#include "systemc/ext/core/sc_module.hh" 38#include "systemc/ext/core/sc_module_name.hh" 39 40namespace sc_gem5 41{ 42 43Process * 44newMethodProcess(const char *name, ProcessFuncWrapper *func) 45{ 46 Process *p = new Method(name, func); 47 scheduler.reg(p); 48 return p; 49} 50 51Process * 52newThreadProcess(const char *name, ProcessFuncWrapper *func) 53{ 54 Process *p = new Thread(name, func); 55 scheduler.reg(p); 56 return p; 57} 58 59Process * 60newCThreadProcess(const char *name, ProcessFuncWrapper *func) 61{ 62 Process *p = new CThread(name, func); 63 scheduler.reg(p); 64 p->dontInitialize(); 65 return p; 66} 67 68UniqueNameGen nameGen; 69 70} // namespace sc_gem5 71 72namespace sc_core 73{ 74 75sc_bind_proxy::sc_bind_proxy(const sc_interface &_interface) : 76 _interface(&_interface), _port(nullptr) 77{} 78 79sc_bind_proxy::sc_bind_proxy(const sc_port_base &_port) : 80 _interface(nullptr), _port(&_port) 81{} 82 83const sc_bind_proxy SC_BIND_PROXY_NUL(*(const sc_port_base *)nullptr); 84 85sc_module::~sc_module() { delete _gem5_module; } 86 87const sc_bind_proxy SC_BIND_PROXY_NIL(*(const sc_port_base *)nullptr); 88 89void 90sc_module::operator () (const sc_bind_proxy &p001, 91 const sc_bind_proxy &p002, 92 const sc_bind_proxy &p003, 93 const sc_bind_proxy &p004, 94 const sc_bind_proxy &p005, 95 const sc_bind_proxy &p006, 96 const sc_bind_proxy &p007, 97 const sc_bind_proxy &p008, 98 const sc_bind_proxy &p009, 99 const sc_bind_proxy &p010, 100 const sc_bind_proxy &p011, 101 const sc_bind_proxy &p012, 102 const sc_bind_proxy &p013, 103 const sc_bind_proxy &p014, 104 const sc_bind_proxy &p015, 105 const sc_bind_proxy &p016, 106 const sc_bind_proxy &p017, 107 const sc_bind_proxy &p018, 108 const sc_bind_proxy &p019, 109 const sc_bind_proxy &p020, 110 const sc_bind_proxy &p021, 111 const sc_bind_proxy &p022, 112 const sc_bind_proxy &p023, 113 const sc_bind_proxy &p024, 114 const sc_bind_proxy &p025, 115 const sc_bind_proxy &p026, 116 const sc_bind_proxy &p027, 117 const sc_bind_proxy &p028, 118 const sc_bind_proxy &p029, 119 const sc_bind_proxy &p030, 120 const sc_bind_proxy &p031, 121 const sc_bind_proxy &p032, 122 const sc_bind_proxy &p033, 123 const sc_bind_proxy &p034, 124 const sc_bind_proxy &p035, 125 const sc_bind_proxy &p036, 126 const sc_bind_proxy &p037, 127 const sc_bind_proxy &p038, 128 const sc_bind_proxy &p039, 129 const sc_bind_proxy &p040, 130 const sc_bind_proxy &p041, 131 const sc_bind_proxy &p042, 132 const sc_bind_proxy &p043, 133 const sc_bind_proxy &p044, 134 const sc_bind_proxy &p045, 135 const sc_bind_proxy &p046, 136 const sc_bind_proxy &p047, 137 const sc_bind_proxy &p048, 138 const sc_bind_proxy &p049, 139 const sc_bind_proxy &p050, 140 const sc_bind_proxy &p051, 141 const sc_bind_proxy &p052, 142 const sc_bind_proxy &p053, 143 const sc_bind_proxy &p054, 144 const sc_bind_proxy &p055, 145 const sc_bind_proxy &p056, 146 const sc_bind_proxy &p057, 147 const sc_bind_proxy &p058, 148 const sc_bind_proxy &p059, 149 const sc_bind_proxy &p060, 150 const sc_bind_proxy &p061, 151 const sc_bind_proxy &p062, 152 const sc_bind_proxy &p063, 153 const sc_bind_proxy &p064) 154{ 155 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 156} 157 158const std::vector<sc_object *> & 159sc_module::get_child_objects() const 160{ 161 return _gem5_module->obj()->get_child_objects(); 162} 163 164const std::vector<sc_event *> & 165sc_module::get_child_events() const 166{ 167 return _gem5_module->obj()->get_child_events(); 168} 169 170sc_module::sc_module() : 171 sc_object(sc_gem5::newModule()->name()), 172 _gem5_module(sc_gem5::currentModule()) 173{} 174 175sc_module::sc_module(const sc_module_name &) : sc_module() {} 176sc_module::sc_module(const char *_name) : sc_module(sc_module_name(_name)) {} 177sc_module::sc_module(const std::string &_name) : 178 sc_module(sc_module_name(_name.c_str())) 179{} 180 181void 182sc_module::reset_signal_is(const sc_in<bool> &, bool) 183{ 184 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 185} 186 187void 188sc_module::reset_signal_is(const sc_inout<bool> &, bool) 189{ 190 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 191} 192 193void 194sc_module::reset_signal_is(const sc_out<bool> &, bool) 195{ 196 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 197} 198 199void 200sc_module::reset_signal_is(const sc_signal_in_if<bool> &, bool) 201{ 202 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 203} 204 205 206void 207sc_module::async_reset_signal_is(const sc_in<bool> &, bool) 208{ 209 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 210} 211 212void 213sc_module::async_reset_signal_is(const sc_inout<bool> &, bool) 214{ 215 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 216} 217 218void 219sc_module::async_reset_signal_is(const sc_out<bool> &, bool) 220{ 221 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 222} 223 224void 225sc_module::async_reset_signal_is(const sc_signal_in_if<bool> &, bool) 226{ 227 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 228} 229 230 231void 232sc_module::dont_initialize() 233{ 234 ::sc_gem5::Process::newest()->dontInitialize(); 235} 236 237void 238sc_module::set_stack_size(size_t size) 239{ 240 ::sc_gem5::Process::newest()->setStackSize(size); 241} 242 243 244void sc_module::next_trigger() { ::sc_core::next_trigger(); } 245 246void 247sc_module::next_trigger(const sc_event &e) 248{ 249 ::sc_core::next_trigger(e); 250} 251 252void 253sc_module::next_trigger(const sc_event_or_list &eol) 254{ 255 ::sc_core::next_trigger(eol); 256} 257 258void 259sc_module::next_trigger(const sc_event_and_list &eal) 260{ 261 ::sc_core::next_trigger(eal); 262} 263 264void 265sc_module::next_trigger(const sc_time &t) 266{ 267 ::sc_core::next_trigger(t); 268} 269 270void 271sc_module::next_trigger(double d, sc_time_unit u) 272{ 273 ::sc_core::next_trigger(d, u); 274} 275 276void 277sc_module::next_trigger(const sc_time &t, const sc_event &e) 278{ 279 ::sc_core::next_trigger(t, e); 280} 281 282void 283sc_module::next_trigger(double d, sc_time_unit u, const sc_event &e) 284{ 285 ::sc_core::next_trigger(d, u, e); 286} 287 288void 289sc_module::next_trigger(const sc_time &t, const sc_event_or_list &eol) 290{ 291 ::sc_core::next_trigger(t, eol); 292} 293 294void 295sc_module::next_trigger(double d, sc_time_unit u, const sc_event_or_list &eol) 296{ 297 ::sc_core::next_trigger(d, u, eol); 298} 299 300void 301sc_module::next_trigger(const sc_time &t, const sc_event_and_list &eal) 302{ 303 ::sc_core::next_trigger(t, eal); 304} 305 306void 307sc_module::next_trigger(double d, sc_time_unit u, const sc_event_and_list &eal) 308{ 309 ::sc_core::next_trigger(d, u, eal); 310} 311 312 313bool 314sc_module::timed_out() 315{ 316 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 317 return false; 318} 319 320 321void 322sc_module::wait() 323{ 324 ::sc_core::wait(); 325} 326 327void 328sc_module::wait(int i) 329{ 330 ::sc_core::wait(i); 331} 332 333void 334sc_module::wait(const sc_event &e) 335{ 336 ::sc_core::wait(e); 337} 338 339void 340sc_module::wait(const sc_event_or_list &eol) 341{ 342 ::sc_core::wait(eol); 343} 344 345void 346sc_module::wait(const sc_event_and_list &eal) 347{ 348 ::sc_core::wait(eal); 349} 350 351void 352sc_module::wait(const sc_time &t) 353{ 354 ::sc_core::wait(t); 355} 356 357void 358sc_module::wait(double d, sc_time_unit u) 359{ 360 ::sc_core::wait(d, u); 361} 362 363void 364sc_module::wait(const sc_time &t, const sc_event &e) 365{ 366 ::sc_core::wait(t, e); 367} 368 369void 370sc_module::wait(double d, sc_time_unit u, const sc_event &e) 371{ 372 ::sc_core::wait(d, u, e); 373} 374 375void 376sc_module::wait(const sc_time &t, const sc_event_or_list &eol) 377{ 378 ::sc_core::wait(t, eol); 379} 380 381void 382sc_module::wait(double d, sc_time_unit u, const sc_event_or_list &eol) 383{ 384 ::sc_core::wait(d, u, eol); 385} 386 387void 388sc_module::wait(const sc_time &t, const sc_event_and_list &eal) 389{ 390 ::sc_core::wait(t, eal); 391} 392 393void 394sc_module::wait(double d, sc_time_unit u, const sc_event_and_list &eal) 395{ 396 ::sc_core::wait(d, u, eal); 397} 398 399 400void 401sc_module::halt() 402{ 403 ::sc_core::halt(); 404} 405 406void 407sc_module::at_posedge(const sc_signal_in_if<bool> &s) 408{ 409 ::sc_core::at_posedge(s); 410} 411 412void 413sc_module::at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &s) 414{ 415 ::sc_core::at_posedge(s); 416} 417 418void 419sc_module::at_negedge(const sc_signal_in_if<bool> &s) 420{ 421 ::sc_core::at_negedge(s); 422} 423 424void 425sc_module::at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &s) 426{ 427 ::sc_core::at_negedge(s); 428} 429 430 431void 432next_trigger() 433{ 434 sc_gem5::Process *p = sc_gem5::scheduler.current(); 435 p->setDynamic(nullptr); 436} 437 438void 439next_trigger(const sc_event &e) 440{ 441 sc_gem5::Process *p = sc_gem5::scheduler.current(); 442 p->setDynamic(new ::sc_gem5::SensitivityEvent(p, &e)); 443} 444 445void 446next_trigger(const sc_event_or_list &eol) 447{ 448 sc_gem5::Process *p = sc_gem5::scheduler.current(); 449 p->setDynamic(new ::sc_gem5::SensitivityEventOrList(p, &eol)); 450} 451 452void 453next_trigger(const sc_event_and_list &eal) 454{ 455 sc_gem5::Process *p = sc_gem5::scheduler.current(); 456 p->setDynamic(new ::sc_gem5::SensitivityEventAndList(p, &eal)); 457} 458 459void 460next_trigger(const sc_time &t) 461{ 462 sc_gem5::Process *p = sc_gem5::scheduler.current(); 463 p->setDynamic(new ::sc_gem5::SensitivityTimeout(p, t)); 464} 465 466void 467next_trigger(double d, sc_time_unit u) 468{ 469 next_trigger(sc_time(d, u)); 470} 471 472void 473next_trigger(const sc_time &t, const sc_event &e) 474{ 475 sc_gem5::Process *p = sc_gem5::scheduler.current(); 476 p->setDynamic(new ::sc_gem5::SensitivityTimeoutAndEvent(p, t, &e)); 477} 478 479void 480next_trigger(double d, sc_time_unit u, const sc_event &e) 481{ 482 next_trigger(sc_time(d, u), e); 483} 484 485void 486next_trigger(const sc_time &t, const sc_event_or_list &eol) 487{ 488 sc_gem5::Process *p = sc_gem5::scheduler.current(); 489 p->setDynamic( 490 new ::sc_gem5::SensitivityTimeoutAndEventOrList(p, t, &eol)); 491} 492 493void 494next_trigger(double d, sc_time_unit u, const sc_event_or_list &eol) 495{ 496 next_trigger(sc_time(d, u), eol); 497} 498 499void 500next_trigger(const sc_time &t, const sc_event_and_list &eal) 501{ 502 sc_gem5::Process *p = sc_gem5::scheduler.current(); 503 p->setDynamic( 504 new ::sc_gem5::SensitivityTimeoutAndEventAndList(p, t, &eal)); 505} 506 507void 508next_trigger(double d, sc_time_unit u, const sc_event_and_list &eal) 509{ 510 next_trigger(sc_time(d, u), eal); 511} 512 513bool 514timed_out() 515{ 516 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 517 return false; 518} 519 520 521void 522wait() 523{ 524 sc_gem5::Process *p = sc_gem5::scheduler.current(); 525 p->setDynamic(nullptr); 526 sc_gem5::scheduler.yield(); 527} 528 529void 530wait(int n) 531{ 532 for (int i = 0; i < n; i++) 533 wait(); 534} 535 536void 537wait(const sc_event &e) 538{ 539 sc_gem5::Process *p = sc_gem5::scheduler.current(); 540 p->setDynamic(new ::sc_gem5::SensitivityEvent(p, &e)); 541 sc_gem5::scheduler.yield(); 542} 543 544void 545wait(const sc_event_or_list &eol) 546{ 547 sc_gem5::Process *p = sc_gem5::scheduler.current(); 548 p->setDynamic(new ::sc_gem5::SensitivityEventOrList(p, &eol)); 549 sc_gem5::scheduler.yield(); 550} 551 552void 553wait(const sc_event_and_list &eal) 554{ 555 sc_gem5::Process *p = sc_gem5::scheduler.current(); 556 p->setDynamic(new ::sc_gem5::SensitivityEventAndList(p, &eal)); 557 sc_gem5::scheduler.yield(); 558} 559 560void 561wait(const sc_time &t) 562{ 563 sc_gem5::Process *p = sc_gem5::scheduler.current(); 564 p->setDynamic(new ::sc_gem5::SensitivityTimeout(p, t)); 565 sc_gem5::scheduler.yield(); 566} 567 568void 569wait(double d, sc_time_unit u) 570{ 571 wait(sc_time(d, u)); 572} 573 574void 575wait(const sc_time &t, const sc_event &e) 576{ 577 sc_gem5::Process *p = sc_gem5::scheduler.current(); 578 p->setDynamic(new ::sc_gem5::SensitivityTimeoutAndEvent(p, t, &e)); 579 sc_gem5::scheduler.yield(); 580} 581 582void 583wait(double d, sc_time_unit u, const sc_event &e) 584{ 585 wait(sc_time(d, u), e); 586} 587 588void 589wait(const sc_time &t, const sc_event_or_list &eol) 590{ 591 sc_gem5::Process *p = sc_gem5::scheduler.current(); 592 p->setDynamic( 593 new ::sc_gem5::SensitivityTimeoutAndEventOrList(p, t, &eol)); 594 sc_gem5::scheduler.yield(); 595} 596 597void 598wait(double d, sc_time_unit u, const sc_event_or_list &eol) 599{ 600 wait(sc_time(d, u), eol); 601} 602 603void 604wait(const sc_time &t, const sc_event_and_list &eal) 605{ 606 sc_gem5::Process *p = sc_gem5::scheduler.current(); 607 p->setDynamic( 608 new ::sc_gem5::SensitivityTimeoutAndEventAndList(p, t, &eal)); 609 sc_gem5::scheduler.yield(); 610} 611 612void 613wait(double d, sc_time_unit u, const sc_event_and_list &eal) 614{ 615 wait(sc_time(d, u), eal); 616} 617 618void 619halt() 620{ 621 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 622} 623 624void 625at_posedge(const sc_signal_in_if<bool> &) 626{ 627 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 628} 629 630void 631at_posedge(const sc_signal_in_if<sc_dt::sc_logic> &) 632{ 633 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 634} 635 636void 637at_negedge(const sc_signal_in_if<bool> &) 638{ 639 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 640} 641 642void 643at_negedge(const sc_signal_in_if<sc_dt::sc_logic> &) 644{ 645 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 646} 647 648const char * 649sc_gen_unique_name(const char *seed) 650{ 651 ::sc_gem5::Module *mod = ::sc_gem5::currentModule(); 652 return mod ? mod->uniqueName(seed) : 653 ::sc_gem5::nameGen.gen(seed); 654} 655 656bool 657sc_hierarchical_name_exists(const char *name) 658{ 659 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 660 return false; 661} 662 663bool 664sc_start_of_simulation_invoked() 665{ 666 return ::sc_gem5::kernel->startOfSimulationComplete(); 667} 668 669bool 670sc_end_of_simulation_invoked() 671{ 672 return ::sc_gem5::kernel->endOfSimulationComplete(); 673} 674 675sc_module * 676sc_module_sc_new(sc_module *mod) 677{ 678 static std::vector<std::unique_ptr<sc_module> > modules; 679 modules.emplace_back(mod); 680 return mod; 681} 682 683} // namespace sc_core 684