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