sc_event.hh (13303:045f002c325c) sc_event.hh (13324:c8b709468e61)
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#ifndef __SYSTEMC_EXT_CORE_SC_EVENT_HH__
31#define __SYSTEMC_EXT_CORE_SC_EVENT_HH__
32
33#include <cassert>
34#include <set>
35#include <sstream>
36#include <vector>
37
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#ifndef __SYSTEMC_EXT_CORE_SC_EVENT_HH__
31#define __SYSTEMC_EXT_CORE_SC_EVENT_HH__
32
33#include <cassert>
34#include <set>
35#include <sstream>
36#include <vector>
37
38#include "../channel/messages.hh"
38#include "../utils/sc_report_handler.hh"
39#include "sc_port.hh"
40#include "sc_time.hh"
41
42namespace sc_gem5
43{
44
45class Event;
46class DynamicSensitivityEventAndList;
47class DynamicSensitivityEventOrList;
48class InternalScEvent;
49
50}
51
52namespace sc_core
53{
54
55class sc_event;
56class sc_event_and_expr;
57class sc_event_or_expr;
58class sc_interface;
59class sc_object;
60class sc_port_base;
61
62class sc_event_and_list
63{
64 public:
65 sc_event_and_list();
66 sc_event_and_list(const sc_event_and_list &);
67 sc_event_and_list(const sc_event &);
68 sc_event_and_list &operator = (const sc_event_and_list &);
69 ~sc_event_and_list();
70
71 int size() const;
72 void swap(sc_event_and_list &);
73
74 sc_event_and_list &operator &= (const sc_event &);
75 sc_event_and_list &operator &= (const sc_event_and_list &);
76
77 sc_event_and_expr operator & (const sc_event &) const;
78 sc_event_and_expr operator & (const sc_event_and_list &);
79
80 private:
81 friend class sc_event_and_expr;
82 friend class sc_gem5::DynamicSensitivityEventAndList;
83
84 explicit sc_event_and_list(bool auto_delete);
85
86 void insert(sc_event const &e);
87 void insert(sc_event_and_list const &eal);
88
89 std::set<const sc_event *> events;
90 bool autoDelete;
91 mutable unsigned busy;
92};
93
94class sc_event_or_list
95{
96 public:
97 sc_event_or_list();
98 sc_event_or_list(const sc_event_or_list &);
99 sc_event_or_list(const sc_event &);
100 sc_event_or_list& operator = (const sc_event_or_list &);
101 ~sc_event_or_list();
102
103 int size() const;
104 void swap(sc_event_or_list &);
105
106 sc_event_or_list &operator |= (const sc_event &);
107 sc_event_or_list &operator |= (const sc_event_or_list &);
108
109 sc_event_or_expr operator | (const sc_event &) const;
110 sc_event_or_expr operator | (const sc_event_or_list &) const;
111
112 private:
113 friend class sc_event_or_expr;
114 friend class sc_gem5::DynamicSensitivityEventOrList;
115
116 explicit sc_event_or_list(bool auto_delete);
117
118 void insert(sc_event const &e);
119 void insert(sc_event_or_list const &eol);
120
121 std::set<const sc_event *> events;
122 bool autoDelete;
123 mutable unsigned busy;
124};
125
126class sc_event_and_expr
127{
128 public:
129 sc_event_and_expr(sc_event_and_expr const &e);
130 operator const sc_event_and_list &() const;
131
132 void insert(sc_event const &e) const;
133 void insert(sc_event_and_list const &eal) const;
134
135 ~sc_event_and_expr();
136
137 private:
138 friend class sc_event_and_list;
139 friend class sc_event;
140
141 sc_event_and_expr();
142 mutable sc_event_and_list *list;
143};
144
145sc_event_and_expr operator & (sc_event_and_expr, sc_event const &);
146sc_event_and_expr operator & (sc_event_and_expr, sc_event_and_list const &);
147
148class sc_event_or_expr
149{
150 public:
151 sc_event_or_expr(sc_event_or_expr const &e);
152 operator const sc_event_or_list &() const;
153
154 void insert(sc_event const &e) const;
155 void insert(sc_event_or_list const &eol) const;
156
157 ~sc_event_or_expr();
158
159 private:
160 friend class sc_event_or_list;
161 friend class sc_event;
162
163 sc_event_or_expr();
164 mutable sc_event_or_list *list;
165};
166
167sc_event_or_expr operator | (sc_event_or_expr, sc_event const &);
168sc_event_or_expr operator | (sc_event_or_expr, sc_event_or_list const &);
169
170class sc_event
171{
172 public:
173 sc_event();
174 explicit sc_event(const char *);
175 ~sc_event();
176
177 const char *name() const;
178 const char *basename() const;
179 bool in_hierarchy() const;
180 sc_object *get_parent_object() const;
181
182 void notify();
183 void notify(const sc_time &);
184 void notify(double, sc_time_unit);
185 void cancel();
186
187 // Nonstandard
188 // Returns whether this event is currently triggered.
189 bool triggered() const;
190
191 // Deprecated
192 void notify_delayed();
193 void notify_delayed(const sc_time &);
194
195 sc_event_and_expr operator & (const sc_event &) const;
196 sc_event_and_expr operator & (const sc_event_and_list &) const;
197 sc_event_or_expr operator | (const sc_event &) const;
198 sc_event_or_expr operator | (const sc_event_or_list &) const;
199
200 protected:
201 explicit sc_event(bool);
202 explicit sc_event(bool, const char *);
203
204 private:
205 // Disabled
206 sc_event(const sc_event &) {}
207 sc_event &operator = (const sc_event &) { return *this; }
208
209 friend class ::sc_gem5::Event;
210 ::sc_gem5::Event *_gem5_event;
211};
212
213class sc_event_finder
214{
215 protected:
216 virtual ~sc_event_finder() {}
217
218 public:
219 // Should be "implementation defined" but used in the tests.
220 virtual const sc_event &find_event(sc_interface *if_p=NULL) const = 0;
221 virtual const sc_port_base *port() const = 0;
222};
223
224template <class IF>
225class sc_event_finder_t : public sc_event_finder
226{
227 public:
228 sc_event_finder_t(const sc_port_base &p,
229 const sc_event & (IF::*_method)() const) :
230 _method(_method)
231 {
232 _port = dynamic_cast<const sc_port_b<IF> *>(&p);
233 assert(_port);
234 }
235
236 virtual ~sc_event_finder_t() {}
237
238 const sc_port_base *port() const { return _port; }
239
240 const sc_event &
241 find_event(sc_interface *if_p=NULL) const override
242 {
243 static const sc_gem5::InternalScEvent none;
244 const IF *iface = if_p ? dynamic_cast<const IF *>(if_p) :
245 dynamic_cast<const IF *>(_port->get_interface());
246 if (!iface) {
247 std::ostringstream ss;
248 ss << "port is not bound: port '" << _port->name() << "' (" <<
249 _port->kind() << ")";
39#include "../utils/sc_report_handler.hh"
40#include "sc_port.hh"
41#include "sc_time.hh"
42
43namespace sc_gem5
44{
45
46class Event;
47class DynamicSensitivityEventAndList;
48class DynamicSensitivityEventOrList;
49class InternalScEvent;
50
51}
52
53namespace sc_core
54{
55
56class sc_event;
57class sc_event_and_expr;
58class sc_event_or_expr;
59class sc_interface;
60class sc_object;
61class sc_port_base;
62
63class sc_event_and_list
64{
65 public:
66 sc_event_and_list();
67 sc_event_and_list(const sc_event_and_list &);
68 sc_event_and_list(const sc_event &);
69 sc_event_and_list &operator = (const sc_event_and_list &);
70 ~sc_event_and_list();
71
72 int size() const;
73 void swap(sc_event_and_list &);
74
75 sc_event_and_list &operator &= (const sc_event &);
76 sc_event_and_list &operator &= (const sc_event_and_list &);
77
78 sc_event_and_expr operator & (const sc_event &) const;
79 sc_event_and_expr operator & (const sc_event_and_list &);
80
81 private:
82 friend class sc_event_and_expr;
83 friend class sc_gem5::DynamicSensitivityEventAndList;
84
85 explicit sc_event_and_list(bool auto_delete);
86
87 void insert(sc_event const &e);
88 void insert(sc_event_and_list const &eal);
89
90 std::set<const sc_event *> events;
91 bool autoDelete;
92 mutable unsigned busy;
93};
94
95class sc_event_or_list
96{
97 public:
98 sc_event_or_list();
99 sc_event_or_list(const sc_event_or_list &);
100 sc_event_or_list(const sc_event &);
101 sc_event_or_list& operator = (const sc_event_or_list &);
102 ~sc_event_or_list();
103
104 int size() const;
105 void swap(sc_event_or_list &);
106
107 sc_event_or_list &operator |= (const sc_event &);
108 sc_event_or_list &operator |= (const sc_event_or_list &);
109
110 sc_event_or_expr operator | (const sc_event &) const;
111 sc_event_or_expr operator | (const sc_event_or_list &) const;
112
113 private:
114 friend class sc_event_or_expr;
115 friend class sc_gem5::DynamicSensitivityEventOrList;
116
117 explicit sc_event_or_list(bool auto_delete);
118
119 void insert(sc_event const &e);
120 void insert(sc_event_or_list const &eol);
121
122 std::set<const sc_event *> events;
123 bool autoDelete;
124 mutable unsigned busy;
125};
126
127class sc_event_and_expr
128{
129 public:
130 sc_event_and_expr(sc_event_and_expr const &e);
131 operator const sc_event_and_list &() const;
132
133 void insert(sc_event const &e) const;
134 void insert(sc_event_and_list const &eal) const;
135
136 ~sc_event_and_expr();
137
138 private:
139 friend class sc_event_and_list;
140 friend class sc_event;
141
142 sc_event_and_expr();
143 mutable sc_event_and_list *list;
144};
145
146sc_event_and_expr operator & (sc_event_and_expr, sc_event const &);
147sc_event_and_expr operator & (sc_event_and_expr, sc_event_and_list const &);
148
149class sc_event_or_expr
150{
151 public:
152 sc_event_or_expr(sc_event_or_expr const &e);
153 operator const sc_event_or_list &() const;
154
155 void insert(sc_event const &e) const;
156 void insert(sc_event_or_list const &eol) const;
157
158 ~sc_event_or_expr();
159
160 private:
161 friend class sc_event_or_list;
162 friend class sc_event;
163
164 sc_event_or_expr();
165 mutable sc_event_or_list *list;
166};
167
168sc_event_or_expr operator | (sc_event_or_expr, sc_event const &);
169sc_event_or_expr operator | (sc_event_or_expr, sc_event_or_list const &);
170
171class sc_event
172{
173 public:
174 sc_event();
175 explicit sc_event(const char *);
176 ~sc_event();
177
178 const char *name() const;
179 const char *basename() const;
180 bool in_hierarchy() const;
181 sc_object *get_parent_object() const;
182
183 void notify();
184 void notify(const sc_time &);
185 void notify(double, sc_time_unit);
186 void cancel();
187
188 // Nonstandard
189 // Returns whether this event is currently triggered.
190 bool triggered() const;
191
192 // Deprecated
193 void notify_delayed();
194 void notify_delayed(const sc_time &);
195
196 sc_event_and_expr operator & (const sc_event &) const;
197 sc_event_and_expr operator & (const sc_event_and_list &) const;
198 sc_event_or_expr operator | (const sc_event &) const;
199 sc_event_or_expr operator | (const sc_event_or_list &) const;
200
201 protected:
202 explicit sc_event(bool);
203 explicit sc_event(bool, const char *);
204
205 private:
206 // Disabled
207 sc_event(const sc_event &) {}
208 sc_event &operator = (const sc_event &) { return *this; }
209
210 friend class ::sc_gem5::Event;
211 ::sc_gem5::Event *_gem5_event;
212};
213
214class sc_event_finder
215{
216 protected:
217 virtual ~sc_event_finder() {}
218
219 public:
220 // Should be "implementation defined" but used in the tests.
221 virtual const sc_event &find_event(sc_interface *if_p=NULL) const = 0;
222 virtual const sc_port_base *port() const = 0;
223};
224
225template <class IF>
226class sc_event_finder_t : public sc_event_finder
227{
228 public:
229 sc_event_finder_t(const sc_port_base &p,
230 const sc_event & (IF::*_method)() const) :
231 _method(_method)
232 {
233 _port = dynamic_cast<const sc_port_b<IF> *>(&p);
234 assert(_port);
235 }
236
237 virtual ~sc_event_finder_t() {}
238
239 const sc_port_base *port() const { return _port; }
240
241 const sc_event &
242 find_event(sc_interface *if_p=NULL) const override
243 {
244 static const sc_gem5::InternalScEvent none;
245 const IF *iface = if_p ? dynamic_cast<const IF *>(if_p) :
246 dynamic_cast<const IF *>(_port->get_interface());
247 if (!iface) {
248 std::ostringstream ss;
249 ss << "port is not bound: port '" << _port->name() << "' (" <<
250 _port->kind() << ")";
250 SC_REPORT_ERROR("(E118) find event failed", ss.str().c_str());
251 SC_REPORT_ERROR(SC_ID_FIND_EVENT_, ss.str().c_str());
251 return none;
252 }
253 return (const_cast<IF *>(iface)->*_method)();
254 }
255
256 private:
257 const sc_port_b<IF> *_port;
258 const sc_event &(IF::*_method)() const;
259};
260
261const std::vector<sc_event *> &sc_get_top_level_events();
262sc_event *sc_find_event(const char *);
263
264} // namespace sc_core
265
266namespace sc_gem5
267{
268
269class InternalScEvent : public ::sc_core::sc_event
270{
271 public:
272 InternalScEvent();
273 InternalScEvent(const char *);
274};
275
276} // namespace sc_gem5
277
278#endif //__SYSTEMC_EXT_CORE_SC_INTERFACE_HH__
252 return none;
253 }
254 return (const_cast<IF *>(iface)->*_method)();
255 }
256
257 private:
258 const sc_port_b<IF> *_port;
259 const sc_event &(IF::*_method)() const;
260};
261
262const std::vector<sc_event *> &sc_get_top_level_events();
263sc_event *sc_find_event(const char *);
264
265} // namespace sc_core
266
267namespace sc_gem5
268{
269
270class InternalScEvent : public ::sc_core::sc_event
271{
272 public:
273 InternalScEvent();
274 InternalScEvent(const char *);
275};
276
277} // namespace sc_gem5
278
279#endif //__SYSTEMC_EXT_CORE_SC_INTERFACE_HH__