sc_port.hh revision 13036:6f7e3c29c11a
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#ifndef __SYSTEMC_EXT_CORE_SC_PORT_HH__ 31#define __SYSTEMC_EXT_CORE_SC_PORT_HH__ 32 33#include <vector> 34 35#include "sc_module.hh" // for sc_gen_unique_name 36#include "sc_object.hh" 37 38namespace sc_gem5 39{ 40 41class BindInfo; 42class PendingSensitivityPort; 43 44}; 45 46namespace sc_core 47{ 48 49class sc_interface; 50 51enum sc_port_policy 52{ 53 SC_ONE_OR_MORE_BOUND, // Default 54 SC_ZERO_OR_MORE_BOUND, 55 SC_ALL_BOUND 56}; 57 58class sc_port_base : public sc_object 59{ 60 public: 61 sc_port_base(const char *name, int n, sc_port_policy p); 62 63 void warn_unimpl(const char *func) const; 64 65 int maxSize() const; 66 int size() const; 67 68 protected: 69 // Implementation defined, but depended on by the tests. 70 void bind(sc_interface &); 71 void bind(sc_port_base &); 72 73 // Implementation defined, but depended on by the tests. 74 virtual int vbind(sc_interface &) = 0; 75 virtual int vbind(sc_port_base &) = 0; 76 77 private: 78 friend class ::sc_gem5::PendingSensitivityPort; 79 80 std::vector<::sc_gem5::BindInfo *> _gem5BindInfo; 81 int _maxSize; 82}; 83 84template <class IF> 85class sc_port_b : public sc_port_base 86{ 87 public: 88 void 89 operator () (IF &) 90 { 91 this->warn_unimpl(__PRETTY_FUNCTION__); 92 } 93 94 void 95 operator () (sc_port_b<IF> &) 96 { 97 this->warn_unimpl(__PRETTY_FUNCTION__); 98 } 99 100 virtual void 101 bind(IF &) 102 { 103 this->warn_unimpl(__PRETTY_FUNCTION__); 104 } 105 106 virtual void 107 bind(sc_port_b<IF> &) 108 { 109 this->warn_unimpl(__PRETTY_FUNCTION__); 110 } 111 112 int 113 size() const 114 { 115 this->warn_unimpl(__PRETTY_FUNCTION__); 116 return 0; 117 } 118 119 IF * 120 operator -> () 121 { 122 this->warn_unimpl(__PRETTY_FUNCTION__); 123 return (IF *)nullptr; 124 } 125 126 const IF * 127 operator -> () const 128 { 129 this->warn_unimpl(__PRETTY_FUNCTION__); 130 return (IF *)nullptr; 131 } 132 133 IF * 134 operator [] (int) 135 { 136 this->warn_unimpl(__PRETTY_FUNCTION__); 137 return (IF *)nullptr; 138 } 139 140 const IF * 141 operator [] (int) const 142 { 143 this->warn_unimpl(__PRETTY_FUNCTION__); 144 return (IF *)nullptr; 145 } 146 147 virtual sc_interface * 148 get_interface() 149 { 150 this->warn_unimpl(__PRETTY_FUNCTION__); 151 return (sc_interface *)nullptr; 152 } 153 154 virtual const sc_interface * 155 get_interface() const 156 { 157 this->warn_unimpl(__PRETTY_FUNCTION__); 158 return (sc_interface *)nullptr; 159 } 160 161 protected: 162 virtual void before_end_of_elaboration() {} 163 virtual void end_of_elaboration() {} 164 virtual void start_of_elaboration() {} 165 virtual void end_of_simulation() {} 166 167 explicit sc_port_b(int n, sc_port_policy p) : 168 sc_port_base(sc_gen_unique_name("port"), n, p) 169 {} 170 sc_port_b(const char *name, int n, sc_port_policy p) : 171 sc_port_base(name, n, p) 172 {} 173 virtual ~sc_port_b() {} 174 175 // Implementation defined, but depended on by the tests. 176 int 177 vbind(sc_interface &) 178 { 179 this->warn_unimpl(__PRETTY_FUNCTION__); 180 return 0; 181 } 182 int 183 vbind(sc_port_base &) 184 { 185 this->warn_unimpl(__PRETTY_FUNCTION__); 186 return 0; 187 } 188 189 private: 190 // Disabled 191 sc_port_b() {} 192 sc_port_b(const sc_port_b<IF> &) {} 193 sc_port_b<IF> &operator = (const sc_port_b<IF> &) { return *this; } 194}; 195 196template <class IF, int N=1, sc_port_policy P=SC_ONE_OR_MORE_BOUND> 197class sc_port : public sc_port_b<IF> 198{ 199 public: 200 sc_port() : sc_port_b<IF>(N, P) {} 201 explicit sc_port(const char *name) : sc_port_b<IF>(name, N, P) {} 202 virtual ~sc_port() {} 203 204 // Deprecated binding constructors. 205 explicit sc_port(const IF &interface) : sc_port_b<IF>(N, P) 206 { 207 this->warn_unimpl(__PRETTY_FUNCTION__); 208 // Should warn that these are deprecated. See Accellera sc_port.h. 209 sc_port_b<IF>::bind(const_cast<IF &>(interface)); 210 } 211 sc_port(const char *name, const IF &interface) : sc_port_b<IF>(name, N, P) 212 { 213 this->warn_unimpl(__PRETTY_FUNCTION__); 214 // Should warn that these are deprecated. See Accellera sc_port.h. 215 sc_port_b<IF>::bind(const_cast<IF &>(interface)); 216 } 217 explicit sc_port(sc_port_b<IF> &parent) : sc_port_b<IF>(N, P) 218 { 219 this->warn_unimpl(__PRETTY_FUNCTION__); 220 // Should warn that these are deprecated. See Accellera sc_port.h. 221 sc_port_b<IF>::bind(parent); 222 } 223 sc_port(const char *name, sc_port_b<IF> &parent) : 224 sc_port_b<IF>(name, N, P) 225 { 226 this->warn_unimpl(__PRETTY_FUNCTION__); 227 // Should warn that these are deprecated. See Accellera sc_port.h. 228 sc_port_b<IF>::bind(parent); 229 } 230 explicit sc_port(sc_port<IF, N, P> &parent) : sc_port_b<IF>(N, P) 231 { 232 this->warn_unimpl(__PRETTY_FUNCTION__); 233 // Should warn that these are deprecated. See Accellera sc_port.h. 234 sc_port_b<IF>::bind(parent); 235 } 236 sc_port(const char *name, sc_port<IF, N, P> &parent) : 237 sc_port_b<IF>(name, N, P) 238 { 239 this->warn_unimpl(__PRETTY_FUNCTION__); 240 // Should warn that these are deprecated. See Accellera sc_port.h. 241 sc_port_b<IF>::bind(parent); 242 } 243 244 virtual const char *kind() const { return "sc_port"; } 245 246 private: 247 // Disabled 248 sc_port(const sc_port<IF, N, P> &) {} 249 sc_port<IF, N, P> &operator = (const sc_port<IF, N, P> &) { return *this; } 250}; 251 252} // namespace sc_core 253 254#endif //__SYSTEMC_EXT_CORE_SC_PORT_HH__ 255