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