gem5 v24.0.0.0
Loading...
Searching...
No Matches
sc_port.hh
Go to the documentation of this file.
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
28#ifndef __SYSTEMC_EXT_CORE_SC_PORT_HH__
29#define __SYSTEMC_EXT_CORE_SC_PORT_HH__
30
31#include <typeinfo>
32#include <vector>
33
36#include "sc_module.hh" // for sc_gen_unique_name
37#include "sc_object.hh"
38
39namespace sc_gem5
40{
41
42class Port;
43
44};
45
46namespace sc_core
47{
48
49class sc_interface;
50class sc_trace_file;
51
52// Nonstandard
53// Despite having a warning "FOR INTERNAL USE ONLY!" in all caps above this
54// class definition in the Accellera implementation, it appears in their
55// examples and test programs, and so we need to have it here as well.
57{
59 std::string name;
60
61 sc_trace_params(sc_trace_file *tf, const std::string &name) :
62 tf(tf), name(name)
63 {}
64};
66
73
74class sc_port_base : public sc_object
75{
76 public:
77 sc_port_base(const char *name, int n, sc_port_policy p);
78 virtual ~sc_port_base();
79
80 void warn_port_constructor() const;
81
82 int maxSize() const;
83 int size() const;
84
85 const char *kind() const { return "sc_port_base"; }
86
87 protected:
88 // Implementation defined, but depended on by the tests.
89 void bind(sc_interface &);
90 void bind(sc_port_base &);
91
92 friend class ::sc_gem5::Module;
93
94 // Implementation defined, but depended on by the tests.
95 virtual int vbind(sc_interface &) = 0;
96 virtual int vbind(sc_port_base &) = 0;
97
98 virtual void before_end_of_elaboration() = 0;
99 virtual void end_of_elaboration() = 0;
100 virtual void start_of_simulation() = 0;
101 virtual void end_of_simulation() = 0;
102
103 void report_error(const char *id, const char *add_msg) const;
104
105 private:
106 friend class ::sc_gem5::Port;
107 friend class ::sc_gem5::Kernel;
108
109 virtual sc_interface *_gem5Interface(int n) const = 0;
110 virtual void _gem5AddInterface(sc_interface *i) = 0;
111
113 virtual const char *_ifTypeName() const = 0;
114 virtual sc_port_policy _portPolicy() const = 0;
115};
116
117// The overloaded virtual is intended in SystemC, so we'll disable the warning.
118// Please check section 9.3 of SystemC 2.3.1 release note for more details.
119#pragma GCC diagnostic push
120#pragma GCC diagnostic ignored "-Woverloaded-virtual"
121template <class IF>
123{
124 public:
125 void operator () (IF &i) { bind(i); }
127
128 virtual void bind(IF &i) { sc_port_base::bind(i); }
129 virtual void bind(sc_port_b<IF> &p) { sc_port_base::bind(p); }
130
131 IF *
133 {
134 if (_interfaces.empty()) {
135 report_error(SC_ID_GET_IF_, "port is not bound");
136 sc_abort();
137 }
138 return _interfaces[0];
139 }
140 const IF *
142 {
143 if (_interfaces.empty()) {
144 report_error(SC_ID_GET_IF_, "port is not bound");
145 sc_abort();
146 }
147 return _interfaces[0];
148 }
149
150 IF *
152 {
153 if (n < 0 || n >= size()) {
154 report_error(SC_ID_GET_IF_, "index out of range");
155 return NULL;
156 }
157 return _interfaces[n];
158 }
159 const IF *
160 operator [] (int n) const
161 {
162 if (n < 0 || n >= size()) {
163 report_error(SC_ID_GET_IF_, "index out of range");
164 return NULL;
165 }
166 return _interfaces[n];
167 }
168
171 {
172 if (_interfaces.empty())
173 return NULL;
174 return _interfaces[0];
175 }
176 const sc_interface *
178 {
179 if (_interfaces.empty())
180 return NULL;
181 return _interfaces[0];
182 }
183
184 protected:
185 void before_end_of_elaboration() override {}
186 void end_of_elaboration() override {}
187 void start_of_simulation() override {}
188 void end_of_simulation() override {}
189
190 explicit sc_port_b(int n, sc_port_policy p) :
191 sc_port_base(sc_gen_unique_name("port"), n, p)
192 {}
193 sc_port_b(const char *name, int n, sc_port_policy p) :
194 sc_port_base(name, n, p)
195 {}
196 virtual ~sc_port_b() {}
197
198 // Implementation defined, but depended on by the tests.
199 int
200 vbind(sc_interface &i) override
201 {
202 IF *interface = dynamic_cast<IF *>(&i);
203 if (!interface)
204 return 2;
205 sc_port_base::bind(*interface);
206 return 0;
207 }
208 int
209 vbind(sc_port_base &pb) override
210 {
211 sc_port_b<IF> *p = dynamic_cast<sc_port_b<IF> *>(&pb);
212 if (!p)
213 return 2;
215 return 0;
216 }
217
218 private:
220
222 _gem5Interface(int n) const override
223 {
224 if (n < 0 || n >= size()) {
225 report_error(SC_ID_GET_IF_, "index out of range");
226 return NULL;
227 }
228 return _interfaces[n];
229 }
230 void
232 {
233 IF *interface = dynamic_cast<IF *>(iface);
234 sc_assert(interface);
235 for (unsigned i = 0; i < _interfaces.size(); i++) {
236 if (interface == _interfaces[i]) {
237 report_error(SC_ID_BIND_IF_TO_PORT_,
238 "interface already bound to port");
239 }
240 }
241 _interfaces.push_back(interface);
242 }
243
244 const char *_ifTypeName() const override { return typeid(IF).name(); }
245
246 // Disabled
249 sc_port_b<IF> &operator = (const sc_port_b<IF> &) { return *this; }
250};
251#pragma GCC diagnostic pop
252
253template <class IF, int N=1, sc_port_policy P=SC_ONE_OR_MORE_BOUND>
254class sc_port : public sc_port_b<IF>
255{
256 public:
257 sc_port() : sc_port_b<IF>(N, P) {}
258 explicit sc_port(const char *name) : sc_port_b<IF>(name, N, P) {}
259 virtual ~sc_port() {}
260
261 // Deprecated binding constructors.
262 explicit sc_port(const IF &interface) : sc_port_b<IF>(N, P)
263 {
264 this->warn_port_constructor();
265 sc_port_b<IF>::bind(const_cast<IF &>(interface));
266 }
267 sc_port(const char *name, const IF &interface) : sc_port_b<IF>(name, N, P)
268 {
269 this->warn_port_constructor();
270 sc_port_b<IF>::bind(const_cast<IF &>(interface));
271 }
272 explicit sc_port(sc_port_b<IF> &parent) : sc_port_b<IF>(N, P)
273 {
274 this->warn_port_constructor();
275 sc_port_b<IF>::bind(parent);
276 }
277 sc_port(const char *name, sc_port_b<IF> &parent) :
278 sc_port_b<IF>(name, N, P)
279 {
280 this->warn_port_constructor();
281 sc_port_b<IF>::bind(parent);
282 }
283 explicit sc_port(sc_port<IF, N, P> &parent) : sc_port_b<IF>(N, P)
284 {
285 this->warn_port_constructor();
286 sc_port_b<IF>::bind(parent);
287 }
288 sc_port(const char *name, sc_port<IF, N, P> &parent) :
289 sc_port_b<IF>(name, N, P)
290 {
291 this->warn_port_constructor();
292 sc_port_b<IF>::bind(parent);
293 }
294
295 virtual const char *kind() const override { return "sc_port"; }
296
297 private:
298 // Disabled
301
302 virtual sc_port_policy _portPolicy() const override { return P; }
303};
304
305} // namespace sc_core
306
307#endif //__SYSTEMC_EXT_CORE_SC_PORT_HH__
const char * name() const
Definition sc_object.cc:44
sc_port_b(const char *name, int n, sc_port_policy p)
Definition sc_port.hh:193
void start_of_simulation() override
Definition sc_port.hh:187
void end_of_simulation() override
Definition sc_port.hh:188
std::vector< IF * > _interfaces
Definition sc_port.hh:219
const sc_interface * get_interface() const
Definition sc_port.hh:177
virtual void bind(sc_port_b< IF > &p)
Definition sc_port.hh:129
sc_interface * _gem5Interface(int n) const override
Definition sc_port.hh:222
int vbind(sc_port_base &pb) override
Definition sc_port.hh:209
virtual ~sc_port_b()
Definition sc_port.hh:196
int vbind(sc_interface &i) override
Definition sc_port.hh:200
sc_interface * get_interface()
Definition sc_port.hh:170
sc_port_b(const sc_port_b< IF > &)
Definition sc_port.hh:248
IF * operator[](int n)
Definition sc_port.hh:151
sc_port_b(int n, sc_port_policy p)
Definition sc_port.hh:190
void before_end_of_elaboration() override
Definition sc_port.hh:185
const char * _ifTypeName() const override
Definition sc_port.hh:244
void _gem5AddInterface(sc_interface *iface) override
Definition sc_port.hh:231
virtual void bind(IF &i)
Definition sc_port.hh:128
sc_port_b< IF > & operator=(const sc_port_b< IF > &)
Definition sc_port.hh:249
void operator()(IF &i)
Definition sc_port.hh:125
void end_of_elaboration() override
Definition sc_port.hh:186
virtual ~sc_port_base()
Definition sc_port.cc:79
int maxSize() const
Definition sc_port.cc:106
const char * kind() const
Definition sc_port.hh:85
virtual const char * _ifTypeName() const =0
virtual sc_port_policy _portPolicy() const =0
virtual sc_interface * _gem5Interface(int n) const =0
virtual int vbind(sc_port_base &)=0
virtual void _gem5AddInterface(sc_interface *i)=0
virtual void before_end_of_elaboration()=0
::sc_gem5::Port * _gem5Port
Definition sc_port.hh:112
virtual void start_of_simulation()=0
void bind(sc_interface &)
Definition sc_port.cc:109
void report_error(const char *id, const char *add_msg) const
Definition sc_port.cc:97
virtual void end_of_simulation()=0
virtual int vbind(sc_interface &)=0
void warn_port_constructor() const
Definition sc_port.cc:85
virtual void end_of_elaboration()=0
sc_port_base(const char *name, int n, sc_port_policy p)
Definition sc_port.cc:59
sc_port(const char *name, sc_port< IF, N, P > &parent)
Definition sc_port.hh:288
virtual ~sc_port()
Definition sc_port.hh:259
sc_port(const sc_port< IF, N, P > &)
Definition sc_port.hh:299
sc_port(const char *name, const IF &interface)
Definition sc_port.hh:267
sc_port(const char *name)
Definition sc_port.hh:258
sc_port(sc_port< IF, N, P > &parent)
Definition sc_port.hh:283
sc_port(const IF &interface)
Definition sc_port.hh:262
virtual sc_port_policy _portPolicy() const override
Definition sc_port.hh:302
sc_port< IF, N, P > & operator=(const sc_port< IF, N, P > &)
Definition sc_port.hh:300
sc_port(const char *name, sc_port_b< IF > &parent)
Definition sc_port.hh:277
sc_port(sc_port_b< IF > &parent)
Definition sc_port.hh:272
virtual const char * kind() const override
Definition sc_port.hh:295
STL vector class.
Definition stl.hh:37
void sc_abort()
Definition sc_report.cc:178
std::vector< sc_trace_params * > sc_trace_params_vec
Definition sc_port.hh:65
sc_port_policy
Definition sc_port.hh:68
@ SC_ZERO_OR_MORE_BOUND
Definition sc_port.hh:70
@ SC_ONE_OR_MORE_BOUND
Definition sc_port.hh:69
#define sc_assert(expr)
sc_trace_file * tf
Definition sc_port.hh:58
sc_trace_params(sc_trace_file *tf, const std::string &name)
Definition sc_port.hh:61

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0