sc_port.hh revision 13091
112837Sgabeblack@google.com/* 212837Sgabeblack@google.com * Copyright 2018 Google, Inc. 312837Sgabeblack@google.com * 412837Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 512837Sgabeblack@google.com * modification, are permitted provided that the following conditions are 612837Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 712837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 812837Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 912837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1012837Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1112837Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1212837Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1312837Sgabeblack@google.com * this software without specific prior written permission. 1412837Sgabeblack@google.com * 1512837Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1612837Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1712837Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1812837Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1912837Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2012837Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2112837Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2212837Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2312837Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2412837Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2512837Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2612837Sgabeblack@google.com * 2712837Sgabeblack@google.com * Authors: Gabe Black 2812837Sgabeblack@google.com */ 2912837Sgabeblack@google.com 3012837Sgabeblack@google.com#ifndef __SYSTEMC_EXT_CORE_SC_PORT_HH__ 3112837Sgabeblack@google.com#define __SYSTEMC_EXT_CORE_SC_PORT_HH__ 3212837Sgabeblack@google.com 3312957Sgabeblack@google.com#include <vector> 3412957Sgabeblack@google.com 3513053Sgabeblack@google.com#include "../utils/sc_report_handler.hh" 3612842Sgabeblack@google.com#include "sc_module.hh" // for sc_gen_unique_name 3712837Sgabeblack@google.com#include "sc_object.hh" 3812837Sgabeblack@google.com 3912957Sgabeblack@google.comnamespace sc_gem5 4012957Sgabeblack@google.com{ 4112957Sgabeblack@google.com 4212957Sgabeblack@google.comclass BindInfo; 4313091Sgabeblack@google.comclass Module; 4412957Sgabeblack@google.comclass PendingSensitivityPort; 4512957Sgabeblack@google.com 4612957Sgabeblack@google.com}; 4712957Sgabeblack@google.com 4812837Sgabeblack@google.comnamespace sc_core 4912837Sgabeblack@google.com{ 5012837Sgabeblack@google.com 5112837Sgabeblack@google.comclass sc_interface; 5212837Sgabeblack@google.com 5312837Sgabeblack@google.comenum sc_port_policy 5412837Sgabeblack@google.com{ 5512837Sgabeblack@google.com SC_ONE_OR_MORE_BOUND, // Default 5612837Sgabeblack@google.com SC_ZERO_OR_MORE_BOUND, 5712837Sgabeblack@google.com SC_ALL_BOUND 5812837Sgabeblack@google.com}; 5912837Sgabeblack@google.com 6012837Sgabeblack@google.comclass sc_port_base : public sc_object 6112837Sgabeblack@google.com{ 6212837Sgabeblack@google.com public: 6312957Sgabeblack@google.com sc_port_base(const char *name, int n, sc_port_policy p); 6412842Sgabeblack@google.com 6512842Sgabeblack@google.com void warn_unimpl(const char *func) const; 6612938Sgabeblack@google.com 6712957Sgabeblack@google.com int maxSize() const; 6812957Sgabeblack@google.com int size() const; 6912957Sgabeblack@google.com 7012938Sgabeblack@google.com protected: 7112938Sgabeblack@google.com // Implementation defined, but depended on by the tests. 7212938Sgabeblack@google.com void bind(sc_interface &); 7312938Sgabeblack@google.com void bind(sc_port_base &); 7412944Sgabeblack@google.com 7513091Sgabeblack@google.com friend class ::sc_gem5::Module; 7613091Sgabeblack@google.com 7712944Sgabeblack@google.com // Implementation defined, but depended on by the tests. 7812944Sgabeblack@google.com virtual int vbind(sc_interface &) = 0; 7912944Sgabeblack@google.com virtual int vbind(sc_port_base &) = 0; 8012957Sgabeblack@google.com 8113059Sgabeblack@google.com virtual void before_end_of_elaboration() = 0; 8213059Sgabeblack@google.com virtual void end_of_elaboration() = 0; 8313059Sgabeblack@google.com virtual void start_of_simulation() = 0; 8413059Sgabeblack@google.com virtual void end_of_simulation() = 0; 8513059Sgabeblack@google.com 8612957Sgabeblack@google.com private: 8712957Sgabeblack@google.com friend class ::sc_gem5::PendingSensitivityPort; 8813053Sgabeblack@google.com friend class ::sc_gem5::Kernel; 8913053Sgabeblack@google.com 9013053Sgabeblack@google.com void _gem5Finalize(); 9113053Sgabeblack@google.com 9213053Sgabeblack@google.com virtual sc_interface *_gem5Interface(int n) const = 0; 9313053Sgabeblack@google.com virtual void _gem5AddInterface(sc_interface *i) = 0; 9412957Sgabeblack@google.com 9512957Sgabeblack@google.com std::vector<::sc_gem5::BindInfo *> _gem5BindInfo; 9612957Sgabeblack@google.com int _maxSize; 9713053Sgabeblack@google.com int _size; 9813053Sgabeblack@google.com bool finalized; 9912837Sgabeblack@google.com}; 10012837Sgabeblack@google.com 10112837Sgabeblack@google.comtemplate <class IF> 10212837Sgabeblack@google.comclass sc_port_b : public sc_port_base 10312837Sgabeblack@google.com{ 10412837Sgabeblack@google.com public: 10513053Sgabeblack@google.com void operator () (IF &i) { bind(i); } 10613053Sgabeblack@google.com void operator () (sc_port_b<IF> &p) { bind(p); } 10712837Sgabeblack@google.com 10813053Sgabeblack@google.com virtual void bind(IF &i) { sc_port_base::bind(i); } 10913053Sgabeblack@google.com virtual void bind(sc_port_b<IF> &p) { sc_port_base::bind(p); } 11012837Sgabeblack@google.com 11113090Sgabeblack@google.com IF * 11213090Sgabeblack@google.com operator -> () 11313090Sgabeblack@google.com { 11413090Sgabeblack@google.com sc_assert(!_interfaces.empty()); 11513090Sgabeblack@google.com return _interfaces[0]; 11613090Sgabeblack@google.com } 11713090Sgabeblack@google.com const IF * 11813090Sgabeblack@google.com operator -> () const 11913090Sgabeblack@google.com { 12013090Sgabeblack@google.com sc_assert(!_interfaces.empty()); 12113090Sgabeblack@google.com return _interfaces[0]; 12213090Sgabeblack@google.com } 12312837Sgabeblack@google.com 12413090Sgabeblack@google.com IF * 12513090Sgabeblack@google.com operator [] (int n) 12613090Sgabeblack@google.com { 12713090Sgabeblack@google.com sc_assert(_interfaces.size() > n); 12813090Sgabeblack@google.com return _interfaces[n]; 12913090Sgabeblack@google.com } 13013090Sgabeblack@google.com const IF * 13113090Sgabeblack@google.com operator [] (int n) const 13213090Sgabeblack@google.com { 13313090Sgabeblack@google.com sc_assert(_interfaces.size() > n); 13413090Sgabeblack@google.com return _interfaces[n]; 13513090Sgabeblack@google.com } 13612837Sgabeblack@google.com 13713090Sgabeblack@google.com sc_interface * 13813090Sgabeblack@google.com get_interface() 13913090Sgabeblack@google.com { 14013090Sgabeblack@google.com sc_assert(!_interfaces.empty()); 14113090Sgabeblack@google.com return _interfaces[0]; 14213090Sgabeblack@google.com } 14313090Sgabeblack@google.com const sc_interface * 14413090Sgabeblack@google.com get_interface() const 14513090Sgabeblack@google.com { 14613090Sgabeblack@google.com sc_assert(!_interfaces.empty()); 14713090Sgabeblack@google.com return _interfaces[0]; 14813090Sgabeblack@google.com } 14912837Sgabeblack@google.com 15012837Sgabeblack@google.com protected: 15113059Sgabeblack@google.com void before_end_of_elaboration() {} 15213059Sgabeblack@google.com void end_of_elaboration() {} 15313059Sgabeblack@google.com void start_of_simulation() {} 15413059Sgabeblack@google.com void end_of_simulation() {} 15512837Sgabeblack@google.com 15612842Sgabeblack@google.com explicit sc_port_b(int n, sc_port_policy p) : 15713036Sgabeblack@google.com sc_port_base(sc_gen_unique_name("port"), n, p) 15812842Sgabeblack@google.com {} 15912842Sgabeblack@google.com sc_port_b(const char *name, int n, sc_port_policy p) : 16012842Sgabeblack@google.com sc_port_base(name, n, p) 16112842Sgabeblack@google.com {} 16212842Sgabeblack@google.com virtual ~sc_port_b() {} 16312837Sgabeblack@google.com 16412944Sgabeblack@google.com // Implementation defined, but depended on by the tests. 16512944Sgabeblack@google.com int 16613053Sgabeblack@google.com vbind(sc_interface &i) 16712944Sgabeblack@google.com { 16813053Sgabeblack@google.com IF *interface = dynamic_cast<IF *>(&i); 16913053Sgabeblack@google.com if (!interface) 17013053Sgabeblack@google.com return 2; 17113053Sgabeblack@google.com sc_port_base::bind(*interface); 17212944Sgabeblack@google.com return 0; 17312944Sgabeblack@google.com } 17412944Sgabeblack@google.com int 17513053Sgabeblack@google.com vbind(sc_port_base &pb) 17612944Sgabeblack@google.com { 17713053Sgabeblack@google.com sc_port_b<IF> *p = dynamic_cast<sc_port_b<IF> *>(&pb); 17813053Sgabeblack@google.com if (!p) 17913053Sgabeblack@google.com return 2; 18013053Sgabeblack@google.com sc_port_base::bind(*p); 18112944Sgabeblack@google.com return 0; 18212944Sgabeblack@google.com } 18312944Sgabeblack@google.com 18412837Sgabeblack@google.com private: 18513053Sgabeblack@google.com std::vector<IF *> _interfaces; 18613053Sgabeblack@google.com 18713090Sgabeblack@google.com sc_interface * 18813090Sgabeblack@google.com _gem5Interface(int n) const 18913090Sgabeblack@google.com { 19013090Sgabeblack@google.com sc_assert(_interfaces.size() > n); 19113090Sgabeblack@google.com return _interfaces[n]; 19213090Sgabeblack@google.com } 19313053Sgabeblack@google.com void 19413053Sgabeblack@google.com _gem5AddInterface(sc_interface *i) 19513053Sgabeblack@google.com { 19613053Sgabeblack@google.com IF *interface = dynamic_cast<IF *>(i); 19713053Sgabeblack@google.com sc_assert(interface); 19813053Sgabeblack@google.com _interfaces.push_back(interface); 19913053Sgabeblack@google.com } 20013053Sgabeblack@google.com 20112837Sgabeblack@google.com // Disabled 20212837Sgabeblack@google.com sc_port_b() {} 20312837Sgabeblack@google.com sc_port_b(const sc_port_b<IF> &) {} 20412837Sgabeblack@google.com sc_port_b<IF> &operator = (const sc_port_b<IF> &) { return *this; } 20512837Sgabeblack@google.com}; 20612837Sgabeblack@google.com 20712837Sgabeblack@google.comtemplate <class IF, int N=1, sc_port_policy P=SC_ONE_OR_MORE_BOUND> 20812837Sgabeblack@google.comclass sc_port : public sc_port_b<IF> 20912837Sgabeblack@google.com{ 21012837Sgabeblack@google.com public: 21112868Sgabeblack@google.com sc_port() : sc_port_b<IF>(N, P) {} 21212842Sgabeblack@google.com explicit sc_port(const char *name) : sc_port_b<IF>(name, N, P) {} 21312842Sgabeblack@google.com virtual ~sc_port() {} 21412837Sgabeblack@google.com 21512868Sgabeblack@google.com // Deprecated binding constructors. 21612868Sgabeblack@google.com explicit sc_port(const IF &interface) : sc_port_b<IF>(N, P) 21712868Sgabeblack@google.com { 21812868Sgabeblack@google.com this->warn_unimpl(__PRETTY_FUNCTION__); 21912868Sgabeblack@google.com // Should warn that these are deprecated. See Accellera sc_port.h. 22012868Sgabeblack@google.com sc_port_b<IF>::bind(const_cast<IF &>(interface)); 22112868Sgabeblack@google.com } 22212868Sgabeblack@google.com sc_port(const char *name, const IF &interface) : sc_port_b<IF>(name, N, P) 22312868Sgabeblack@google.com { 22412868Sgabeblack@google.com this->warn_unimpl(__PRETTY_FUNCTION__); 22512868Sgabeblack@google.com // Should warn that these are deprecated. See Accellera sc_port.h. 22612868Sgabeblack@google.com sc_port_b<IF>::bind(const_cast<IF &>(interface)); 22712868Sgabeblack@google.com } 22812868Sgabeblack@google.com explicit sc_port(sc_port_b<IF> &parent) : sc_port_b<IF>(N, P) 22912868Sgabeblack@google.com { 23012868Sgabeblack@google.com this->warn_unimpl(__PRETTY_FUNCTION__); 23112868Sgabeblack@google.com // Should warn that these are deprecated. See Accellera sc_port.h. 23212868Sgabeblack@google.com sc_port_b<IF>::bind(parent); 23312868Sgabeblack@google.com } 23412868Sgabeblack@google.com sc_port(const char *name, sc_port_b<IF> &parent) : 23512868Sgabeblack@google.com sc_port_b<IF>(name, N, P) 23612868Sgabeblack@google.com { 23712868Sgabeblack@google.com this->warn_unimpl(__PRETTY_FUNCTION__); 23812868Sgabeblack@google.com // Should warn that these are deprecated. See Accellera sc_port.h. 23912868Sgabeblack@google.com sc_port_b<IF>::bind(parent); 24012868Sgabeblack@google.com } 24112868Sgabeblack@google.com explicit sc_port(sc_port<IF, N, P> &parent) : sc_port_b<IF>(N, P) 24212868Sgabeblack@google.com { 24312868Sgabeblack@google.com this->warn_unimpl(__PRETTY_FUNCTION__); 24412868Sgabeblack@google.com // Should warn that these are deprecated. See Accellera sc_port.h. 24512868Sgabeblack@google.com sc_port_b<IF>::bind(parent); 24612868Sgabeblack@google.com } 24712868Sgabeblack@google.com sc_port(const char *name, sc_port<IF, N, P> &parent) : 24812868Sgabeblack@google.com sc_port_b<IF>(name, N, P) 24912868Sgabeblack@google.com { 25012868Sgabeblack@google.com this->warn_unimpl(__PRETTY_FUNCTION__); 25112868Sgabeblack@google.com // Should warn that these are deprecated. See Accellera sc_port.h. 25212868Sgabeblack@google.com sc_port_b<IF>::bind(parent); 25312868Sgabeblack@google.com } 25412868Sgabeblack@google.com 25512842Sgabeblack@google.com virtual const char *kind() const { return "sc_port"; } 25612837Sgabeblack@google.com 25712837Sgabeblack@google.com private: 25812837Sgabeblack@google.com // Disabled 25912837Sgabeblack@google.com sc_port(const sc_port<IF, N, P> &) {} 26012837Sgabeblack@google.com sc_port<IF, N, P> &operator = (const sc_port<IF, N, P> &) { return *this; } 26112837Sgabeblack@google.com}; 26212837Sgabeblack@google.com 26312837Sgabeblack@google.com} // namespace sc_core 26412837Sgabeblack@google.com 26512837Sgabeblack@google.com#endif //__SYSTEMC_EXT_CORE_SC_PORT_HH__ 266