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