2 * Copyright 2018 Google, Inc.
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.
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.
30 #ifndef __SYSTEMC_EXT_CORE_SC_PORT_HH__
31 #define __SYSTEMC_EXT_CORE_SC_PORT_HH__
35 #include "../utils/sc_report_handler.hh"
36 #include "sc_module.hh" // for sc_gen_unique_name
37 #include "sc_object.hh"
43 class PendingSensitivityPort;
54 SC_ONE_OR_MORE_BOUND, // Default
55 SC_ZERO_OR_MORE_BOUND,
59 class sc_port_base : public sc_object
62 sc_port_base(const char *name, int n, sc_port_policy p);
64 void warn_unimpl(const char *func) const;
70 // Implementation defined, but depended on by the tests.
71 void bind(sc_interface &);
72 void bind(sc_port_base &);
74 // Implementation defined, but depended on by the tests.
75 virtual int vbind(sc_interface &) = 0;
76 virtual int vbind(sc_port_base &) = 0;
78 virtual void before_end_of_elaboration() = 0;
79 virtual void end_of_elaboration() = 0;
80 virtual void start_of_simulation() = 0;
81 virtual void end_of_simulation() = 0;
84 friend class ::sc_gem5::PendingSensitivityPort;
85 friend class ::sc_gem5::Kernel;
89 virtual sc_interface *_gem5Interface(int n) const = 0;
90 virtual void _gem5AddInterface(sc_interface *i) = 0;
92 std::vector<::sc_gem5::BindInfo *> _gem5BindInfo;
99 class sc_port_b : public sc_port_base
102 void operator () (IF &i) { bind(i); }
103 void operator () (sc_port_b<IF> &p) { bind(p); }
105 virtual void bind(IF &i) { sc_port_base::bind(i); }
106 virtual void bind(sc_port_b<IF> &p) { sc_port_base::bind(p); }
108 IF *operator -> () { return _interfaces.at(0); }
109 const IF *operator -> () const { return _interfaces.at(0); }
111 IF *operator [] (int n) { return _interfaces.at(n); }
112 const IF *operator [] (int n) const { return _interfaces.at(n); }
114 sc_interface *get_interface() { return _interfaces.at(0); }
115 const sc_interface *get_interface() const { return _interfaces.at(0); }
118 void before_end_of_elaboration() {}
119 void end_of_elaboration() {}
120 void start_of_simulation() {}
121 void end_of_simulation() {}
123 explicit sc_port_b(int n, sc_port_policy p) :
124 sc_port_base(sc_gen_unique_name("port"), n, p)
126 sc_port_b(const char *name, int n, sc_port_policy p) :
127 sc_port_base(name, n, p)
129 virtual ~sc_port_b() {}
131 // Implementation defined, but depended on by the tests.
133 vbind(sc_interface &i)
135 IF *interface = dynamic_cast<IF *>(&i);
138 sc_port_base::bind(*interface);
142 vbind(sc_port_base &pb)
144 sc_port_b<IF> *p = dynamic_cast<sc_port_b<IF> *>(&pb);
147 sc_port_base::bind(*p);
152 std::vector<IF *> _interfaces;
154 sc_interface *_gem5Interface(int n) const { return _interfaces.at(n); }
156 _gem5AddInterface(sc_interface *i)
158 IF *interface = dynamic_cast<IF *>(i);
159 sc_assert(interface);
160 _interfaces.push_back(interface);
165 sc_port_b(const sc_port_b<IF> &) {}
166 sc_port_b<IF> &operator = (const sc_port_b<IF> &) { return *this; }
169 template <class IF, int N=1, sc_port_policy P=SC_ONE_OR_MORE_BOUND>
170 class sc_port : public sc_port_b<IF>
173 sc_port() : sc_port_b<IF>(N, P) {}
174 explicit sc_port(const char *name) : sc_port_b<IF>(name, N, P) {}
175 virtual ~sc_port() {}
177 // Deprecated binding constructors.
178 explicit sc_port(const IF &interface) : sc_port_b<IF>(N, P)
180 this->warn_unimpl(__PRETTY_FUNCTION__);
181 // Should warn that these are deprecated. See Accellera sc_port.h.
182 sc_port_b<IF>::bind(const_cast<IF &>(interface));
184 sc_port(const char *name, const IF &interface) : sc_port_b<IF>(name, N, P)
186 this->warn_unimpl(__PRETTY_FUNCTION__);
187 // Should warn that these are deprecated. See Accellera sc_port.h.
188 sc_port_b<IF>::bind(const_cast<IF &>(interface));
190 explicit sc_port(sc_port_b<IF> &parent) : sc_port_b<IF>(N, P)
192 this->warn_unimpl(__PRETTY_FUNCTION__);
193 // Should warn that these are deprecated. See Accellera sc_port.h.
194 sc_port_b<IF>::bind(parent);
196 sc_port(const char *name, sc_port_b<IF> &parent) :
197 sc_port_b<IF>(name, N, P)
199 this->warn_unimpl(__PRETTY_FUNCTION__);
200 // Should warn that these are deprecated. See Accellera sc_port.h.
201 sc_port_b<IF>::bind(parent);
203 explicit sc_port(sc_port<IF, N, P> &parent) : sc_port_b<IF>(N, P)
205 this->warn_unimpl(__PRETTY_FUNCTION__);
206 // Should warn that these are deprecated. See Accellera sc_port.h.
207 sc_port_b<IF>::bind(parent);
209 sc_port(const char *name, sc_port<IF, N, P> &parent) :
210 sc_port_b<IF>(name, N, P)
212 this->warn_unimpl(__PRETTY_FUNCTION__);
213 // Should warn that these are deprecated. See Accellera sc_port.h.
214 sc_port_b<IF>::bind(parent);
217 virtual const char *kind() const { return "sc_port"; }
221 sc_port(const sc_port<IF, N, P> &) {}
222 sc_port<IF, N, P> &operator = (const sc_port<IF, N, P> &) { return *this; }
225 } // namespace sc_core
227 #endif //__SYSTEMC_EXT_CORE_SC_PORT_HH__