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