Deleted Added
sdiff udiff text old ( 13288:f1c04129f709 ) new ( 13293:60c727f33e16 )
full compact
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 "systemc/core/process.hh"
33#include "systemc/core/sensitivity.hh"
34#include "systemc/ext/channel/sc_signal_in_if.hh"
35
36namespace sc_gem5
37{
38
39void
40Port::finalizePort(StaticSensitivityPort *port)
41{
42 for (int i = 0; i < size(); i++)
43 port->addEvent(&getInterface(i)->default_event());
44}
45
46void
47Port::finalizeFinder(StaticSensitivityFinder *finder)
48{
49 for (int i = 0; i < size(); i++)
50 finder->addEvent(&finder->find(getInterface(i)));
51}
52
53void
54Port::finalizeReset(Reset *reset)
55{
56 assert(size() <= 1);
57 if (size()) {
58 auto iface =
59 dynamic_cast<sc_core::sc_signal_in_if<bool> *>(getInterface(0));
60 assert(iface);
61 if (!reset->install(iface))
62 delete reset;
63 }
64}
65
66void
67Port::sensitive(StaticSensitivityPort *port)
68{
69 if (finalized)
70 finalizePort(port);
71 else
72 sensitivities.push_back(new Sensitivity(port));
73}
74
75void
76Port::sensitive(StaticSensitivityFinder *finder)
77{
78 if (finalized)
79 finalizeFinder(finder);
80 else
81 sensitivities.push_back(new Sensitivity(finder));
82}
83
84void
85Port::addReset(Reset *reset)
86{
87 if (finalized)
88 finalizeReset(reset);
89 else
90 resets.push_back(reset);
91}
92
93void
94Port::finalize()
95{
96 if (finalized)
97 return;
98 finalized = true;
99
100 for (auto &b: bindings) {
101 if (b->interface) {
102 addInterface(b->interface);
103 } else {
104 b->port->_gem5Port->finalize();
105 addInterfaces(b->port);
106 }
107 delete b;
108 }
109
110 bindings.clear();
111
112 for (auto &s: sensitivities) {
113 if (s->port)
114 finalizePort(s->port);
115 else
116 finalizeFinder(s->finder);
117 delete s;
118 }
119
120 sensitivities.clear();
121
122 for (auto &r: resets)
123 finalizeReset(r);
124
125 resets.clear();
126}
127
128void
129Port::regPort()
130{
131 if (!regPortNeeded)
132 return;
133
134 for (int i = 0; i < size(); i++)
135 getInterface(i)->register_port(*portBase, portBase->_ifTypeName());
136}
137
138std::list<Port *> allPorts;
139
140} // namespace sc_gem5