sc_process_handle.cc (12953:ddfd5e4643a9) sc_process_handle.cc (12960:ff77756883e0)
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/core/scheduler.hh"
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/core/scheduler.hh"
33#include "systemc/ext/core/sc_main.hh"
33#include "systemc/ext/core/sc_process_handle.hh"
34
35namespace sc_core
36{
37
38const char *
39sc_unwind_exception::what() const throw()
40{
41 panic("%s for base class called.\n", __PRETTY_FUNCTION__);
42}
43
44bool
45sc_unwind_exception::is_reset() const
46{
47 panic("%s for base class called.\n", __PRETTY_FUNCTION__);
48}
49
50sc_unwind_exception::sc_unwind_exception() {}
51sc_unwind_exception::sc_unwind_exception(const sc_unwind_exception &) {}
52sc_unwind_exception::~sc_unwind_exception() throw() {}
53
54
55const char *
56sc_process_b::name()
57{
58 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
59 return "";
60}
61
62const char *
63sc_process_b::kind()
64{
65 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
66 return "";
67}
68
69
70sc_process_b *
71sc_get_curr_process_handle()
72{
73 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
74 return nullptr;
75}
76
77
78sc_process_handle::sc_process_handle() : _gem5_process(nullptr) {}
79
80sc_process_handle::sc_process_handle(const sc_process_handle &handle) :
81 _gem5_process(handle._gem5_process)
82{
83 if (_gem5_process)
84 _gem5_process->incref();
85}
86
87sc_process_handle::sc_process_handle(sc_object *obj) :
88 _gem5_process(dynamic_cast<::sc_gem5::Process *>(obj))
89{
90 if (_gem5_process)
91 _gem5_process->incref();
92}
93
94sc_process_handle::~sc_process_handle()
95{
96 if (_gem5_process)
97 _gem5_process->decref();
98}
99
100
101bool
102sc_process_handle::valid() const
103{
104 return _gem5_process != nullptr;
105}
106
107
108sc_process_handle &
109sc_process_handle::operator = (const sc_process_handle &handle)
110{
111 if (_gem5_process)
112 _gem5_process->decref();
113 _gem5_process = handle._gem5_process;
114 if (_gem5_process)
115 _gem5_process->incref();
116 return *this;
117}
118
119bool
120sc_process_handle::operator == (const sc_process_handle &handle) const
121{
122 return _gem5_process && handle._gem5_process &&
123 (_gem5_process == handle._gem5_process);
124}
125
126bool
127sc_process_handle::operator != (const sc_process_handle &handle) const
128{
129 return !(handle == *this);
130}
131
132bool
133sc_process_handle::operator < (const sc_process_handle &other) const
134{
135 return _gem5_process < other._gem5_process;
136}
137
138void
139sc_process_handle::swap(sc_process_handle &handle)
140{
141 ::sc_gem5::Process *temp = handle._gem5_process;
142 handle._gem5_process = _gem5_process;
143 _gem5_process = temp;
144}
145
146
147const char *
148sc_process_handle::name() const
149{
150 return _gem5_process ? _gem5_process->name() : "";
151}
152
153sc_curr_proc_kind
154sc_process_handle::proc_kind() const
155{
156 return _gem5_process ? _gem5_process->procKind() : SC_NO_PROC_;
157}
158
159const std::vector<sc_object *> &
160sc_process_handle::get_child_objects() const
161{
162 static const std::vector<sc_object *> empty;
163 return _gem5_process ? _gem5_process->get_child_objects() : empty;
164}
165
166const std::vector<sc_event *> &
167sc_process_handle::get_child_events() const
168{
169 static const std::vector<sc_event *> empty;
170 return _gem5_process ? _gem5_process->get_child_events() : empty;
171}
172
173sc_object *
174sc_process_handle::get_parent_object() const
175{
176 return _gem5_process ? _gem5_process->get_parent_object() : nullptr;
177}
178
179sc_object *
180sc_process_handle::get_process_object() const
181{
182 return _gem5_process;
183}
184
185bool
186sc_process_handle::dynamic() const
187{
188 return _gem5_process ? _gem5_process->dynamic() : false;
189}
190
191bool
192sc_process_handle::terminated() const
193{
194 return _gem5_process ? _gem5_process->terminated() : false;
195}
196
197const sc_event &
198sc_process_handle::terminated_event() const
199{
200 static sc_event non_event;
201 return _gem5_process ? _gem5_process->terminatedEvent() : non_event;
202}
203
204
205void
206sc_process_handle::suspend(sc_descendent_inclusion_info include_descendants)
207{
208 if (!_gem5_process)
209 return;
210 _gem5_process->suspend(include_descendants == SC_INCLUDE_DESCENDANTS);
211}
212
213void
214sc_process_handle::resume(sc_descendent_inclusion_info include_descendants)
215{
216 if (!_gem5_process)
217 return;
218 _gem5_process->resume(include_descendants == SC_INCLUDE_DESCENDANTS);
219}
220
221void
222sc_process_handle::disable(sc_descendent_inclusion_info include_descendants)
223{
224 if (!_gem5_process)
225 return;
226 _gem5_process->disable(include_descendants == SC_INCLUDE_DESCENDANTS);
227}
228
229void
230sc_process_handle::enable(sc_descendent_inclusion_info include_descendants)
231{
232 if (!_gem5_process)
233 return;
234 _gem5_process->enable(include_descendants == SC_INCLUDE_DESCENDANTS);
235}
236
237void
238sc_process_handle::kill(sc_descendent_inclusion_info include_descendants)
239{
240 if (!_gem5_process)
241 return;
242 _gem5_process->kill(include_descendants == SC_INCLUDE_DESCENDANTS);
243}
244
245void
246sc_process_handle::reset(sc_descendent_inclusion_info include_descendants)
247{
248 if (!_gem5_process)
249 return;
250 _gem5_process->reset(include_descendants == SC_INCLUDE_DESCENDANTS);
251}
252
253bool
254sc_process_handle::is_unwinding()
255{
256 if (!_gem5_process) {
257 //TODO This should generate a systemc style warning if the handle is
258 //invalid.
259 return false;
260 } else {
261 return _gem5_process->isUnwinding();
262 }
263}
264
265const sc_event &
266sc_process_handle::reset_event() const
267{
268 static sc_event non_event;
269 return _gem5_process ? _gem5_process->resetEvent() : non_event;
270}
271
272
273void
274sc_process_handle::sync_reset_on(
275 sc_descendent_inclusion_info include_descendants)
276{
277 if (!_gem5_process)
278 return;
279 _gem5_process->syncResetOn(include_descendants == SC_INCLUDE_DESCENDANTS);
280}
281
282void
283sc_process_handle::sync_reset_off(
284 sc_descendent_inclusion_info include_descendants)
285{
286 if (!_gem5_process)
287 return;
288 _gem5_process->syncResetOff(include_descendants == SC_INCLUDE_DESCENDANTS);
289}
290
291
292sc_process_handle
293sc_get_current_process_handle()
294{
34#include "systemc/ext/core/sc_process_handle.hh"
35
36namespace sc_core
37{
38
39const char *
40sc_unwind_exception::what() const throw()
41{
42 panic("%s for base class called.\n", __PRETTY_FUNCTION__);
43}
44
45bool
46sc_unwind_exception::is_reset() const
47{
48 panic("%s for base class called.\n", __PRETTY_FUNCTION__);
49}
50
51sc_unwind_exception::sc_unwind_exception() {}
52sc_unwind_exception::sc_unwind_exception(const sc_unwind_exception &) {}
53sc_unwind_exception::~sc_unwind_exception() throw() {}
54
55
56const char *
57sc_process_b::name()
58{
59 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
60 return "";
61}
62
63const char *
64sc_process_b::kind()
65{
66 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
67 return "";
68}
69
70
71sc_process_b *
72sc_get_curr_process_handle()
73{
74 warn("%s not implemented.\n", __PRETTY_FUNCTION__);
75 return nullptr;
76}
77
78
79sc_process_handle::sc_process_handle() : _gem5_process(nullptr) {}
80
81sc_process_handle::sc_process_handle(const sc_process_handle &handle) :
82 _gem5_process(handle._gem5_process)
83{
84 if (_gem5_process)
85 _gem5_process->incref();
86}
87
88sc_process_handle::sc_process_handle(sc_object *obj) :
89 _gem5_process(dynamic_cast<::sc_gem5::Process *>(obj))
90{
91 if (_gem5_process)
92 _gem5_process->incref();
93}
94
95sc_process_handle::~sc_process_handle()
96{
97 if (_gem5_process)
98 _gem5_process->decref();
99}
100
101
102bool
103sc_process_handle::valid() const
104{
105 return _gem5_process != nullptr;
106}
107
108
109sc_process_handle &
110sc_process_handle::operator = (const sc_process_handle &handle)
111{
112 if (_gem5_process)
113 _gem5_process->decref();
114 _gem5_process = handle._gem5_process;
115 if (_gem5_process)
116 _gem5_process->incref();
117 return *this;
118}
119
120bool
121sc_process_handle::operator == (const sc_process_handle &handle) const
122{
123 return _gem5_process && handle._gem5_process &&
124 (_gem5_process == handle._gem5_process);
125}
126
127bool
128sc_process_handle::operator != (const sc_process_handle &handle) const
129{
130 return !(handle == *this);
131}
132
133bool
134sc_process_handle::operator < (const sc_process_handle &other) const
135{
136 return _gem5_process < other._gem5_process;
137}
138
139void
140sc_process_handle::swap(sc_process_handle &handle)
141{
142 ::sc_gem5::Process *temp = handle._gem5_process;
143 handle._gem5_process = _gem5_process;
144 _gem5_process = temp;
145}
146
147
148const char *
149sc_process_handle::name() const
150{
151 return _gem5_process ? _gem5_process->name() : "";
152}
153
154sc_curr_proc_kind
155sc_process_handle::proc_kind() const
156{
157 return _gem5_process ? _gem5_process->procKind() : SC_NO_PROC_;
158}
159
160const std::vector<sc_object *> &
161sc_process_handle::get_child_objects() const
162{
163 static const std::vector<sc_object *> empty;
164 return _gem5_process ? _gem5_process->get_child_objects() : empty;
165}
166
167const std::vector<sc_event *> &
168sc_process_handle::get_child_events() const
169{
170 static const std::vector<sc_event *> empty;
171 return _gem5_process ? _gem5_process->get_child_events() : empty;
172}
173
174sc_object *
175sc_process_handle::get_parent_object() const
176{
177 return _gem5_process ? _gem5_process->get_parent_object() : nullptr;
178}
179
180sc_object *
181sc_process_handle::get_process_object() const
182{
183 return _gem5_process;
184}
185
186bool
187sc_process_handle::dynamic() const
188{
189 return _gem5_process ? _gem5_process->dynamic() : false;
190}
191
192bool
193sc_process_handle::terminated() const
194{
195 return _gem5_process ? _gem5_process->terminated() : false;
196}
197
198const sc_event &
199sc_process_handle::terminated_event() const
200{
201 static sc_event non_event;
202 return _gem5_process ? _gem5_process->terminatedEvent() : non_event;
203}
204
205
206void
207sc_process_handle::suspend(sc_descendent_inclusion_info include_descendants)
208{
209 if (!_gem5_process)
210 return;
211 _gem5_process->suspend(include_descendants == SC_INCLUDE_DESCENDANTS);
212}
213
214void
215sc_process_handle::resume(sc_descendent_inclusion_info include_descendants)
216{
217 if (!_gem5_process)
218 return;
219 _gem5_process->resume(include_descendants == SC_INCLUDE_DESCENDANTS);
220}
221
222void
223sc_process_handle::disable(sc_descendent_inclusion_info include_descendants)
224{
225 if (!_gem5_process)
226 return;
227 _gem5_process->disable(include_descendants == SC_INCLUDE_DESCENDANTS);
228}
229
230void
231sc_process_handle::enable(sc_descendent_inclusion_info include_descendants)
232{
233 if (!_gem5_process)
234 return;
235 _gem5_process->enable(include_descendants == SC_INCLUDE_DESCENDANTS);
236}
237
238void
239sc_process_handle::kill(sc_descendent_inclusion_info include_descendants)
240{
241 if (!_gem5_process)
242 return;
243 _gem5_process->kill(include_descendants == SC_INCLUDE_DESCENDANTS);
244}
245
246void
247sc_process_handle::reset(sc_descendent_inclusion_info include_descendants)
248{
249 if (!_gem5_process)
250 return;
251 _gem5_process->reset(include_descendants == SC_INCLUDE_DESCENDANTS);
252}
253
254bool
255sc_process_handle::is_unwinding()
256{
257 if (!_gem5_process) {
258 //TODO This should generate a systemc style warning if the handle is
259 //invalid.
260 return false;
261 } else {
262 return _gem5_process->isUnwinding();
263 }
264}
265
266const sc_event &
267sc_process_handle::reset_event() const
268{
269 static sc_event non_event;
270 return _gem5_process ? _gem5_process->resetEvent() : non_event;
271}
272
273
274void
275sc_process_handle::sync_reset_on(
276 sc_descendent_inclusion_info include_descendants)
277{
278 if (!_gem5_process)
279 return;
280 _gem5_process->syncResetOn(include_descendants == SC_INCLUDE_DESCENDANTS);
281}
282
283void
284sc_process_handle::sync_reset_off(
285 sc_descendent_inclusion_info include_descendants)
286{
287 if (!_gem5_process)
288 return;
289 _gem5_process->syncResetOff(include_descendants == SC_INCLUDE_DESCENDANTS);
290}
291
292
293sc_process_handle
294sc_get_current_process_handle()
295{
295 return sc_process_handle(::sc_gem5::scheduler.current());
296 if (sc_is_running())
297 return sc_process_handle(::sc_gem5::scheduler.current());
298 else
299 return sc_process_handle(::sc_gem5::Process::newest());
296}
297
298bool
299sc_is_unwinding()
300{
301 return sc_get_current_process_handle().is_unwinding();
302}
303
304bool sc_allow_process_control_corners;
305
306} // namespace sc_core
300}
301
302bool
303sc_is_unwinding()
304{
305 return sc_get_current_process_handle().is_unwinding();
306}
307
308bool sc_allow_process_control_corners;
309
310} // namespace sc_core