sc_export.hh revision 13246:b2648bba3d91
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright 2018 Google, Inc. 36145Snate@binkert.org * 46145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 56145Snate@binkert.org * modification, are permitted provided that the following conditions are 66145Snate@binkert.org * met: redistributions of source code must retain the above copyright 76145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 86145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 96145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 106145Snate@binkert.org * documentation and/or other materials provided with the distribution; 116145Snate@binkert.org * neither the name of the copyright holders nor the names of its 126145Snate@binkert.org * contributors may be used to endorse or promote products derived from 136145Snate@binkert.org * this software without specific prior written permission. 146145Snate@binkert.org * 156145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 166145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 176145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 186145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 196145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 206145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 216145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 226145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 236145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 246145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 256145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 266145Snate@binkert.org * 276145Snate@binkert.org * Authors: Gabe Black 286145Snate@binkert.org */ 297454Snate@binkert.org 307454Snate@binkert.org#ifndef __SYSTEMC_EXT_CORE_SC_EXPORT_HH__ 318645Snilay@cs.wisc.edu#define __SYSTEMC_EXT_CORE_SC_EXPORT_HH__ 327454Snate@binkert.org 3310301Snilay@cs.wisc.edu#include "../utils/sc_report_handler.hh" 347054Snate@binkert.org#include "sc_module.hh" // for sc_gen_unique_name 358259SBrad.Beckmann@amd.com#include "sc_object.hh" 366154Snate@binkert.org 376154Snate@binkert.orgnamespace sc_core 386145Snate@binkert.org{ 397055Snate@binkert.org 407454Snate@binkert.orgclass sc_interface; 417454Snate@binkert.org 427055Snate@binkert.orgclass sc_export_base : public sc_object 439274Snilay@cs.wisc.edu{ 446145Snate@binkert.org public: 459858Snilay@cs.wisc.edu sc_export_base(const char *n); 4611021Sjthestness@gmail.com ~sc_export_base(); 4711021Sjthestness@gmail.com 486145Snate@binkert.org virtual sc_interface *get_iterface() = 0; 496145Snate@binkert.org virtual const sc_interface *get_interface() const = 0; 506145Snate@binkert.org 516145Snate@binkert.org protected: 529858Snilay@cs.wisc.edu friend class sc_gem5::Module; 536145Snate@binkert.org 547054Snate@binkert.org virtual void before_end_of_elaboration() = 0; 557454Snate@binkert.org virtual void end_of_elaboration() = 0; 566145Snate@binkert.org virtual void start_of_simulation() = 0; 577054Snate@binkert.org virtual void end_of_simulation() = 0; 5811021Sjthestness@gmail.com}; 596145Snate@binkert.org 606145Snate@binkert.orgtemplate <class IF> 617054Snate@binkert.orgclass sc_export : public sc_export_base 629274Snilay@cs.wisc.edu{ 639274Snilay@cs.wisc.edu public: 649274Snilay@cs.wisc.edu sc_export() : 659858Snilay@cs.wisc.edu sc_export_base(sc_gen_unique_name("export")), interface(nullptr) 669274Snilay@cs.wisc.edu {} 679274Snilay@cs.wisc.edu explicit sc_export(const char *n) : 689274Snilay@cs.wisc.edu sc_export_base(n), interface(nullptr) 6910370Snilay@cs.wisc.edu {} 706145Snate@binkert.org virtual ~sc_export() {} 719858Snilay@cs.wisc.edu 726145Snate@binkert.org virtual const char *kind() const { return "sc_export"; } 736145Snate@binkert.org 747054Snate@binkert.org void operator () (IF &i) { bind(i); } 7510370Snilay@cs.wisc.edu virtual void 7610311Snilay@cs.wisc.edu bind(IF &i) 7710311Snilay@cs.wisc.edu { 786145Snate@binkert.org if (interface) { 797054Snate@binkert.org SC_REPORT_ERROR("(E126) sc_export instance already bound", name()); 8010918Sbrandon.potter@amd.com return; 8110918Sbrandon.potter@amd.com } 8210311Snilay@cs.wisc.edu interface = &i; 8310311Snilay@cs.wisc.edu } 8410311Snilay@cs.wisc.edu operator IF & () 8510311Snilay@cs.wisc.edu { 867454Snate@binkert.org if (!interface) { 876145Snate@binkert.org SC_REPORT_ERROR("(E120) sc_export instance has no interface", 887054Snate@binkert.org name()); 8910370Snilay@cs.wisc.edu } 9010311Snilay@cs.wisc.edu return *interface; 9110370Snilay@cs.wisc.edu } 9211021Sjthestness@gmail.com operator const IF & () const { return *interface; } 9311021Sjthestness@gmail.com 9411021Sjthestness@gmail.com IF * 9510370Snilay@cs.wisc.edu operator -> () 969274Snilay@cs.wisc.edu { 976145Snate@binkert.org if (!interface) { 987054Snate@binkert.org SC_REPORT_ERROR("(E120) sc_export instance has no interface", 999858Snilay@cs.wisc.edu name()); 1006145Snate@binkert.org } 1017054Snate@binkert.org return interface; 1029508Snilay@cs.wisc.edu } 1036145Snate@binkert.org const IF * 1046145Snate@binkert.org operator -> () const 1057054Snate@binkert.org { 1067054Snate@binkert.org if (!interface) { 1076145Snate@binkert.org SC_REPORT_ERROR("(E120) sc_export instance has no interface", 1087054Snate@binkert.org name()); 1097054Snate@binkert.org } 1106145Snate@binkert.org return interface; 1116145Snate@binkert.org } 1127054Snate@binkert.org 1139863Snilay@cs.wisc.edu sc_interface *get_iterface() override { return interface; } 1146145Snate@binkert.org const sc_interface *get_interface() const override { return interface; } 11511523Sdavid.guillen@arm.com 11611523Sdavid.guillen@arm.com protected: 1179863Snilay@cs.wisc.edu void before_end_of_elaboration() {} 1189863Snilay@cs.wisc.edu void 1199863Snilay@cs.wisc.edu end_of_elaboration() 1206145Snate@binkert.org { 1219863Snilay@cs.wisc.edu if (!interface) { 1229863Snilay@cs.wisc.edu std::string msg = "export not bound: export '"; 1239863Snilay@cs.wisc.edu msg = msg + name() + "' (" + kind() + ")"; 1249863Snilay@cs.wisc.edu SC_REPORT_ERROR("(E109) complete binding failed", msg.c_str()); 1259863Snilay@cs.wisc.edu } 1266145Snate@binkert.org } 1279863Snilay@cs.wisc.edu void start_of_simulation() {} 1289863Snilay@cs.wisc.edu void end_of_simulation() {} 1299863Snilay@cs.wisc.edu 1309863Snilay@cs.wisc.edu private: 1319863Snilay@cs.wisc.edu IF *interface; 1329863Snilay@cs.wisc.edu 1339863Snilay@cs.wisc.edu // Disabled 1349863Snilay@cs.wisc.edu sc_export(const sc_export<IF> &); 1359863Snilay@cs.wisc.edu sc_export<IF> &operator = (const sc_export<IF> &); 1369863Snilay@cs.wisc.edu}; 1379863Snilay@cs.wisc.edu 1389863Snilay@cs.wisc.edu} // namespace sc_core 1399863Snilay@cs.wisc.edu 1409863Snilay@cs.wisc.edu#endif //__SYSTEMC_EXT_CORE_SC_EXPORT_HH__ 1419863Snilay@cs.wisc.edu