112955Sgabeblack@google.com/*
212955Sgabeblack@google.com * Copyright 2018 Google, Inc.
312955Sgabeblack@google.com *
412955Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
512955Sgabeblack@google.com * modification, are permitted provided that the following conditions are
612955Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
712955Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
812955Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
912955Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1012955Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1112955Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1212955Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1312955Sgabeblack@google.com * this software without specific prior written permission.
1412955Sgabeblack@google.com *
1512955Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1612955Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1712955Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1812955Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1912955Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2012955Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2112955Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2212955Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2312955Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2412955Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2512955Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2612955Sgabeblack@google.com *
2712955Sgabeblack@google.com * Authors: Gabe Black
2812955Sgabeblack@google.com */
2912955Sgabeblack@google.com
3012955Sgabeblack@google.com#ifndef __SYSTEMC_CORE_EVENT_HH__
3112955Sgabeblack@google.com#define __SYSTEMC_CORE_EVENT_HH__
3212955Sgabeblack@google.com
3313193Sgabeblack@google.com#include <list>
3412955Sgabeblack@google.com#include <string>
3512955Sgabeblack@google.com#include <vector>
3612955Sgabeblack@google.com
3712957Sgabeblack@google.com#include "sim/eventq.hh"
3812955Sgabeblack@google.com#include "systemc/core/list.hh"
3912955Sgabeblack@google.com#include "systemc/core/object.hh"
4013206Sgabeblack@google.com#include "systemc/core/process.hh"
4113063Sgabeblack@google.com#include "systemc/core/sched_event.hh"
4213206Sgabeblack@google.com#include "systemc/core/sensitivity.hh"
4312955Sgabeblack@google.com#include "systemc/ext/core/sc_prim.hh"
4412955Sgabeblack@google.com#include "systemc/ext/core/sc_time.hh"
4512955Sgabeblack@google.com
4612955Sgabeblack@google.comnamespace sc_core
4712955Sgabeblack@google.com{
4812955Sgabeblack@google.com
4912955Sgabeblack@google.comclass sc_event;
5012955Sgabeblack@google.com
5112955Sgabeblack@google.com} // namespace sc_core
5212955Sgabeblack@google.com
5312955Sgabeblack@google.comnamespace sc_gem5
5412955Sgabeblack@google.com{
5512955Sgabeblack@google.com
5612955Sgabeblack@google.comtypedef std::vector<sc_core::sc_event *> Events;
5712955Sgabeblack@google.com
5812957Sgabeblack@google.comclass Sensitivity;
5912957Sgabeblack@google.com
6012955Sgabeblack@google.comclass Event
6112955Sgabeblack@google.com{
6212955Sgabeblack@google.com  public:
6313303Sgabeblack@google.com    Event(sc_core::sc_event *_sc_event, bool internal=false);
6413303Sgabeblack@google.com    Event(sc_core::sc_event *_sc_event, const char *_basename,
6513303Sgabeblack@google.com            bool internal=false);
6612955Sgabeblack@google.com
6712955Sgabeblack@google.com    ~Event();
6812955Sgabeblack@google.com
6912955Sgabeblack@google.com    sc_core::sc_event *sc_event() { return _sc_event; }
7012955Sgabeblack@google.com
7112955Sgabeblack@google.com    const std::string &name() const;
7212955Sgabeblack@google.com    const std::string &basename() const;
7312955Sgabeblack@google.com    bool inHierarchy() const;
7412955Sgabeblack@google.com    sc_core::sc_object *getParentObject() const;
7512955Sgabeblack@google.com
7613208Sgabeblack@google.com    void notify(StaticSensitivities &senses);
7713208Sgabeblack@google.com    void notify(DynamicSensitivities &senses);
7813208Sgabeblack@google.com
7912955Sgabeblack@google.com    void notify();
8012955Sgabeblack@google.com    void notify(const sc_core::sc_time &t);
8112955Sgabeblack@google.com    void
8212955Sgabeblack@google.com    notify(double d, sc_core::sc_time_unit &u)
8312955Sgabeblack@google.com    {
8412955Sgabeblack@google.com        notify(sc_core::sc_time(d, u));
8512955Sgabeblack@google.com    }
8613299Sgabeblack@google.com    void notifyDelayed(const sc_core::sc_time &t);
8712955Sgabeblack@google.com    void cancel();
8812955Sgabeblack@google.com
8912955Sgabeblack@google.com    bool triggered() const;
9013243Sgabeblack@google.com    uint64_t triggeredStamp() const { return _triggeredStamp; }
9112955Sgabeblack@google.com
9212955Sgabeblack@google.com    static Event *
9312955Sgabeblack@google.com    getFromScEvent(sc_core::sc_event *e)
9412955Sgabeblack@google.com    {
9512955Sgabeblack@google.com        return e->_gem5_event;
9612955Sgabeblack@google.com    }
9712955Sgabeblack@google.com
9812955Sgabeblack@google.com    static const Event *
9912955Sgabeblack@google.com    getFromScEvent(const sc_core::sc_event *e)
10012955Sgabeblack@google.com    {
10112955Sgabeblack@google.com        return e->_gem5_event;
10212955Sgabeblack@google.com    }
10312955Sgabeblack@google.com
10413206Sgabeblack@google.com    void
10513206Sgabeblack@google.com    addSensitivity(StaticSensitivity *s) const
10613206Sgabeblack@google.com    {
10713206Sgabeblack@google.com        // Insert static sensitivities in reverse order to match Accellera's
10813206Sgabeblack@google.com        // implementation.
10913208Sgabeblack@google.com        auto &senses = s->ofMethod() ? staticSenseMethod : staticSenseThread;
11013208Sgabeblack@google.com        senses.insert(senses.begin(), s);
11113206Sgabeblack@google.com    }
11213206Sgabeblack@google.com    void
11313206Sgabeblack@google.com    delSensitivity(StaticSensitivity *s) const
11413206Sgabeblack@google.com    {
11513208Sgabeblack@google.com        auto &senses = s->ofMethod() ? staticSenseMethod : staticSenseThread;
11613208Sgabeblack@google.com        for (auto &t: senses) {
11713206Sgabeblack@google.com            if (t == s) {
11813208Sgabeblack@google.com                t = senses.back();
11913208Sgabeblack@google.com                senses.pop_back();
12013206Sgabeblack@google.com                break;
12113206Sgabeblack@google.com            }
12213206Sgabeblack@google.com        }
12313206Sgabeblack@google.com    }
12413206Sgabeblack@google.com    void
12513206Sgabeblack@google.com    addSensitivity(DynamicSensitivity *s) const
12613206Sgabeblack@google.com    {
12713208Sgabeblack@google.com        auto &senses = s->ofMethod() ? dynamicSenseMethod : dynamicSenseThread;
12813208Sgabeblack@google.com        senses.push_back(s);
12913206Sgabeblack@google.com    }
13013206Sgabeblack@google.com    void
13113206Sgabeblack@google.com    delSensitivity(DynamicSensitivity *s) const
13213206Sgabeblack@google.com    {
13313208Sgabeblack@google.com        auto &senses = s->ofMethod() ? dynamicSenseMethod : dynamicSenseThread;
13413208Sgabeblack@google.com        for (auto &t: senses) {
13513206Sgabeblack@google.com            if (t == s) {
13613208Sgabeblack@google.com                t = senses.back();
13713208Sgabeblack@google.com                senses.pop_back();
13813206Sgabeblack@google.com                break;
13913206Sgabeblack@google.com            }
14013206Sgabeblack@google.com        }
14113206Sgabeblack@google.com    }
14212957Sgabeblack@google.com
14313295Sgabeblack@google.com    void clearParent();
14413295Sgabeblack@google.com
14512955Sgabeblack@google.com  private:
14612955Sgabeblack@google.com    sc_core::sc_event *_sc_event;
14712955Sgabeblack@google.com
14812955Sgabeblack@google.com    std::string _basename;
14912955Sgabeblack@google.com    std::string _name;
15012955Sgabeblack@google.com    bool _inHierarchy;
15112955Sgabeblack@google.com
15212955Sgabeblack@google.com    sc_core::sc_object *parent;
15312957Sgabeblack@google.com
15413063Sgabeblack@google.com    ScEvent delayedNotify;
15513243Sgabeblack@google.com    mutable uint64_t _triggeredStamp;
15612957Sgabeblack@google.com
15713208Sgabeblack@google.com    mutable StaticSensitivities staticSenseMethod;
15813208Sgabeblack@google.com    mutable StaticSensitivities staticSenseThread;
15913208Sgabeblack@google.com    mutable DynamicSensitivities dynamicSenseMethod;
16013208Sgabeblack@google.com    mutable DynamicSensitivities dynamicSenseThread;
16112955Sgabeblack@google.com};
16212955Sgabeblack@google.com
16312955Sgabeblack@google.comextern Events topLevelEvents;
16412955Sgabeblack@google.comextern Events allEvents;
16512955Sgabeblack@google.com
16612955Sgabeblack@google.comEventsIt findEvent(const std::string &name);
16712955Sgabeblack@google.com
16812955Sgabeblack@google.com} // namespace sc_gem5
16912955Sgabeblack@google.com
17012955Sgabeblack@google.com#endif  //__SYSTEMC_CORE_EVENT_HH__
171