sc_port.hh revision 13053
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; 4312957Sgabeblack@google.comclass PendingSensitivityPort; 4412957Sgabeblack@google.com 4512957Sgabeblack@google.com}; 4612957Sgabeblack@google.com 4712837Sgabeblack@google.comnamespace sc_core 4812837Sgabeblack@google.com{ 4912837Sgabeblack@google.com 5012837Sgabeblack@google.comclass sc_interface; 5112837Sgabeblack@google.com 5212837Sgabeblack@google.comenum sc_port_policy 5312837Sgabeblack@google.com{ 5412837Sgabeblack@google.com SC_ONE_OR_MORE_BOUND, // Default 5512837Sgabeblack@google.com SC_ZERO_OR_MORE_BOUND, 5612837Sgabeblack@google.com SC_ALL_BOUND 5712837Sgabeblack@google.com}; 5812837Sgabeblack@google.com 5912837Sgabeblack@google.comclass sc_port_base : public sc_object 6012837Sgabeblack@google.com{ 6112837Sgabeblack@google.com public: 6212957Sgabeblack@google.com sc_port_base(const char *name, int n, sc_port_policy p); 6312842Sgabeblack@google.com 6412842Sgabeblack@google.com void warn_unimpl(const char *func) const; 6512938Sgabeblack@google.com 6612957Sgabeblack@google.com int maxSize() const; 6712957Sgabeblack@google.com int size() const; 6812957Sgabeblack@google.com 6912938Sgabeblack@google.com protected: 7012938Sgabeblack@google.com // Implementation defined, but depended on by the tests. 7112938Sgabeblack@google.com void bind(sc_interface &); 7212938Sgabeblack@google.com void bind(sc_port_base &); 7312944Sgabeblack@google.com 7412944Sgabeblack@google.com // Implementation defined, but depended on by the tests. 7512944Sgabeblack@google.com virtual int vbind(sc_interface &) = 0; 7612944Sgabeblack@google.com virtual int vbind(sc_port_base &) = 0; 7712957Sgabeblack@google.com 7812957Sgabeblack@google.com private: 7912957Sgabeblack@google.com friend class ::sc_gem5::PendingSensitivityPort; 8013053Sgabeblack@google.com friend class ::sc_gem5::Kernel; 8113053Sgabeblack@google.com 8213053Sgabeblack@google.com void _gem5Finalize(); 8313053Sgabeblack@google.com 8413053Sgabeblack@google.com virtual sc_interface *_gem5Interface(int n) const = 0; 8513053Sgabeblack@google.com virtual void _gem5AddInterface(sc_interface *i) = 0; 8612957Sgabeblack@google.com 8712957Sgabeblack@google.com std::vector<::sc_gem5::BindInfo *> _gem5BindInfo; 8812957Sgabeblack@google.com int _maxSize; 8913053Sgabeblack@google.com int _size; 9013053Sgabeblack@google.com bool finalized; 9112837Sgabeblack@google.com}; 9212837Sgabeblack@google.com 9312837Sgabeblack@google.comtemplate <class IF> 9412837Sgabeblack@google.comclass sc_port_b : public sc_port_base 9512837Sgabeblack@google.com{ 9612837Sgabeblack@google.com public: 9713053Sgabeblack@google.com void operator () (IF &i) { bind(i); } 9813053Sgabeblack@google.com void operator () (sc_port_b<IF> &p) { bind(p); } 9912837Sgabeblack@google.com 10013053Sgabeblack@google.com virtual void bind(IF &i) { sc_port_base::bind(i); } 10113053Sgabeblack@google.com virtual void bind(sc_port_b<IF> &p) { sc_port_base::bind(p); } 10212837Sgabeblack@google.com 10313053Sgabeblack@google.com IF *operator -> () { return _interfaces.at(0); } 10413053Sgabeblack@google.com const IF *operator -> () const { return _interfaces.at(0); } 10512837Sgabeblack@google.com 10613053Sgabeblack@google.com IF *operator [] (int n) { return _interfaces.at(n); } 10713053Sgabeblack@google.com const IF *operator [] (int n) const { return _interfaces.at(n); } 10812837Sgabeblack@google.com 10913053Sgabeblack@google.com sc_interface *get_interface() { return _interfaces.at(0); } 11013053Sgabeblack@google.com const sc_interface *get_interface() const { return _interfaces.at(0); } 11112837Sgabeblack@google.com 11212837Sgabeblack@google.com protected: 11312837Sgabeblack@google.com virtual void before_end_of_elaboration() {} 11412837Sgabeblack@google.com virtual void end_of_elaboration() {} 11512837Sgabeblack@google.com virtual void start_of_elaboration() {} 11612837Sgabeblack@google.com virtual void end_of_simulation() {} 11712837Sgabeblack@google.com 11812842Sgabeblack@google.com explicit sc_port_b(int n, sc_port_policy p) : 11913036Sgabeblack@google.com sc_port_base(sc_gen_unique_name("port"), n, p) 12012842Sgabeblack@google.com {} 12112842Sgabeblack@google.com sc_port_b(const char *name, int n, sc_port_policy p) : 12212842Sgabeblack@google.com sc_port_base(name, n, p) 12312842Sgabeblack@google.com {} 12412842Sgabeblack@google.com virtual ~sc_port_b() {} 12512837Sgabeblack@google.com 12612944Sgabeblack@google.com // Implementation defined, but depended on by the tests. 12712944Sgabeblack@google.com int 12813053Sgabeblack@google.com vbind(sc_interface &i) 12912944Sgabeblack@google.com { 13013053Sgabeblack@google.com IF *interface = dynamic_cast<IF *>(&i); 13113053Sgabeblack@google.com if (!interface) 13213053Sgabeblack@google.com return 2; 13313053Sgabeblack@google.com sc_port_base::bind(*interface); 13412944Sgabeblack@google.com return 0; 13512944Sgabeblack@google.com } 13612944Sgabeblack@google.com int 13713053Sgabeblack@google.com vbind(sc_port_base &pb) 13812944Sgabeblack@google.com { 13913053Sgabeblack@google.com sc_port_b<IF> *p = dynamic_cast<sc_port_b<IF> *>(&pb); 14013053Sgabeblack@google.com if (!p) 14113053Sgabeblack@google.com return 2; 14213053Sgabeblack@google.com sc_port_base::bind(*p); 14312944Sgabeblack@google.com return 0; 14412944Sgabeblack@google.com } 14512944Sgabeblack@google.com 14612837Sgabeblack@google.com private: 14713053Sgabeblack@google.com std::vector<IF *> _interfaces; 14813053Sgabeblack@google.com 14913053Sgabeblack@google.com sc_interface *_gem5Interface(int n) const { return _interfaces.at(n); } 15013053Sgabeblack@google.com void 15113053Sgabeblack@google.com _gem5AddInterface(sc_interface *i) 15213053Sgabeblack@google.com { 15313053Sgabeblack@google.com IF *interface = dynamic_cast<IF *>(i); 15413053Sgabeblack@google.com sc_assert(interface); 15513053Sgabeblack@google.com _interfaces.push_back(interface); 15613053Sgabeblack@google.com } 15713053Sgabeblack@google.com 15812837Sgabeblack@google.com // Disabled 15912837Sgabeblack@google.com sc_port_b() {} 16012837Sgabeblack@google.com sc_port_b(const sc_port_b<IF> &) {} 16112837Sgabeblack@google.com sc_port_b<IF> &operator = (const sc_port_b<IF> &) { return *this; } 16212837Sgabeblack@google.com}; 16312837Sgabeblack@google.com 16412837Sgabeblack@google.comtemplate <class IF, int N=1, sc_port_policy P=SC_ONE_OR_MORE_BOUND> 16512837Sgabeblack@google.comclass sc_port : public sc_port_b<IF> 16612837Sgabeblack@google.com{ 16712837Sgabeblack@google.com public: 16812868Sgabeblack@google.com sc_port() : sc_port_b<IF>(N, P) {} 16912842Sgabeblack@google.com explicit sc_port(const char *name) : sc_port_b<IF>(name, N, P) {} 17012842Sgabeblack@google.com virtual ~sc_port() {} 17112837Sgabeblack@google.com 17212868Sgabeblack@google.com // Deprecated binding constructors. 17312868Sgabeblack@google.com explicit sc_port(const IF &interface) : sc_port_b<IF>(N, P) 17412868Sgabeblack@google.com { 17512868Sgabeblack@google.com this->warn_unimpl(__PRETTY_FUNCTION__); 17612868Sgabeblack@google.com // Should warn that these are deprecated. See Accellera sc_port.h. 17712868Sgabeblack@google.com sc_port_b<IF>::bind(const_cast<IF &>(interface)); 17812868Sgabeblack@google.com } 17912868Sgabeblack@google.com sc_port(const char *name, const IF &interface) : sc_port_b<IF>(name, N, P) 18012868Sgabeblack@google.com { 18112868Sgabeblack@google.com this->warn_unimpl(__PRETTY_FUNCTION__); 18212868Sgabeblack@google.com // Should warn that these are deprecated. See Accellera sc_port.h. 18312868Sgabeblack@google.com sc_port_b<IF>::bind(const_cast<IF &>(interface)); 18412868Sgabeblack@google.com } 18512868Sgabeblack@google.com explicit sc_port(sc_port_b<IF> &parent) : sc_port_b<IF>(N, P) 18612868Sgabeblack@google.com { 18712868Sgabeblack@google.com this->warn_unimpl(__PRETTY_FUNCTION__); 18812868Sgabeblack@google.com // Should warn that these are deprecated. See Accellera sc_port.h. 18912868Sgabeblack@google.com sc_port_b<IF>::bind(parent); 19012868Sgabeblack@google.com } 19112868Sgabeblack@google.com sc_port(const char *name, sc_port_b<IF> &parent) : 19212868Sgabeblack@google.com sc_port_b<IF>(name, N, P) 19312868Sgabeblack@google.com { 19412868Sgabeblack@google.com this->warn_unimpl(__PRETTY_FUNCTION__); 19512868Sgabeblack@google.com // Should warn that these are deprecated. See Accellera sc_port.h. 19612868Sgabeblack@google.com sc_port_b<IF>::bind(parent); 19712868Sgabeblack@google.com } 19812868Sgabeblack@google.com explicit sc_port(sc_port<IF, N, P> &parent) : sc_port_b<IF>(N, P) 19912868Sgabeblack@google.com { 20012868Sgabeblack@google.com this->warn_unimpl(__PRETTY_FUNCTION__); 20112868Sgabeblack@google.com // Should warn that these are deprecated. See Accellera sc_port.h. 20212868Sgabeblack@google.com sc_port_b<IF>::bind(parent); 20312868Sgabeblack@google.com } 20412868Sgabeblack@google.com sc_port(const char *name, sc_port<IF, N, P> &parent) : 20512868Sgabeblack@google.com sc_port_b<IF>(name, N, P) 20612868Sgabeblack@google.com { 20712868Sgabeblack@google.com this->warn_unimpl(__PRETTY_FUNCTION__); 20812868Sgabeblack@google.com // Should warn that these are deprecated. See Accellera sc_port.h. 20912868Sgabeblack@google.com sc_port_b<IF>::bind(parent); 21012868Sgabeblack@google.com } 21112868Sgabeblack@google.com 21212842Sgabeblack@google.com virtual const char *kind() const { return "sc_port"; } 21312837Sgabeblack@google.com 21412837Sgabeblack@google.com private: 21512837Sgabeblack@google.com // Disabled 21612837Sgabeblack@google.com sc_port(const sc_port<IF, N, P> &) {} 21712837Sgabeblack@google.com sc_port<IF, N, P> &operator = (const sc_port<IF, N, P> &) { return *this; } 21812837Sgabeblack@google.com}; 21912837Sgabeblack@google.com 22012837Sgabeblack@google.com} // namespace sc_core 22112837Sgabeblack@google.com 22212837Sgabeblack@google.com#endif //__SYSTEMC_EXT_CORE_SC_PORT_HH__ 223