gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
port.cc
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 #include "systemc/core/port.hh"
31 
32 #include "base/logging.hh"
33 #include "systemc/core/process.hh"
37 
38 namespace sc_gem5
39 {
40 
41 void
43 {
44  for (int i = 0; i < size(); i++)
45  port->addEvent(&getInterface(i)->default_event());
46 }
47 
48 void
50 {
51  for (int i = 0; i < size(); i++)
52  finder->addEvent(&finder->find(getInterface(i)));
53 }
54 
55 void
57 {
58  assert(size() <= 1);
59  if (size()) {
60  auto iface =
61  dynamic_cast<sc_core::sc_signal_in_if<bool> *>(getInterface(0));
62  assert(iface);
63  if (!reset->install(iface))
64  delete reset;
65  }
66 }
67 
68 void
70 {
71  if (finalized)
72  finalizePort(port);
73  else
74  sensitivities.push_back(new Sensitivity(port));
75 }
76 
77 void
79 {
80  if (finalized)
81  finalizeFinder(finder);
82  else
83  sensitivities.push_back(new Sensitivity(finder));
84 }
85 
86 void
88 {
89  if (finalized)
90  finalizeReset(reset);
91  else
92  resets.push_back(reset);
93 }
94 
95 void
97 {
98  if (finalized)
99  return;
100  finalized = true;
101 
102  for (auto &b: bindings) {
103  if (b->interface) {
104  addInterface(b->interface);
105  } else {
106  b->port->_gem5Port->finalize();
107  addInterfaces(b->port);
108  }
109  delete b;
110  }
111 
112  bindings.clear();
113 
114  for (auto &s: sensitivities) {
115  if (s->port)
116  finalizePort(s->port);
117  else
118  finalizeFinder(s->finder);
119  delete s;
120  }
121 
122  sensitivities.clear();
123 
124  for (auto &r: resets)
125  finalizeReset(r);
126 
127  resets.clear();
128 
129  if (size() > maxSize()) {
130  std::ostringstream ss;
131  ss << size() << " binds exceeds maximum of " << maxSize() <<
132  " allowed";
134  ss.str().c_str());
135  }
136 
137  switch (portBase->_portPolicy()) {
139  if (size() == 0)
141  "port not bound");
142  break;
144  if (size() < maxSize() || size() < 1) {
145  std::stringstream ss;
146  ss << size() << " actual binds is less than required " <<
147  maxSize();
149  ss.str().c_str());
150  }
151  break;
153  break;
154  default:
155  panic("Unrecognized port policy %d.", portBase->_portPolicy());
156  }
157 }
158 
159 void
161 {
162  if (!regPortNeeded)
163  return;
164 
165  for (int i = 0; i < size(); i++)
167 }
168 
170 
171 } // namespace sc_gem5
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
void finalize()
Definition: port.cc:96
Bitfield< 7 > i
void addInterface(::sc_core::sc_interface *iface)
Definition: port.hh:68
void finalizeFinder(StaticSensitivityFinder *finder)
Definition: port.cc:49
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
const ::sc_core::sc_event & find(::sc_core::sc_interface *i)
Definition: sensitivity.cc:179
void finalizePort(StaticSensitivityPort *port)
Definition: port.cc:42
std::vector< Reset * > resets
Definition: port.hh:119
void report_error(const char *id, const char *add_msg) const
Definition: sc_port.cc:99
const char SC_ID_COMPLETE_BINDING_[]
Definition: messages.cc:48
Bitfield< 7 > b
void finalizeReset(Reset *reset)
Definition: port.cc:56
Bitfield< 4 > s
bool finalized
Definition: port.hh:57
void addInterfaces(::sc_core::sc_port_base *pb)
Definition: port.hh:75
bool regPortNeeded
Definition: port.hh:61
virtual sc_port_policy _portPolicy() const =0
void sensitive(StaticSensitivityPort *port)
Definition: port.cc:69
Bitfield< 21 > ss
STL list class.
Definition: stl.hh:54
virtual const char * _ifTypeName() const =0
void addEvent(const ::sc_core::sc_event *event)
Definition: sensitivity.hh:165
std::vector< Sensitivity * > sensitivities
Definition: port.hh:118
virtual void register_port(sc_port_base &, const char *)
Definition: sc_interface.cc:38
std::list< Port * > allPorts
Definition: port.cc:169
::sc_core::sc_interface * getInterface(int i)
Definition: port.hh:84
int size()
Definition: port.hh:161
::sc_core::sc_port_base * portBase
Definition: port.hh:55
bool install(const sc_core::sc_signal_in_if< bool > *s)
Definition: process.hh:216
int maxSize()
Definition: port.hh:162

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