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