sc_sensitive.cc revision 13317
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#include "base/logging.hh"
3112957Sgabeblack@google.com#include "systemc/core/process.hh"
3213210Sgabeblack@google.com#include "systemc/ext/channel/sc_in.hh"
3313210Sgabeblack@google.com#include "systemc/ext/channel/sc_inout.hh"
3413210Sgabeblack@google.com#include "systemc/ext/channel/sc_signal_in_if.hh"
3513317Sgabeblack@google.com#include "systemc/ext/core/messages.hh"
3612957Sgabeblack@google.com#include "systemc/ext/core/sc_interface.hh"
3713211Sgabeblack@google.com#include "systemc/ext/core/sc_main.hh"
3812837Sgabeblack@google.com#include "systemc/ext/core/sc_sensitive.hh"
3913211Sgabeblack@google.com#include "systemc/ext/utils/sc_report_handler.hh"
4012837Sgabeblack@google.com
4112837Sgabeblack@google.comnamespace sc_core
4212837Sgabeblack@google.com{
4312837Sgabeblack@google.com
4413211Sgabeblack@google.comnamespace
4513211Sgabeblack@google.com{
4613211Sgabeblack@google.com
4713211Sgabeblack@google.comvoid
4813211Sgabeblack@google.comcheckIfRunning()
4913211Sgabeblack@google.com{
5013211Sgabeblack@google.com    if (sc_is_running())
5113317Sgabeblack@google.com        SC_REPORT_ERROR(SC_ID_MAKE_SENSITIVE_, "simulation running");
5213211Sgabeblack@google.com}
5313211Sgabeblack@google.com
5413211Sgabeblack@google.com} // anonymous namespace
5513211Sgabeblack@google.com
5612952Sgabeblack@google.comsc_sensitive::sc_sensitive() : currentProcess(nullptr) {}
5712952Sgabeblack@google.com
5812837Sgabeblack@google.comsc_sensitive &
5912957Sgabeblack@google.comsc_sensitive::operator << (const sc_event &e)
6012837Sgabeblack@google.com{
6113211Sgabeblack@google.com    checkIfRunning();
6213207Sgabeblack@google.com    sc_gem5::newStaticSensitivityEvent(currentProcess, &e);
6312837Sgabeblack@google.com    return *this;
6412837Sgabeblack@google.com}
6512837Sgabeblack@google.com
6612837Sgabeblack@google.comsc_sensitive &
6712957Sgabeblack@google.comsc_sensitive::operator << (const sc_interface &i)
6812837Sgabeblack@google.com{
6913211Sgabeblack@google.com    checkIfRunning();
7013207Sgabeblack@google.com    sc_gem5::newStaticSensitivityInterface(currentProcess, &i);
7112837Sgabeblack@google.com    return *this;
7212837Sgabeblack@google.com}
7312837Sgabeblack@google.com
7412837Sgabeblack@google.comsc_sensitive &
7512957Sgabeblack@google.comsc_sensitive::operator << (const sc_port_base &b)
7612837Sgabeblack@google.com{
7713211Sgabeblack@google.com    checkIfRunning();
7813207Sgabeblack@google.com    sc_gem5::newStaticSensitivityPort(currentProcess, &b);
7912837Sgabeblack@google.com    return *this;
8012837Sgabeblack@google.com}
8112837Sgabeblack@google.com
8212837Sgabeblack@google.comsc_sensitive &
8312957Sgabeblack@google.comsc_sensitive::operator << (sc_event_finder &f)
8412837Sgabeblack@google.com{
8513211Sgabeblack@google.com    checkIfRunning();
8613207Sgabeblack@google.com    sc_gem5::newStaticSensitivityFinder(currentProcess, &f);
8712837Sgabeblack@google.com    return *this;
8812837Sgabeblack@google.com}
8912837Sgabeblack@google.com
9012952Sgabeblack@google.comsc_sensitive &
9112952Sgabeblack@google.comsc_sensitive::operator << (::sc_gem5::Process *p)
9212952Sgabeblack@google.com{
9312952Sgabeblack@google.com    currentProcess = p;
9412952Sgabeblack@google.com    return *this;
9512952Sgabeblack@google.com}
9612952Sgabeblack@google.com
9713210Sgabeblack@google.com
9813210Sgabeblack@google.comvoid
9913210Sgabeblack@google.comsc_sensitive::operator () (::sc_gem5::Process *p,
10013210Sgabeblack@google.com                           const sc_signal_in_if<bool> &i)
10113210Sgabeblack@google.com{
10213211Sgabeblack@google.com    checkIfRunning();
10313210Sgabeblack@google.com    sc_gem5::newStaticSensitivityEvent(p, &i.posedge_event());
10413210Sgabeblack@google.com}
10513210Sgabeblack@google.com
10613210Sgabeblack@google.comvoid
10713210Sgabeblack@google.comsc_sensitive::operator () (::sc_gem5::Process *p,
10813210Sgabeblack@google.com                           const sc_signal_in_if<sc_dt::sc_logic> &i)
10913210Sgabeblack@google.com{
11013211Sgabeblack@google.com    checkIfRunning();
11113210Sgabeblack@google.com    sc_gem5::newStaticSensitivityEvent(p, &i.posedge_event());
11213210Sgabeblack@google.com}
11313210Sgabeblack@google.com
11413210Sgabeblack@google.comvoid
11513210Sgabeblack@google.comsc_sensitive::operator () (::sc_gem5::Process *p, const sc_in<bool> &port)
11613210Sgabeblack@google.com{
11713211Sgabeblack@google.com    checkIfRunning();
11813210Sgabeblack@google.com    sc_gem5::newStaticSensitivityFinder(p, &port.pos());
11913210Sgabeblack@google.com}
12013210Sgabeblack@google.com
12113210Sgabeblack@google.comvoid
12213210Sgabeblack@google.comsc_sensitive::operator () (::sc_gem5::Process *p,
12313210Sgabeblack@google.com                           const sc_in<sc_dt::sc_logic> &port)
12413210Sgabeblack@google.com{
12513211Sgabeblack@google.com    checkIfRunning();
12613210Sgabeblack@google.com    sc_gem5::newStaticSensitivityFinder(p, &port.pos());
12713210Sgabeblack@google.com}
12813210Sgabeblack@google.com
12913210Sgabeblack@google.comvoid
13013210Sgabeblack@google.comsc_sensitive::operator () (::sc_gem5::Process *p, const sc_inout<bool> &port)
13113210Sgabeblack@google.com{
13213211Sgabeblack@google.com    checkIfRunning();
13313210Sgabeblack@google.com    sc_gem5::newStaticSensitivityFinder(p, &port.pos());
13413210Sgabeblack@google.com}
13513210Sgabeblack@google.com
13613210Sgabeblack@google.comvoid
13713210Sgabeblack@google.comsc_sensitive::operator () (::sc_gem5::Process *p,
13813210Sgabeblack@google.com                           const sc_inout<sc_dt::sc_logic> &port)
13913210Sgabeblack@google.com{
14013211Sgabeblack@google.com    checkIfRunning();
14113210Sgabeblack@google.com    sc_gem5::newStaticSensitivityFinder(p, &port.pos());
14213210Sgabeblack@google.com}
14313210Sgabeblack@google.com
14413210Sgabeblack@google.comvoid
14513210Sgabeblack@google.comsc_sensitive::operator () (::sc_gem5::Process *p, sc_event_finder &f)
14613210Sgabeblack@google.com{
14713211Sgabeblack@google.com    checkIfRunning();
14813210Sgabeblack@google.com    sc_gem5::newStaticSensitivityFinder(p, &f);
14913210Sgabeblack@google.com}
15013210Sgabeblack@google.com
15112837Sgabeblack@google.com} // namespace sc_core
152