sc_process_handle.cc revision 13317
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/messages.hh" 34#include "systemc/ext/core/sc_main.hh" 35#include "systemc/ext/core/sc_process_handle.hh" 36#include "systemc/ext/utils/sc_report_handler.hh" 37 38namespace sc_core 39{ 40 41const char * 42sc_unwind_exception::what() const throw() 43{ 44 return _isReset ? "RESET" : "KILL"; 45} 46 47bool 48sc_unwind_exception::is_reset() const 49{ 50 return _isReset; 51} 52 53sc_unwind_exception::sc_unwind_exception() : _isReset(false) {} 54sc_unwind_exception::sc_unwind_exception(const sc_unwind_exception &e) : 55 _isReset(e._isReset) 56{} 57sc_unwind_exception::~sc_unwind_exception() throw() {} 58 59 60void 61sc_set_location(const char *file, int lineno) 62{ 63 sc_process_b *current = ::sc_gem5::scheduler.current(); 64 if (!current) 65 return; 66 current->file = file; 67 current->lineno = lineno; 68} 69 70 71sc_process_b * 72sc_get_curr_process_handle() 73{ 74 return ::sc_gem5::scheduler.current(); 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 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