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
62template <class IF>
63class sc_port_b : public sc_port_base
64{
65 public:
66 void
67 operator () (IF &)
68 {
69 this->warn_unimpl(__PRETTY_FUNCTION__);
70 }
71
72 void
73 operator () (sc_port_b<IF> &)
74 {
75 this->warn_unimpl(__PRETTY_FUNCTION__);
76 }
77
78 virtual void
79 bind(IF &)
80 {
81 this->warn_unimpl(__PRETTY_FUNCTION__);
82 }
83
84 virtual void
85 bind(sc_port_b<IF> &)
86 {
87 this->warn_unimpl(__PRETTY_FUNCTION__);
88 }
89
90 int
91 size() const
92 {
93 this->warn_unimpl(__PRETTY_FUNCTION__);
94 return 0;
95 }
96
97 IF *
98 operator -> ()
99 {
100 this->warn_unimpl(__PRETTY_FUNCTION__);
101 return (IF *)nullptr;
102 }
103
104 const IF *
105 operator -> () const
106 {
107 this->warn_unimpl(__PRETTY_FUNCTION__);
108 return (IF *)nullptr;
109 }
110
111 IF *
112 operator [] (int)
113 {
114 this->warn_unimpl(__PRETTY_FUNCTION__);
115 return (IF *)nullptr;
116 }
117
118 const IF *
119 operator [] (int) const
120 {
121 this->warn_unimpl(__PRETTY_FUNCTION__);
122 return (IF *)nullptr;
123 }
124
125 virtual sc_interface *
126 get_interface()
127 {
128 this->warn_unimpl(__PRETTY_FUNCTION__);
129 return (sc_interface *)nullptr;
130 }
131
132 virtual const sc_interface *
133 get_interface() const
134 {
135 this->warn_unimpl(__PRETTY_FUNCTION__);
136 return (sc_interface *)nullptr;
137 }
138
139 protected:
140 virtual void before_end_of_elaboration() {}
141 virtual void end_of_elaboration() {}
142 virtual void start_of_elaboration() {}
143 virtual void end_of_simulation() {}
144
145 explicit sc_port_b(int n, sc_port_policy p) :
146 sc_port_base(sc_gen_unique_name("sc_port"), n, p)
147 {}
148 sc_port_b(const char *name, int n, sc_port_policy p) :
149 sc_port_base(name, n, p)
150 {}
151 virtual ~sc_port_b() {}
152
153 private:
154 // Disabled
155 sc_port_b() {}
156 sc_port_b(const sc_port_b<IF> &) {}
157 sc_port_b<IF> &operator = (const sc_port_b<IF> &) { return *this; }
158};
159
160template <class IF, int N=1, sc_port_policy P=SC_ONE_OR_MORE_BOUND>
161class sc_port : public sc_port_b<IF>
162{
163 public:
164 sc_port() : sc_port_b<IF>(N, P) {}
165 explicit sc_port(const char *name) : sc_port_b<IF>(name, N, P) {}
166 virtual ~sc_port() {}
167
168 // Deprecated binding constructors.
169 explicit sc_port(const IF &interface) : sc_port_b<IF>(N, P)
170 {
171 this->warn_unimpl(__PRETTY_FUNCTION__);
172 // Should warn that these are deprecated. See Accellera sc_port.h.
173 sc_port_b<IF>::bind(const_cast<IF &>(interface));
174 }
175 sc_port(const char *name, const IF &interface) : sc_port_b<IF>(name, N, P)
176 {
177 this->warn_unimpl(__PRETTY_FUNCTION__);
178 // Should warn that these are deprecated. See Accellera sc_port.h.
179 sc_port_b<IF>::bind(const_cast<IF &>(interface));
180 }
181 explicit sc_port(sc_port_b<IF> &parent) : sc_port_b<IF>(N, P)
182 {
183 this->warn_unimpl(__PRETTY_FUNCTION__);
184 // Should warn that these are deprecated. See Accellera sc_port.h.
185 sc_port_b<IF>::bind(parent);
186 }
187 sc_port(const char *name, sc_port_b<IF> &parent) :
188 sc_port_b<IF>(name, N, P)
189 {
190 this->warn_unimpl(__PRETTY_FUNCTION__);
191 // Should warn that these are deprecated. See Accellera sc_port.h.
192 sc_port_b<IF>::bind(parent);
193 }
194 explicit sc_port(sc_port<IF, N, P> &parent) : sc_port_b<IF>(N, P)
195 {
196 this->warn_unimpl(__PRETTY_FUNCTION__);
197 // Should warn that these are deprecated. See Accellera sc_port.h.
198 sc_port_b<IF>::bind(parent);
199 }
200 sc_port(const char *name, sc_port<IF, N, P> &parent) :
201 sc_port_b<IF>(name, N, P)
202 {
203 this->warn_unimpl(__PRETTY_FUNCTION__);
204 // Should warn that these are deprecated. See Accellera sc_port.h.
205 sc_port_b<IF>::bind(parent);
206 }
207
208 virtual const char *kind() const { return "sc_port"; }
209
210 private:
211 // Disabled
212 sc_port(const sc_port<IF, N, P> &) {}
213 sc_port<IF, N, P> &operator = (const sc_port<IF, N, P> &) { return *this; }
214};
215
216} // namespace sc_core
217
218#endif //__SYSTEMC_EXT_CORE_SC_PORT_HH__