gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Gabe Black
28  */
29 
30 #ifndef __SYSTEMC_CORE_PORT_HH__
31 #define __SYSTEMC_CORE_PORT_HH__
32 
33 #include <list>
34 #include <typeinfo>
35 #include <vector>
36 
37 #include "base/cprintf.hh"
40 
41 namespace sc_gem5
42 {
43 
44 class StaticSensitivityPort;
45 class StaticSensitivityFinder;
46 class Reset;
47 
48 class Port;
49 
51 
52 class Port
53 {
54  private:
56 
57  bool finalized;
58  int _maxSize;
59  int _size;
60 
62 
65  void finalizeReset(Reset *reset);
66 
67  void
69  {
70  portBase->_gem5AddInterface(iface);
71  _size++;
72  }
73 
74  void
76  {
77  // Only the ports farthest from the interfaces call register_port.
78  pb->_gem5Port->regPortNeeded = false;
79  for (int i = 0; i < pb->size(); i++)
81  }
82 
85  {
86  return portBase->_gem5Interface(i);
87  }
88 
89  struct Binding
90  {
92  interface(interface), port(nullptr)
93  {}
94 
96  interface(nullptr), port(port)
97  {}
98 
101  };
102 
103  struct Sensitivity
104  {
106  port(port), finder(nullptr)
107  {}
108 
110  port(nullptr), finder(finder)
111  {}
112 
115  };
116 
120 
121  public:
122  static Port *
123  fromPort(const ::sc_core::sc_port_base *pb)
124  {
125  return pb->_gem5Port;
126  }
127 
129 
130  Port(::sc_core::sc_port_base *port_base, int max) :
131  portBase(port_base), finalized(false), _maxSize(max), _size(0),
132  regPortNeeded(true)
133  {
134  allPorts.push_front(this);
135  }
136 
137  ~Port() { allPorts.remove(this); }
138 
139  void
141  {
142  if (bindings.empty())
143  addInterface(interface);
144  else
145  bindings.push_back(new Binding(interface));
146  }
147 
148  void
150  {
151  bindings.push_back(new Binding(port));
152  }
153 
155  void sensitive(StaticSensitivityFinder *finder);
156  void addReset(Reset *reset);
157 
158  void finalize();
159  void regPort();
160 
161  int size() { return _size; }
162  int maxSize() { return _maxSize ? _maxSize : _size; }
163 };
164 
165 } // namespace sc_gem5
166 
167 #endif // __SYSTEMC_CORE_PORT_HH__
Ports are used to interface objects to each other.
Definition: port.hh:60
StaticSensitivityFinder * finder
Definition: port.hh:114
void finalize()
Definition: port.cc:96
Bitfield< 7 > i
void addInterface(::sc_core::sc_interface *iface)
Definition: port.hh:68
Binding(::sc_core::sc_port_base *port)
Definition: port.hh:95
void finalizeFinder(StaticSensitivityFinder *finder)
Definition: port.cc:49
Port(::sc_core::sc_port_base *port_base, int max)
Definition: port.hh:130
void regPort()
Definition: port.cc:160
std::vector< Binding * > bindings
Definition: port.hh:117
void addReset(Reset *reset)
Definition: port.cc:87
void reset()
Definition: statistics.cc:570
void finalizePort(StaticSensitivityPort *port)
Definition: port.cc:42
std::vector< Reset * > resets
Definition: port.hh:119
STL vector class.
Definition: stl.hh:40
int size() const
Definition: sc_port.cc:109
void finalizeReset(Reset *reset)
Definition: port.cc:56
::sc_core::sc_interface * interface
Definition: port.hh:99
virtual void _gem5AddInterface(sc_interface *i)=0
bool finalized
Definition: port.hh:57
void addInterfaces(::sc_core::sc_port_base *pb)
Definition: port.hh:75
virtual sc_interface * _gem5Interface(int n) const =0
void bind(::sc_core::sc_port_base *port)
Definition: port.hh:149
bool regPortNeeded
Definition: port.hh:61
Binding(::sc_core::sc_interface *interface)
Definition: port.hh:91
void sensitive(StaticSensitivityPort *port)
Definition: port.cc:69
STL list class.
Definition: stl.hh:54
::sc_core::sc_port_base * port
Definition: port.hh:100
::sc_core::sc_port_base * sc_port_base()
Definition: port.hh:128
static Port * fromPort(const ::sc_core::sc_port_base *pb)
Definition: port.hh:123
std::vector< Sensitivity * > sensitivities
Definition: port.hh:118
int _maxSize
Definition: port.hh:58
std::list< Port * > allPorts
Definition: port.cc:169
::sc_core::sc_interface * getInterface(int i)
Definition: port.hh:84
int _size
Definition: port.hh:59
StaticSensitivityPort * port
Definition: port.hh:113
void bind(::sc_core::sc_interface *interface)
Definition: port.hh:140
int size()
Definition: port.hh:161
Sensitivity(StaticSensitivityPort *port)
Definition: port.hh:105
::sc_core::sc_port_base * portBase
Definition: port.hh:55
::sc_gem5::Port * _gem5Port
Definition: sc_port.hh:114
Sensitivity(StaticSensitivityFinder *finder)
Definition: port.hh:109
int maxSize()
Definition: port.hh:162

Generated on Fri Feb 28 2020 16:27:02 for gem5 by doxygen 1.8.13