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