port.cc revision 13260
113207Sgabeblack@google.com/*
213207Sgabeblack@google.com * Copyright 2018 Google, Inc.
313207Sgabeblack@google.com *
413207Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
513207Sgabeblack@google.com * modification, are permitted provided that the following conditions are
613207Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
713207Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
813207Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
913207Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1013207Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1113207Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1213207Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1313207Sgabeblack@google.com * this software without specific prior written permission.
1413207Sgabeblack@google.com *
1513207Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1613207Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1713207Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1813207Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1913207Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2013207Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2113207Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2213207Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2313207Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2413207Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2513207Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2613207Sgabeblack@google.com *
2713207Sgabeblack@google.com * Authors: Gabe Black
2813207Sgabeblack@google.com */
2913207Sgabeblack@google.com
3013207Sgabeblack@google.com#include "systemc/core/port.hh"
3113207Sgabeblack@google.com
3213207Sgabeblack@google.com#include "systemc/core/sensitivity.hh"
3313260Sgabeblack@google.com#include "systemc/ext/channel/sc_signal_in_if.hh"
3413207Sgabeblack@google.com
3513207Sgabeblack@google.comnamespace sc_gem5
3613207Sgabeblack@google.com{
3713207Sgabeblack@google.com
3813207Sgabeblack@google.comvoid
3913207Sgabeblack@google.comPort::finalizePort(StaticSensitivityPort *port)
4013207Sgabeblack@google.com{
4113207Sgabeblack@google.com    for (int i = 0; i < size(); i++)
4213207Sgabeblack@google.com        port->addEvent(&getInterface(i)->default_event());
4313207Sgabeblack@google.com}
4413207Sgabeblack@google.com
4513207Sgabeblack@google.comvoid
4613207Sgabeblack@google.comPort::finalizeFinder(StaticSensitivityFinder *finder)
4713207Sgabeblack@google.com{
4813207Sgabeblack@google.com    for (int i = 0; i < size(); i++)
4913207Sgabeblack@google.com        finder->addEvent(&finder->find(getInterface(i)));
5013207Sgabeblack@google.com}
5113207Sgabeblack@google.com
5213207Sgabeblack@google.comvoid
5313260Sgabeblack@google.comPort::finalizeReset(ResetSensitivityPort *reset)
5413260Sgabeblack@google.com{
5513260Sgabeblack@google.com    assert(size() <= 1);
5613260Sgabeblack@google.com    if (size()) {
5713260Sgabeblack@google.com        auto iface =
5813260Sgabeblack@google.com            dynamic_cast<sc_core::sc_signal_in_if<bool> *>(getInterface(0));
5913260Sgabeblack@google.com        assert(iface);
6013260Sgabeblack@google.com        reset->setSignal(iface);
6113260Sgabeblack@google.com    }
6213260Sgabeblack@google.com}
6313260Sgabeblack@google.com
6413260Sgabeblack@google.comvoid
6513207Sgabeblack@google.comPort::sensitive(StaticSensitivityPort *port)
6613207Sgabeblack@google.com{
6713207Sgabeblack@google.com    if (finalized)
6813207Sgabeblack@google.com        finalizePort(port);
6913207Sgabeblack@google.com    else
7013207Sgabeblack@google.com        sensitivities.push_back(new Sensitivity(port));
7113207Sgabeblack@google.com}
7213207Sgabeblack@google.com
7313207Sgabeblack@google.comvoid
7413207Sgabeblack@google.comPort::sensitive(StaticSensitivityFinder *finder)
7513207Sgabeblack@google.com{
7613207Sgabeblack@google.com    if (finalized)
7713207Sgabeblack@google.com        finalizeFinder(finder);
7813207Sgabeblack@google.com    else
7913207Sgabeblack@google.com        sensitivities.push_back(new Sensitivity(finder));
8013207Sgabeblack@google.com}
8113207Sgabeblack@google.com
8213207Sgabeblack@google.comvoid
8313260Sgabeblack@google.comPort::sensitive(ResetSensitivityPort *reset)
8413260Sgabeblack@google.com{
8513260Sgabeblack@google.com    if (finalized)
8613260Sgabeblack@google.com        finalizeReset(reset);
8713260Sgabeblack@google.com    else
8813260Sgabeblack@google.com        sensitivities.push_back(new Sensitivity(reset));
8913260Sgabeblack@google.com}
9013260Sgabeblack@google.com
9113260Sgabeblack@google.comvoid
9213207Sgabeblack@google.comPort::finalize()
9313207Sgabeblack@google.com{
9413207Sgabeblack@google.com    if (finalized)
9513207Sgabeblack@google.com        return;
9613207Sgabeblack@google.com    finalized = true;
9713207Sgabeblack@google.com
9813207Sgabeblack@google.com    for (auto &b: bindings) {
9913207Sgabeblack@google.com        if (b->interface) {
10013207Sgabeblack@google.com            addInterface(b->interface);
10113207Sgabeblack@google.com        } else {
10213207Sgabeblack@google.com            b->port->_gem5Port->finalize();
10313207Sgabeblack@google.com            addInterfaces(b->port);
10413207Sgabeblack@google.com        }
10513207Sgabeblack@google.com        delete b;
10613207Sgabeblack@google.com    }
10713207Sgabeblack@google.com
10813207Sgabeblack@google.com    bindings.clear();
10913207Sgabeblack@google.com
11013207Sgabeblack@google.com    for (auto &s: sensitivities) {
11113207Sgabeblack@google.com        if (s->port)
11213207Sgabeblack@google.com            finalizePort(s->port);
11313260Sgabeblack@google.com        else if (s->finder)
11413260Sgabeblack@google.com            finalizeFinder(s->finder);
11513207Sgabeblack@google.com        else
11613260Sgabeblack@google.com            finalizeReset(s->reset);
11713207Sgabeblack@google.com        delete s;
11813207Sgabeblack@google.com    }
11913207Sgabeblack@google.com
12013207Sgabeblack@google.com    sensitivities.clear();
12113207Sgabeblack@google.com}
12213207Sgabeblack@google.com
12313207Sgabeblack@google.comstd::list<Port *> allPorts;
12413207Sgabeblack@google.com
12513207Sgabeblack@google.com} // namespace sc_gem5
126