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