112837Sgabeblack@google.com/* 212837Sgabeblack@google.com * Copyright 2018 Google, Inc. 312837Sgabeblack@google.com * 412837Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 512837Sgabeblack@google.com * modification, are permitted provided that the following conditions are 612837Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 712837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 812837Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 912837Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1012837Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1112837Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1212837Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1312837Sgabeblack@google.com * this software without specific prior written permission. 1412837Sgabeblack@google.com * 1512837Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1612837Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1712837Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1812837Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1912837Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2012837Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2112837Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2212837Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2312837Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2412837Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2512837Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2612837Sgabeblack@google.com * 2712837Sgabeblack@google.com * Authors: Gabe Black 2812837Sgabeblack@google.com */ 2912837Sgabeblack@google.com 3012837Sgabeblack@google.com#ifndef __SYSTEMC_EXT_CORE_SC_EVENT_HH__ 3112837Sgabeblack@google.com#define __SYSTEMC_EXT_CORE_SC_EVENT_HH__ 3212837Sgabeblack@google.com 3313051Sgabeblack@google.com#include <cassert> 3412955Sgabeblack@google.com#include <set> 3513294Sgabeblack@google.com#include <sstream> 3612837Sgabeblack@google.com#include <vector> 3712837Sgabeblack@google.com 3813324Sgabeblack@google.com#include "../channel/messages.hh" 3913294Sgabeblack@google.com#include "../utils/sc_report_handler.hh" 4013051Sgabeblack@google.com#include "sc_port.hh" 4112837Sgabeblack@google.com#include "sc_time.hh" 4212837Sgabeblack@google.com 4312955Sgabeblack@google.comnamespace sc_gem5 4412955Sgabeblack@google.com{ 4512955Sgabeblack@google.com 4612955Sgabeblack@google.comclass Event; 4713206Sgabeblack@google.comclass DynamicSensitivityEventAndList; 4813206Sgabeblack@google.comclass DynamicSensitivityEventOrList; 4913303Sgabeblack@google.comclass InternalScEvent; 5012955Sgabeblack@google.com 5112955Sgabeblack@google.com} 5212955Sgabeblack@google.com 5312837Sgabeblack@google.comnamespace sc_core 5412837Sgabeblack@google.com{ 5512837Sgabeblack@google.com 5612837Sgabeblack@google.comclass sc_event; 5712837Sgabeblack@google.comclass sc_event_and_expr; 5812837Sgabeblack@google.comclass sc_event_or_expr; 5912924Sgabeblack@google.comclass sc_interface; 6012837Sgabeblack@google.comclass sc_object; 6112837Sgabeblack@google.comclass sc_port_base; 6212837Sgabeblack@google.com 6312837Sgabeblack@google.comclass sc_event_and_list 6412837Sgabeblack@google.com{ 6512837Sgabeblack@google.com public: 6612837Sgabeblack@google.com sc_event_and_list(); 6712837Sgabeblack@google.com sc_event_and_list(const sc_event_and_list &); 6812837Sgabeblack@google.com sc_event_and_list(const sc_event &); 6912837Sgabeblack@google.com sc_event_and_list &operator = (const sc_event_and_list &); 7012955Sgabeblack@google.com ~sc_event_and_list(); 7112837Sgabeblack@google.com 7212837Sgabeblack@google.com int size() const; 7312837Sgabeblack@google.com void swap(sc_event_and_list &); 7412837Sgabeblack@google.com 7512837Sgabeblack@google.com sc_event_and_list &operator &= (const sc_event &); 7612837Sgabeblack@google.com sc_event_and_list &operator &= (const sc_event_and_list &); 7712837Sgabeblack@google.com 7812837Sgabeblack@google.com sc_event_and_expr operator & (const sc_event &) const; 7913406Sgabeblack@google.com sc_event_and_expr operator & (const sc_event_and_list &) const; 8012955Sgabeblack@google.com 8112955Sgabeblack@google.com private: 8212955Sgabeblack@google.com friend class sc_event_and_expr; 8313206Sgabeblack@google.com friend class sc_gem5::DynamicSensitivityEventAndList; 8412955Sgabeblack@google.com 8512955Sgabeblack@google.com explicit sc_event_and_list(bool auto_delete); 8612955Sgabeblack@google.com 8712955Sgabeblack@google.com void insert(sc_event const &e); 8812955Sgabeblack@google.com void insert(sc_event_and_list const &eal); 8912955Sgabeblack@google.com 9012955Sgabeblack@google.com std::set<const sc_event *> events; 9112955Sgabeblack@google.com bool autoDelete; 9212955Sgabeblack@google.com mutable unsigned busy; 9312837Sgabeblack@google.com}; 9412837Sgabeblack@google.com 9512837Sgabeblack@google.comclass sc_event_or_list 9612837Sgabeblack@google.com{ 9712837Sgabeblack@google.com public: 9812837Sgabeblack@google.com sc_event_or_list(); 9912837Sgabeblack@google.com sc_event_or_list(const sc_event_or_list &); 10012837Sgabeblack@google.com sc_event_or_list(const sc_event &); 10112837Sgabeblack@google.com sc_event_or_list& operator = (const sc_event_or_list &); 10212837Sgabeblack@google.com ~sc_event_or_list(); 10312837Sgabeblack@google.com 10412837Sgabeblack@google.com int size() const; 10512837Sgabeblack@google.com void swap(sc_event_or_list &); 10612837Sgabeblack@google.com 10712837Sgabeblack@google.com sc_event_or_list &operator |= (const sc_event &); 10812837Sgabeblack@google.com sc_event_or_list &operator |= (const sc_event_or_list &); 10912837Sgabeblack@google.com 11012837Sgabeblack@google.com sc_event_or_expr operator | (const sc_event &) const; 11112837Sgabeblack@google.com sc_event_or_expr operator | (const sc_event_or_list &) const; 11212955Sgabeblack@google.com 11312955Sgabeblack@google.com private: 11412955Sgabeblack@google.com friend class sc_event_or_expr; 11513206Sgabeblack@google.com friend class sc_gem5::DynamicSensitivityEventOrList; 11612955Sgabeblack@google.com 11712955Sgabeblack@google.com explicit sc_event_or_list(bool auto_delete); 11812955Sgabeblack@google.com 11912955Sgabeblack@google.com void insert(sc_event const &e); 12012955Sgabeblack@google.com void insert(sc_event_or_list const &eol); 12112955Sgabeblack@google.com 12212955Sgabeblack@google.com std::set<const sc_event *> events; 12312955Sgabeblack@google.com bool autoDelete; 12412955Sgabeblack@google.com mutable unsigned busy; 12512837Sgabeblack@google.com}; 12612837Sgabeblack@google.com 12712837Sgabeblack@google.comclass sc_event_and_expr 12812837Sgabeblack@google.com{ 12912837Sgabeblack@google.com public: 13012955Sgabeblack@google.com sc_event_and_expr(sc_event_and_expr const &e); 13112837Sgabeblack@google.com operator const sc_event_and_list &() const; 13212955Sgabeblack@google.com 13312955Sgabeblack@google.com void insert(sc_event const &e) const; 13412955Sgabeblack@google.com void insert(sc_event_and_list const &eal) const; 13512955Sgabeblack@google.com 13612955Sgabeblack@google.com ~sc_event_and_expr(); 13712955Sgabeblack@google.com 13812955Sgabeblack@google.com private: 13912955Sgabeblack@google.com friend class sc_event_and_list; 14012955Sgabeblack@google.com friend class sc_event; 14112955Sgabeblack@google.com 14212955Sgabeblack@google.com sc_event_and_expr(); 14312955Sgabeblack@google.com mutable sc_event_and_list *list; 14412837Sgabeblack@google.com}; 14512837Sgabeblack@google.com 14612837Sgabeblack@google.comsc_event_and_expr operator & (sc_event_and_expr, sc_event const &); 14712837Sgabeblack@google.comsc_event_and_expr operator & (sc_event_and_expr, sc_event_and_list const &); 14812837Sgabeblack@google.com 14912837Sgabeblack@google.comclass sc_event_or_expr 15012837Sgabeblack@google.com{ 15112837Sgabeblack@google.com public: 15212955Sgabeblack@google.com sc_event_or_expr(sc_event_or_expr const &e); 15312837Sgabeblack@google.com operator const sc_event_or_list &() const; 15412955Sgabeblack@google.com 15512955Sgabeblack@google.com void insert(sc_event const &e) const; 15612955Sgabeblack@google.com void insert(sc_event_or_list const &eol) const; 15712955Sgabeblack@google.com 15812955Sgabeblack@google.com ~sc_event_or_expr(); 15912955Sgabeblack@google.com 16012955Sgabeblack@google.com private: 16112955Sgabeblack@google.com friend class sc_event_or_list; 16212955Sgabeblack@google.com friend class sc_event; 16312955Sgabeblack@google.com 16412955Sgabeblack@google.com sc_event_or_expr(); 16512955Sgabeblack@google.com mutable sc_event_or_list *list; 16612837Sgabeblack@google.com}; 16712837Sgabeblack@google.com 16812837Sgabeblack@google.comsc_event_or_expr operator | (sc_event_or_expr, sc_event const &); 16912837Sgabeblack@google.comsc_event_or_expr operator | (sc_event_or_expr, sc_event_or_list const &); 17012837Sgabeblack@google.com 17112837Sgabeblack@google.comclass sc_event 17212837Sgabeblack@google.com{ 17312837Sgabeblack@google.com public: 17412837Sgabeblack@google.com sc_event(); 17512837Sgabeblack@google.com explicit sc_event(const char *); 17612837Sgabeblack@google.com ~sc_event(); 17712837Sgabeblack@google.com 17812837Sgabeblack@google.com const char *name() const; 17912837Sgabeblack@google.com const char *basename() const; 18012837Sgabeblack@google.com bool in_hierarchy() const; 18112837Sgabeblack@google.com sc_object *get_parent_object() const; 18212837Sgabeblack@google.com 18312837Sgabeblack@google.com void notify(); 18412837Sgabeblack@google.com void notify(const sc_time &); 18512837Sgabeblack@google.com void notify(double, sc_time_unit); 18612837Sgabeblack@google.com void cancel(); 18712837Sgabeblack@google.com 18812900Sgabeblack@google.com // Nonstandard 18912900Sgabeblack@google.com // Returns whether this event is currently triggered. 19012900Sgabeblack@google.com bool triggered() const; 19112900Sgabeblack@google.com 19212915Sgabeblack@google.com // Deprecated 19312915Sgabeblack@google.com void notify_delayed(); 19412915Sgabeblack@google.com void notify_delayed(const sc_time &); 19512915Sgabeblack@google.com 19612837Sgabeblack@google.com sc_event_and_expr operator & (const sc_event &) const; 19712837Sgabeblack@google.com sc_event_and_expr operator & (const sc_event_and_list &) const; 19812837Sgabeblack@google.com sc_event_or_expr operator | (const sc_event &) const; 19912837Sgabeblack@google.com sc_event_or_expr operator | (const sc_event_or_list &) const; 20012837Sgabeblack@google.com 20113303Sgabeblack@google.com protected: 20213303Sgabeblack@google.com explicit sc_event(bool); 20313303Sgabeblack@google.com explicit sc_event(bool, const char *); 20413303Sgabeblack@google.com 20512837Sgabeblack@google.com private: 20612837Sgabeblack@google.com // Disabled 20712837Sgabeblack@google.com sc_event(const sc_event &) {} 20812837Sgabeblack@google.com sc_event &operator = (const sc_event &) { return *this; } 20912955Sgabeblack@google.com 21012955Sgabeblack@google.com friend class ::sc_gem5::Event; 21112955Sgabeblack@google.com ::sc_gem5::Event *_gem5_event; 21212837Sgabeblack@google.com}; 21312837Sgabeblack@google.com 21413294Sgabeblack@google.comclass sc_event_finder 21513294Sgabeblack@google.com{ 21613294Sgabeblack@google.com protected: 21713294Sgabeblack@google.com virtual ~sc_event_finder() {} 21813294Sgabeblack@google.com 21913294Sgabeblack@google.com public: 22013294Sgabeblack@google.com // Should be "implementation defined" but used in the tests. 22113294Sgabeblack@google.com virtual const sc_event &find_event(sc_interface *if_p=NULL) const = 0; 22213294Sgabeblack@google.com virtual const sc_port_base *port() const = 0; 22313294Sgabeblack@google.com}; 22413294Sgabeblack@google.com 22513294Sgabeblack@google.comtemplate <class IF> 22613294Sgabeblack@google.comclass sc_event_finder_t : public sc_event_finder 22713294Sgabeblack@google.com{ 22813294Sgabeblack@google.com public: 22913294Sgabeblack@google.com sc_event_finder_t(const sc_port_base &p, 23013294Sgabeblack@google.com const sc_event & (IF::*_method)() const) : 23113294Sgabeblack@google.com _method(_method) 23213294Sgabeblack@google.com { 23313294Sgabeblack@google.com _port = dynamic_cast<const sc_port_b<IF> *>(&p); 23413294Sgabeblack@google.com assert(_port); 23513294Sgabeblack@google.com } 23613294Sgabeblack@google.com 23713294Sgabeblack@google.com virtual ~sc_event_finder_t() {} 23813294Sgabeblack@google.com 23913380Sgabeblack@google.com const sc_port_base *port() const override { return _port; } 24013294Sgabeblack@google.com 24113380Sgabeblack@google.com const sc_event &find_event(sc_interface *if_p=NULL) const override; 24213294Sgabeblack@google.com 24313294Sgabeblack@google.com private: 24413294Sgabeblack@google.com const sc_port_b<IF> *_port; 24513294Sgabeblack@google.com const sc_event &(IF::*_method)() const; 24613294Sgabeblack@google.com}; 24713294Sgabeblack@google.com 24812837Sgabeblack@google.comconst std::vector<sc_event *> &sc_get_top_level_events(); 24912837Sgabeblack@google.comsc_event *sc_find_event(const char *); 25012837Sgabeblack@google.com 25112837Sgabeblack@google.com} // namespace sc_core 25212837Sgabeblack@google.com 25313303Sgabeblack@google.comnamespace sc_gem5 25413303Sgabeblack@google.com{ 25513303Sgabeblack@google.com 25613303Sgabeblack@google.comclass InternalScEvent : public ::sc_core::sc_event 25713303Sgabeblack@google.com{ 25813303Sgabeblack@google.com public: 25913303Sgabeblack@google.com InternalScEvent(); 26013303Sgabeblack@google.com InternalScEvent(const char *); 26113303Sgabeblack@google.com}; 26213303Sgabeblack@google.com 26313303Sgabeblack@google.com} // namespace sc_gem5 26413303Sgabeblack@google.com 26513380Sgabeblack@google.comnamespace sc_core 26613380Sgabeblack@google.com{ 26713380Sgabeblack@google.com 26813380Sgabeblack@google.comtemplate <class IF> 26913380Sgabeblack@google.comconst sc_event & 27013380Sgabeblack@google.comsc_event_finder_t<IF>::find_event(sc_interface *if_p) const 27113380Sgabeblack@google.com{ 27213380Sgabeblack@google.com static const sc_gem5::InternalScEvent none; 27313380Sgabeblack@google.com const IF *iface = if_p ? dynamic_cast<const IF *>(if_p) : 27413380Sgabeblack@google.com dynamic_cast<const IF *>(_port->get_interface()); 27513380Sgabeblack@google.com if (!iface) { 27613380Sgabeblack@google.com std::ostringstream ss; 27713380Sgabeblack@google.com ss << "port is not bound: port '" << _port->name() << "' (" << 27813380Sgabeblack@google.com _port->kind() << ")"; 27913380Sgabeblack@google.com SC_REPORT_ERROR(SC_ID_FIND_EVENT_, ss.str().c_str()); 28013380Sgabeblack@google.com return none; 28113380Sgabeblack@google.com } 28213380Sgabeblack@google.com return (const_cast<IF *>(iface)->*_method)(); 28313380Sgabeblack@google.com} 28413380Sgabeblack@google.com 28513380Sgabeblack@google.com} // namespace sc_core 28613380Sgabeblack@google.com 28712837Sgabeblack@google.com#endif //__SYSTEMC_EXT_CORE_SC_INTERFACE_HH__ 288