gem5 v24.0.0.0
Loading...
Searching...
No Matches
sc_port_wrapper.hh
Go to the documentation of this file.
1/*
2 * Copyright 2019 Google LLC.
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_SC_PORT_WRAPPER_HH__
29#define __SYSTEMC_SC_PORT_WRAPPER_HH__
30
31#include <string>
32#include <type_traits>
33
34#include "base/logging.hh"
35#include "sim/port.hh"
39
40namespace sc_gem5
41{
42
43// Forward declaration
44template <typename IF>
45class ScPortWrapper;
46template <typename IF>
47class ScInterfaceWrapper;
48template <typename IF>
49class ScExportWrapper;
50
51template <typename IF>
53{
54 public:
56
57 ScPortWrapper(ScPort& p, const std::string& name, gem5::PortID id)
58 : gem5::Port(name, id), port_(p)
59 {}
60
61 ScPort&
63 {
64 return port_;
65 }
66
67 void
68 unbind() override
69 {
70 using namespace gem5;
71
72 panic("sc_port can't be unbound.");
73 }
74
75 void
76 bind(gem5::Port& peer) override
77 {
78 using namespace gem5;
79
80 // Try ScPortWrapper or ScInterfaceWrapper
81 if (auto* beer = dynamic_cast<ScPortWrapper<IF>*>(&peer)) {
82 port_.bind(beer->port());
83 } else if (auto* iface =
84 dynamic_cast<ScInterfaceWrapper<IF>*>(&peer)) {
85 port_.bind(iface->interface());
86 } else {
87 fatal("Attempt to bind sc_port %s to incompatible port %s.",
88 name(), peer.name());
89 }
90 gem5::Port::bind(peer);
91 }
92
93 private:
95};
96
97template <typename IF>
99{
100 public:
101 ScInterfaceWrapper(IF& i, const std::string name, gem5::PortID id)
102 : gem5::Port(name, id), iface_(i)
103 {}
104
105 IF&
107 {
108 return iface_;
109 }
110
111 void
112 unbind() override
113 {
114 using namespace gem5;
115
116 panic("sc_interface can't be unbound.");
117 }
118
119 void
120 bind(gem5::Port& peer) override
121 {
122 using namespace gem5;
123
124 // fatal error if peer is neither ScPortWrapper nor ScExportWrapper
125 fatal_if(!dynamic_cast<ScPortWrapper<IF>*>(&peer) &&
126 !dynamic_cast<ScExportWrapper<IF>*>(&peer),
127 "Attempt to bind sc_interface %s to incompatible port %s.",
128 name(), peer.name());
129
130 // Don't bind to peer otherwise we may have error messages saying that
131 // this interface has already be bound since the peer may already did
132 // that. Just let sc_port or sc_export do the binding
133 gem5::Port::bind(peer);
134 }
135
136 private:
138};
139
140template <typename IF>
142{
143 public:
145
146 ScExportWrapper(ScExport& p, const std::string& name, gem5::PortID id)
147 : gem5::Port(name, id), port_(p)
148 {}
149
150 ScExport&
152 {
153 return port_;
154 }
155
156 void
157 unbind() override
158 {
159 using namespace gem5;
160
161 panic("sc_export cannot be unbound.");
162 }
163
164 void
165 bind(gem5::Port& peer) override
166 {
167 using namespace gem5;
168
169 auto* iface = dynamic_cast<ScInterfaceWrapper<IF>*>(&peer);
170 fatal_if(!iface,
171 "Attempt to bind sc_export %s to incompatible port %s.",
172 name(), peer.name());
173
174 port_.bind(iface->interface());
175 gem5::Port::bind(peer);
176 }
177
178 private:
180};
181
182} // namespace sc_gem5
183
184#endif // __SYSTEMC_SC_PORT_WRAPPER_HH__
Ports are used to interface objects to each other.
Definition port.hh:62
const PortID id
A numeric identifier to distinguish ports in a vector, and set to InvalidPortID in case this port is ...
Definition port.hh:79
const std::string name() const
Return port name (for DPRINTF).
Definition port.hh:111
virtual void bind(Port &peer)
Attach to a peer port.
Definition port.hh:118
virtual void bind(IF &i)
Definition sc_export.hh:75
virtual void bind(IF &i)
Definition sc_port.hh:128
void unbind() override
Dettach from a peer port.
ScExportWrapper(ScExport &p, const std::string &name, gem5::PortID id)
sc_core::sc_export< IF > ScExport
void bind(gem5::Port &peer) override
Attach to a peer port.
ScInterfaceWrapper(IF &i, const std::string name, gem5::PortID id)
void unbind() override
Dettach from a peer port.
void bind(gem5::Port &peer) override
Attach to a peer port.
void unbind() override
Dettach from a peer port.
sc_core::sc_port_b< IF > ScPort
ScPortWrapper(ScPort &p, const std::string &name, gem5::PortID id)
void bind(gem5::Port &peer) override
Attach to a peer port.
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition logging.hh:236
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition types.hh:245
Port Object Declaration.

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