sc_sensitive.cc revision 13317:36c574a4036e
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 "base/logging.hh"
31#include "systemc/core/process.hh"
32#include "systemc/ext/channel/sc_in.hh"
33#include "systemc/ext/channel/sc_inout.hh"
34#include "systemc/ext/channel/sc_signal_in_if.hh"
35#include "systemc/ext/core/messages.hh"
36#include "systemc/ext/core/sc_interface.hh"
37#include "systemc/ext/core/sc_main.hh"
38#include "systemc/ext/core/sc_sensitive.hh"
39#include "systemc/ext/utils/sc_report_handler.hh"
40
41namespace sc_core
42{
43
44namespace
45{
46
47void
48checkIfRunning()
49{
50    if (sc_is_running())
51        SC_REPORT_ERROR(SC_ID_MAKE_SENSITIVE_, "simulation running");
52}
53
54} // anonymous namespace
55
56sc_sensitive::sc_sensitive() : currentProcess(nullptr) {}
57
58sc_sensitive &
59sc_sensitive::operator << (const sc_event &e)
60{
61    checkIfRunning();
62    sc_gem5::newStaticSensitivityEvent(currentProcess, &e);
63    return *this;
64}
65
66sc_sensitive &
67sc_sensitive::operator << (const sc_interface &i)
68{
69    checkIfRunning();
70    sc_gem5::newStaticSensitivityInterface(currentProcess, &i);
71    return *this;
72}
73
74sc_sensitive &
75sc_sensitive::operator << (const sc_port_base &b)
76{
77    checkIfRunning();
78    sc_gem5::newStaticSensitivityPort(currentProcess, &b);
79    return *this;
80}
81
82sc_sensitive &
83sc_sensitive::operator << (sc_event_finder &f)
84{
85    checkIfRunning();
86    sc_gem5::newStaticSensitivityFinder(currentProcess, &f);
87    return *this;
88}
89
90sc_sensitive &
91sc_sensitive::operator << (::sc_gem5::Process *p)
92{
93    currentProcess = p;
94    return *this;
95}
96
97
98void
99sc_sensitive::operator () (::sc_gem5::Process *p,
100                           const sc_signal_in_if<bool> &i)
101{
102    checkIfRunning();
103    sc_gem5::newStaticSensitivityEvent(p, &i.posedge_event());
104}
105
106void
107sc_sensitive::operator () (::sc_gem5::Process *p,
108                           const sc_signal_in_if<sc_dt::sc_logic> &i)
109{
110    checkIfRunning();
111    sc_gem5::newStaticSensitivityEvent(p, &i.posedge_event());
112}
113
114void
115sc_sensitive::operator () (::sc_gem5::Process *p, const sc_in<bool> &port)
116{
117    checkIfRunning();
118    sc_gem5::newStaticSensitivityFinder(p, &port.pos());
119}
120
121void
122sc_sensitive::operator () (::sc_gem5::Process *p,
123                           const sc_in<sc_dt::sc_logic> &port)
124{
125    checkIfRunning();
126    sc_gem5::newStaticSensitivityFinder(p, &port.pos());
127}
128
129void
130sc_sensitive::operator () (::sc_gem5::Process *p, const sc_inout<bool> &port)
131{
132    checkIfRunning();
133    sc_gem5::newStaticSensitivityFinder(p, &port.pos());
134}
135
136void
137sc_sensitive::operator () (::sc_gem5::Process *p,
138                           const sc_inout<sc_dt::sc_logic> &port)
139{
140    checkIfRunning();
141    sc_gem5::newStaticSensitivityFinder(p, &port.pos());
142}
143
144void
145sc_sensitive::operator () (::sc_gem5::Process *p, sc_event_finder &f)
146{
147    checkIfRunning();
148    sc_gem5::newStaticSensitivityFinder(p, &f);
149}
150
151} // namespace sc_core
152