sc_process_handle.cc revision 13317:36c574a4036e
112027Sjungma@eit.uni-kl.de/*
212027Sjungma@eit.uni-kl.de * Copyright 2018 Google, Inc.
312027Sjungma@eit.uni-kl.de *
412027Sjungma@eit.uni-kl.de * Redistribution and use in source and binary forms, with or without
512027Sjungma@eit.uni-kl.de * modification, are permitted provided that the following conditions are
612027Sjungma@eit.uni-kl.de * met: redistributions of source code must retain the above copyright
712027Sjungma@eit.uni-kl.de * notice, this list of conditions and the following disclaimer;
812027Sjungma@eit.uni-kl.de * redistributions in binary form must reproduce the above copyright
912027Sjungma@eit.uni-kl.de * notice, this list of conditions and the following disclaimer in the
1012027Sjungma@eit.uni-kl.de * documentation and/or other materials provided with the distribution;
1112027Sjungma@eit.uni-kl.de * neither the name of the copyright holders nor the names of its
1212027Sjungma@eit.uni-kl.de * contributors may be used to endorse or promote products derived from
1312027Sjungma@eit.uni-kl.de * this software without specific prior written permission.
1412027Sjungma@eit.uni-kl.de *
1512027Sjungma@eit.uni-kl.de * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1612027Sjungma@eit.uni-kl.de * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1712027Sjungma@eit.uni-kl.de * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1812027Sjungma@eit.uni-kl.de * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1912027Sjungma@eit.uni-kl.de * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2012027Sjungma@eit.uni-kl.de * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2112027Sjungma@eit.uni-kl.de * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2212027Sjungma@eit.uni-kl.de * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2312027Sjungma@eit.uni-kl.de * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2412027Sjungma@eit.uni-kl.de * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2512027Sjungma@eit.uni-kl.de * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2612027Sjungma@eit.uni-kl.de *
2712027Sjungma@eit.uni-kl.de * Authors: Gabe Black
2812027Sjungma@eit.uni-kl.de */
2912027Sjungma@eit.uni-kl.de
3012027Sjungma@eit.uni-kl.de#include "base/logging.hh"
3112027Sjungma@eit.uni-kl.de#include "systemc/core/process.hh"
3212027Sjungma@eit.uni-kl.de#include "systemc/core/scheduler.hh"
3312027Sjungma@eit.uni-kl.de#include "systemc/ext/core/messages.hh"
3412027Sjungma@eit.uni-kl.de#include "systemc/ext/core/sc_main.hh"
3512027Sjungma@eit.uni-kl.de#include "systemc/ext/core/sc_process_handle.hh"
3612027Sjungma@eit.uni-kl.de#include "systemc/ext/utils/sc_report_handler.hh"
3712027Sjungma@eit.uni-kl.de
3812027Sjungma@eit.uni-kl.denamespace sc_core
3912027Sjungma@eit.uni-kl.de{
4012027Sjungma@eit.uni-kl.de
4112027Sjungma@eit.uni-kl.deconst char *
4212027Sjungma@eit.uni-kl.desc_unwind_exception::what() const throw()
4312027Sjungma@eit.uni-kl.de{
4412027Sjungma@eit.uni-kl.de    return _isReset ? "RESET" : "KILL";
4512027Sjungma@eit.uni-kl.de}
4612027Sjungma@eit.uni-kl.de
4712027Sjungma@eit.uni-kl.debool
4812027Sjungma@eit.uni-kl.desc_unwind_exception::is_reset() const
4912027Sjungma@eit.uni-kl.de{
5012027Sjungma@eit.uni-kl.de    return _isReset;
5112027Sjungma@eit.uni-kl.de}
5212027Sjungma@eit.uni-kl.de
5312027Sjungma@eit.uni-kl.desc_unwind_exception::sc_unwind_exception() : _isReset(false) {}
5412027Sjungma@eit.uni-kl.desc_unwind_exception::sc_unwind_exception(const sc_unwind_exception &e) :
5512027Sjungma@eit.uni-kl.de    _isReset(e._isReset)
5612027Sjungma@eit.uni-kl.de{}
5712027Sjungma@eit.uni-kl.desc_unwind_exception::~sc_unwind_exception() throw() {}
5812027Sjungma@eit.uni-kl.de
5912027Sjungma@eit.uni-kl.de
6012027Sjungma@eit.uni-kl.devoid
6112027Sjungma@eit.uni-kl.desc_set_location(const char *file, int lineno)
6212027Sjungma@eit.uni-kl.de{
6312027Sjungma@eit.uni-kl.de    sc_process_b *current = ::sc_gem5::scheduler.current();
6412027Sjungma@eit.uni-kl.de    if (!current)
6512027Sjungma@eit.uni-kl.de        return;
6612027Sjungma@eit.uni-kl.de    current->file = file;
6712027Sjungma@eit.uni-kl.de    current->lineno = lineno;
6812027Sjungma@eit.uni-kl.de}
6912027Sjungma@eit.uni-kl.de
7012027Sjungma@eit.uni-kl.de
7112027Sjungma@eit.uni-kl.desc_process_b *
7212027Sjungma@eit.uni-kl.desc_get_curr_process_handle()
7312027Sjungma@eit.uni-kl.de{
7412027Sjungma@eit.uni-kl.de    return ::sc_gem5::scheduler.current();
7512027Sjungma@eit.uni-kl.de}
7612027Sjungma@eit.uni-kl.de
7712027Sjungma@eit.uni-kl.de
7812027Sjungma@eit.uni-kl.desc_process_handle::sc_process_handle() : _gem5_process(nullptr) {}
7912027Sjungma@eit.uni-kl.de
8012027Sjungma@eit.uni-kl.desc_process_handle::sc_process_handle(const sc_process_handle &handle) :
8112027Sjungma@eit.uni-kl.de    _gem5_process(handle._gem5_process)
8212027Sjungma@eit.uni-kl.de{
8312027Sjungma@eit.uni-kl.de    if (_gem5_process)
8412027Sjungma@eit.uni-kl.de        _gem5_process->incref();
8512027Sjungma@eit.uni-kl.de}
8612027Sjungma@eit.uni-kl.de
8712027Sjungma@eit.uni-kl.desc_process_handle::sc_process_handle(sc_object *obj) :
8812027Sjungma@eit.uni-kl.de    _gem5_process(dynamic_cast<::sc_gem5::Process *>(obj))
8912027Sjungma@eit.uni-kl.de{
9012027Sjungma@eit.uni-kl.de    if (_gem5_process)
9112027Sjungma@eit.uni-kl.de        _gem5_process->incref();
9212027Sjungma@eit.uni-kl.de}
9312027Sjungma@eit.uni-kl.de
9412027Sjungma@eit.uni-kl.desc_process_handle::~sc_process_handle()
9512027Sjungma@eit.uni-kl.de{
9612027Sjungma@eit.uni-kl.de    if (_gem5_process)
9712027Sjungma@eit.uni-kl.de        _gem5_process->decref();
9812027Sjungma@eit.uni-kl.de}
9912027Sjungma@eit.uni-kl.de
10012027Sjungma@eit.uni-kl.de
10112027Sjungma@eit.uni-kl.debool
10212027Sjungma@eit.uni-kl.desc_process_handle::valid() const
10312027Sjungma@eit.uni-kl.de{
10412027Sjungma@eit.uni-kl.de    return _gem5_process != nullptr;
10512027Sjungma@eit.uni-kl.de}
10612027Sjungma@eit.uni-kl.de
10712027Sjungma@eit.uni-kl.de
10812027Sjungma@eit.uni-kl.desc_process_handle &
10912027Sjungma@eit.uni-kl.desc_process_handle::operator = (const sc_process_handle &handle)
11012027Sjungma@eit.uni-kl.de{
11112027Sjungma@eit.uni-kl.de    if (_gem5_process)
11212027Sjungma@eit.uni-kl.de        _gem5_process->decref();
11312027Sjungma@eit.uni-kl.de    _gem5_process = handle._gem5_process;
11412027Sjungma@eit.uni-kl.de    if (_gem5_process)
11512027Sjungma@eit.uni-kl.de        _gem5_process->incref();
11612027Sjungma@eit.uni-kl.de    return *this;
11712027Sjungma@eit.uni-kl.de}
11812027Sjungma@eit.uni-kl.de
11912027Sjungma@eit.uni-kl.debool
12012027Sjungma@eit.uni-kl.desc_process_handle::operator == (const sc_process_handle &handle) const
12112027Sjungma@eit.uni-kl.de{
12212027Sjungma@eit.uni-kl.de    return _gem5_process && handle._gem5_process &&
12312027Sjungma@eit.uni-kl.de        (_gem5_process == handle._gem5_process);
12412027Sjungma@eit.uni-kl.de}
12512027Sjungma@eit.uni-kl.de
12612027Sjungma@eit.uni-kl.debool
12712027Sjungma@eit.uni-kl.desc_process_handle::operator != (const sc_process_handle &handle) const
12812027Sjungma@eit.uni-kl.de{
12912027Sjungma@eit.uni-kl.de    return !(handle == *this);
13012027Sjungma@eit.uni-kl.de}
13112027Sjungma@eit.uni-kl.de
13212027Sjungma@eit.uni-kl.debool
13312027Sjungma@eit.uni-kl.desc_process_handle::operator < (const sc_process_handle &other) const
13412027Sjungma@eit.uni-kl.de{
13512027Sjungma@eit.uni-kl.de    return _gem5_process < other._gem5_process;
13612027Sjungma@eit.uni-kl.de}
13712027Sjungma@eit.uni-kl.de
13812027Sjungma@eit.uni-kl.devoid
13912027Sjungma@eit.uni-kl.desc_process_handle::swap(sc_process_handle &handle)
14012027Sjungma@eit.uni-kl.de{
14112027Sjungma@eit.uni-kl.de    ::sc_gem5::Process *temp = handle._gem5_process;
14212027Sjungma@eit.uni-kl.de    handle._gem5_process = _gem5_process;
14312027Sjungma@eit.uni-kl.de    _gem5_process = temp;
14412027Sjungma@eit.uni-kl.de}
14512027Sjungma@eit.uni-kl.de
14612027Sjungma@eit.uni-kl.de
14712027Sjungma@eit.uni-kl.deconst char *
14812027Sjungma@eit.uni-kl.desc_process_handle::name() const
14912027Sjungma@eit.uni-kl.de{
15012027Sjungma@eit.uni-kl.de    return _gem5_process ? _gem5_process->name() : "";
15112027Sjungma@eit.uni-kl.de}
15212027Sjungma@eit.uni-kl.de
15312027Sjungma@eit.uni-kl.desc_curr_proc_kind
15412027Sjungma@eit.uni-kl.desc_process_handle::proc_kind() const
15512027Sjungma@eit.uni-kl.de{
15612027Sjungma@eit.uni-kl.de    return _gem5_process ? _gem5_process->procKind() : SC_NO_PROC_;
15712027Sjungma@eit.uni-kl.de}
15812027Sjungma@eit.uni-kl.de
15912027Sjungma@eit.uni-kl.deconst std::vector<sc_object *> &
16012027Sjungma@eit.uni-kl.desc_process_handle::get_child_objects() const
16112027Sjungma@eit.uni-kl.de{
16212027Sjungma@eit.uni-kl.de    static const std::vector<sc_object *> empty;
16312027Sjungma@eit.uni-kl.de    return _gem5_process ? _gem5_process->get_child_objects() : empty;
16412027Sjungma@eit.uni-kl.de}
16512027Sjungma@eit.uni-kl.de
16612027Sjungma@eit.uni-kl.deconst std::vector<sc_event *> &
16712027Sjungma@eit.uni-kl.desc_process_handle::get_child_events() const
16812027Sjungma@eit.uni-kl.de{
16912027Sjungma@eit.uni-kl.de    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    if (!_gem5_process) {
201        SC_REPORT_WARNING(SC_ID_EMPTY_PROCESS_HANDLE_, "terminated_event()");
202        static sc_gem5::InternalScEvent non_event;
203        return non_event;
204    }
205    return _gem5_process->terminatedEvent();
206}
207
208
209void
210sc_process_handle::suspend(sc_descendent_inclusion_info include_descendants)
211{
212    if (!_gem5_process) {
213        SC_REPORT_WARNING(SC_ID_EMPTY_PROCESS_HANDLE_, "suspend()");
214        return;
215    }
216    _gem5_process->suspend(include_descendants == SC_INCLUDE_DESCENDANTS);
217}
218
219void
220sc_process_handle::resume(sc_descendent_inclusion_info include_descendants)
221{
222    if (!_gem5_process) {
223        SC_REPORT_WARNING(SC_ID_EMPTY_PROCESS_HANDLE_, "resume()");
224        return;
225    }
226    _gem5_process->resume(include_descendants == SC_INCLUDE_DESCENDANTS);
227}
228
229void
230sc_process_handle::disable(sc_descendent_inclusion_info include_descendants)
231{
232    if (!_gem5_process) {
233        SC_REPORT_WARNING(SC_ID_EMPTY_PROCESS_HANDLE_, "disable()");
234        return;
235    }
236    _gem5_process->disable(include_descendants == SC_INCLUDE_DESCENDANTS);
237}
238
239void
240sc_process_handle::enable(sc_descendent_inclusion_info include_descendants)
241{
242    if (!_gem5_process) {
243        SC_REPORT_WARNING(SC_ID_EMPTY_PROCESS_HANDLE_, "enable()");
244        return;
245    }
246    _gem5_process->enable(include_descendants == SC_INCLUDE_DESCENDANTS);
247}
248
249void
250sc_process_handle::kill(sc_descendent_inclusion_info include_descendants)
251{
252    if (!_gem5_process) {
253        SC_REPORT_WARNING(SC_ID_EMPTY_PROCESS_HANDLE_, "kill()");
254        return;
255    }
256    _gem5_process->kill(include_descendants == SC_INCLUDE_DESCENDANTS);
257}
258
259void
260sc_process_handle::reset(sc_descendent_inclusion_info include_descendants)
261{
262    if (!_gem5_process) {
263        SC_REPORT_WARNING(SC_ID_EMPTY_PROCESS_HANDLE_, "reset()");
264        return;
265    }
266    _gem5_process->reset(include_descendants == SC_INCLUDE_DESCENDANTS);
267}
268
269bool
270sc_process_handle::is_unwinding()
271{
272    if (!_gem5_process) {
273        SC_REPORT_WARNING(SC_ID_EMPTY_PROCESS_HANDLE_, "is_unwinding()");
274        return false;
275    }
276    return _gem5_process->isUnwinding();
277}
278
279const sc_event &
280sc_process_handle::reset_event() const
281{
282    if (!_gem5_process) {
283        SC_REPORT_WARNING(SC_ID_EMPTY_PROCESS_HANDLE_, "reset()");
284        static sc_gem5::InternalScEvent non_event;
285        return non_event;
286    }
287    return _gem5_process->resetEvent();
288}
289
290
291void
292sc_process_handle::sync_reset_on(
293        sc_descendent_inclusion_info include_descendants)
294{
295    if (!_gem5_process) {
296        SC_REPORT_WARNING(SC_ID_EMPTY_PROCESS_HANDLE_, "sync_reset_on()");
297        return;
298    }
299    _gem5_process->syncResetOn(include_descendants == SC_INCLUDE_DESCENDANTS);
300}
301
302void
303sc_process_handle::sync_reset_off(
304        sc_descendent_inclusion_info include_descendants)
305{
306    if (!_gem5_process) {
307        SC_REPORT_WARNING(SC_ID_EMPTY_PROCESS_HANDLE_, "sync_reset_off()");
308        return;
309    }
310    _gem5_process->syncResetOff(include_descendants == SC_INCLUDE_DESCENDANTS);
311}
312
313
314sc_process_handle
315sc_get_current_process_handle()
316{
317    if (sc_is_running())
318        return sc_process_handle(::sc_gem5::scheduler.current());
319    else
320        return sc_process_handle(::sc_gem5::Process::newest());
321}
322
323bool
324sc_is_unwinding()
325{
326    return sc_get_current_process_handle().is_unwinding();
327}
328
329bool sc_allow_process_control_corners;
330
331} // namespace sc_core
332