sc_export.hh revision 13059:4be5f408e128
113372Sgabeblack@google.com/* 213372Sgabeblack@google.com * Copyright 2018 Google, Inc. 313372Sgabeblack@google.com * 413372Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 513372Sgabeblack@google.com * modification, are permitted provided that the following conditions are 613372Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 713372Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 813372Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 913372Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1013372Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1113372Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1213372Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1313372Sgabeblack@google.com * this software without specific prior written permission. 1413372Sgabeblack@google.com * 1513372Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1613372Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1713372Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1813372Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1913372Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2013372Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2113372Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2213372Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2313372Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2413372Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2513372Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2613372Sgabeblack@google.com * 2713372Sgabeblack@google.com * Authors: Gabe Black 2813372Sgabeblack@google.com */ 2913463Sgabeblack@google.com 3013463Sgabeblack@google.com#ifndef __SYSTEMC_EXT_CORE_SC_EXPORT_HH__ 3113463Sgabeblack@google.com#define __SYSTEMC_EXT_CORE_SC_EXPORT_HH__ 3213372Sgabeblack@google.com 3313372Sgabeblack@google.com#include "sc_module.hh" // for sc_gen_unique_name 3413372Sgabeblack@google.com#include "sc_object.hh" 3513463Sgabeblack@google.com 3613463Sgabeblack@google.comnamespace sc_core 3713372Sgabeblack@google.com{ 3813372Sgabeblack@google.com 3913372Sgabeblack@google.comclass sc_interface; 4013463Sgabeblack@google.com 4113463Sgabeblack@google.comclass sc_export_base : public sc_object 4213372Sgabeblack@google.com{ 4313372Sgabeblack@google.com public: 4413372Sgabeblack@google.com sc_export_base(const char *n); 4513372Sgabeblack@google.com ~sc_export_base(); 4613372Sgabeblack@google.com 4713372Sgabeblack@google.com virtual sc_interface *get_iterface() = 0; 4813372Sgabeblack@google.com virtual const sc_interface *get_interface() const = 0; 4913372Sgabeblack@google.com 5013372Sgabeblack@google.com protected: 5113372Sgabeblack@google.com friend class sc_gem5::Kernel; 5213372Sgabeblack@google.com 5313372Sgabeblack@google.com virtual void before_end_of_elaboration() = 0; 5413372Sgabeblack@google.com virtual void end_of_elaboration() = 0; 5513372Sgabeblack@google.com virtual void start_of_simulation() = 0; 5613372Sgabeblack@google.com virtual void end_of_simulation() = 0; 5713372Sgabeblack@google.com}; 5813372Sgabeblack@google.com 5913372Sgabeblack@google.comtemplate <class IF> 6013372Sgabeblack@google.comclass sc_export : public sc_export_base 6113372Sgabeblack@google.com{ 6213372Sgabeblack@google.com public: 6313372Sgabeblack@google.com sc_export() : 6413372Sgabeblack@google.com sc_export_base(sc_gen_unique_name("export")), interface(nullptr) 6513372Sgabeblack@google.com {} 6613372Sgabeblack@google.com explicit sc_export(const char *n) : 6713372Sgabeblack@google.com sc_export_base(n), interface(nullptr) 6813372Sgabeblack@google.com {} 6913372Sgabeblack@google.com virtual ~sc_export() {} 7013372Sgabeblack@google.com 7113372Sgabeblack@google.com virtual const char *kind() const { return "sc_export"; } 7213372Sgabeblack@google.com 7313372Sgabeblack@google.com void operator () (IF &i) { bind(i); } 7413372Sgabeblack@google.com virtual void bind(IF &i) { interface = &i; } 7513372Sgabeblack@google.com operator IF & () { return *interface; } 7613372Sgabeblack@google.com operator const IF & () const { return *interface; } 7713372Sgabeblack@google.com 7813372Sgabeblack@google.com IF *operator -> () { return interface; } 7913372Sgabeblack@google.com const IF *operator -> () const { return interface; } 8013372Sgabeblack@google.com 8113372Sgabeblack@google.com sc_interface *get_iterface() override { return interface; } 8213372Sgabeblack@google.com const sc_interface *get_interface() const override { return interface; } 8313372Sgabeblack@google.com 8413372Sgabeblack@google.com protected: 8513372Sgabeblack@google.com void before_end_of_elaboration() {} 8613372Sgabeblack@google.com void end_of_elaboration() {} 87 void start_of_simulation() {} 88 void end_of_simulation() {} 89 90 private: 91 IF *interface; 92 93 // Disabled 94 sc_export(const sc_export<IF> &); 95 sc_export<IF> &operator = (const sc_export<IF> &); 96}; 97 98} // namespace sc_core 99 100#endif //__SYSTEMC_EXT_CORE_SC_EXPORT_HH__ 101