gem5  v20.1.0.0
sc_process_handle.hh
Go to the documentation of this file.
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 
28 #ifndef __SYSTEMC_EXT_CORE_SC_PROCESS_HANDLE_HH__
29 #define __SYSTEMC_EXT_CORE_SC_PROCESS_HANDLE_HH__
30 
31 #include <exception>
32 #include <vector>
33 
34 #include "../utils/sc_report_handler.hh"
35 #include "messages.hh"
36 #include "sc_object.hh"
37 
38 namespace sc_gem5
39 {
40 
41 class Process;
42 
44 {
45  virtual void call() = 0;
46  virtual ~ProcessFuncWrapper() {}
47 };
48 
49 template <typename T>
51 {
52  typedef void (T::*TFunc)();
53  T *t;
55 
57 
58  void call() override { (t->*func)(); }
59 };
60 
62 {
63  virtual void throw_it() = 0;
64 };
65 
66 template <typename T>
68 {
69  const T &t;
70  ExceptionWrapper(const T &t) : t(t) {}
71 
72  void throw_it() { throw t; }
73 };
74 
75 void throw_it_wrapper(Process *p, ExceptionWrapperBase &exc, bool inc_kids);
76 
77 } // namespace sc_gem5
78 
79 namespace sc_core
80 {
81 
82 class sc_event;
83 
85 {
90 };
91 
93 {
96 };
97 
98 class sc_unwind_exception : public std::exception
99 {
100  public:
101  virtual const char *what() const throw();
102  virtual bool is_reset() const;
103 
104  // Nonstandard.
105  // These should be protected, but I think this is to enable catch by
106  // value.
107  public:
109  virtual ~sc_unwind_exception() throw();
110 
111  protected:
112  bool _isReset;
114 };
115 
116 // Deprecated
117 // An incomplete version of sc_process_b to satisfy the tests.
118 class sc_process_b : public sc_object
119 {
120  public:
121  sc_process_b(const char *name) : sc_object(name), file(nullptr), lineno(0)
122  {}
123  sc_process_b() : sc_object(), file(nullptr), lineno(0) {}
124 
125  const char *file;
126  int lineno;
127 };
128 
129 // Nonstandard
130 void sc_set_location(const char *file, int lineno);
131 
132 // Deprecated
134 static inline sc_process_b *
136 {
138 }
139 
140 // Deprecated/nonstandard
142 {
146 };
148 
150 {
151  private:
153 
154  public:
157  explicit sc_process_handle(sc_object *);
159 
160  // These non-standard operators provide access to the data structure which
161  // actually tracks the process within gem5. By making them operators, we
162  // can minimize the symbols added to the class namespace.
163  operator ::sc_gem5::Process * () const { return _gem5_process; }
166  {
167  _gem5_process = p;
168  return *this;
169  }
170 
171  bool valid() const;
172 
174  bool operator == (const sc_process_handle &) const;
175  bool operator != (const sc_process_handle &) const;
176  bool operator < (const sc_process_handle &) const;
177  void swap(sc_process_handle &);
178 
179  const char *name() const;
183  sc_object *get_parent_object() const;
184  sc_object *get_process_object() const;
185  bool dynamic() const;
186  bool terminated() const;
187  const sc_event &terminated_event() const;
188 
189  void suspend(sc_descendent_inclusion_info include_descendants=
191  void resume(sc_descendent_inclusion_info include_descendants=
193  void disable(sc_descendent_inclusion_info include_descendants=
195  void enable(sc_descendent_inclusion_info include_descendants=
197  void kill(sc_descendent_inclusion_info include_descendants=
199  void reset(sc_descendent_inclusion_info include_descendants=
201  bool is_unwinding();
202  const sc_event &reset_event() const;
203 
204  void sync_reset_on(sc_descendent_inclusion_info include_descendants=
206  void sync_reset_off(sc_descendent_inclusion_info include_descendants=
208 
209  template <typename T>
210  void
211  throw_it(const T &user_defined_exception,
212  sc_descendent_inclusion_info include_descendants=
214  {
215  if (!_gem5_process) {
217  return;
218  }
219  ::sc_gem5::ExceptionWrapper<T> exc(user_defined_exception);
221  include_descendants == SC_INCLUDE_DESCENDANTS);
222  }
223 };
224 
225 sc_process_handle sc_get_current_process_handle();
226 bool sc_is_unwinding();
227 
228 // Nonstandard
229 // See Accellera's kernel/sim_context.cpp for an explanation of what this is
230 // supposed to do. It essentially selects what happens during certain
231 // undefined situations.
233 
234 } // namespace sc_core
235 
236 #endif //__SYSTEMC_EXT_CORE_SC_PROCESS_HANDLE_HH__
sc_core::sc_process_handle::operator=
sc_process_handle & operator=(::sc_gem5::Process *p)
Definition: sc_process_handle.hh:165
sc_core::sc_process_handle::sc_process_handle
sc_process_handle()
Definition: sc_process_handle.cc:75
sc_core::SC_THREAD_PROC_
@ SC_THREAD_PROC_
Definition: sc_process_handle.hh:88
sc_core::sc_process_handle::is_unwinding
bool is_unwinding()
Definition: sc_process_handle.cc:267
sc_core::sc_process_handle::sync_reset_on
void sync_reset_on(sc_descendent_inclusion_info include_descendants=SC_NO_DESCENDANTS)
Definition: sc_process_handle.cc:289
sc_gem5::ProcessFuncWrapper
Definition: sc_process_handle.hh:43
sc_gem5::ProcessMemberFuncWrapper::t
T * t
Definition: sc_process_handle.hh:53
Process
Definition: process.hh:65
sc_core::sc_unwind_exception::~sc_unwind_exception
virtual ~sc_unwind_exception()
Definition: sc_process_handle.cc:54
sc_core::sc_process_handle::swap
void swap(sc_process_handle &)
Definition: sc_process_handle.cc:136
sc_core
Definition: messages.cc:31
sc_gem5::ProcessMemberFuncWrapper
Definition: sc_process_handle.hh:50
sc_core::sc_unwind_exception::_isReset
bool _isReset
Definition: sc_process_handle.hh:112
sc_core::sc_get_current_process_b
static sc_process_b * sc_get_current_process_b()
Definition: sc_process_handle.hh:135
sc_core::sc_process_handle::kill
void kill(sc_descendent_inclusion_info include_descendants=SC_NO_DESCENDANTS)
Definition: sc_process_handle.cc:247
std::vector
STL vector class.
Definition: stl.hh:37
sc_core::sc_process_handle::throw_it
void throw_it(const T &user_defined_exception, sc_descendent_inclusion_info include_descendants=SC_NO_DESCENDANTS)
Definition: sc_process_handle.hh:211
sc_core::sc_process_handle::get_child_objects
const std::vector< sc_object * > & get_child_objects() const
Definition: sc_process_handle.cc:157
sc_core::sc_process_handle::dynamic
bool dynamic() const
Definition: sc_process_handle.cc:183
sc_core::sc_process_handle::suspend
void suspend(sc_descendent_inclusion_info include_descendants=SC_NO_DESCENDANTS)
Definition: sc_process_handle.cc:207
sc_core::SC_NO_PROC_
@ SC_NO_PROC_
Definition: sc_process_handle.hh:86
sc_core::sc_unwind_exception::sc_unwind_exception
sc_unwind_exception()
Definition: sc_process_handle.cc:50
sc_core::sc_curr_proc_info
Definition: sc_process_handle.hh:141
sc_core::sc_process_handle::operator==
bool operator==(const sc_process_handle &) const
Definition: sc_process_handle.cc:117
sc_core::SC_CTHREAD_PROC_
@ SC_CTHREAD_PROC_
Definition: sc_process_handle.hh:89
sc_gem5::ProcessMemberFuncWrapper::TFunc
void(T::* TFunc)()
Definition: sc_process_handle.hh:52
sc_gem5::ExceptionWrapper
Definition: sc_process_handle.hh:67
sc_core::sc_process_b::lineno
int lineno
Definition: sc_process_handle.hh:126
sc_core::sc_process_handle::reset
void reset(sc_descendent_inclusion_info include_descendants=SC_NO_DESCENDANTS)
Definition: sc_process_handle.cc:257
sc_core::sc_process_handle::get_parent_object
sc_object * get_parent_object() const
Definition: sc_process_handle.cc:171
sc_core::sc_process_handle::operator!=
bool operator!=(const sc_process_handle &) const
Definition: sc_process_handle.cc:124
sc_core::sc_process_handle::reset_event
const sc_event & reset_event() const
Definition: sc_process_handle.cc:277
sc_core::sc_process_handle::sync_reset_off
void sync_reset_off(sc_descendent_inclusion_info include_descendants=SC_NO_DESCENDANTS)
Definition: sc_process_handle.cc:300
sc_core::sc_set_location
void sc_set_location(const char *file, int lineno)
Definition: sc_process_handle.cc:58
sc_core::sc_process_b
Definition: sc_process_handle.hh:118
sc_core::sc_process_handle::disable
void disable(sc_descendent_inclusion_info include_descendants=SC_NO_DESCENDANTS)
Definition: sc_process_handle.cc:227
sc_core::sc_event
Definition: sc_event.hh:169
sc_core::sc_unwind_exception
Definition: sc_process_handle.hh:98
sc_gem5::ExceptionWrapperBase
Definition: sc_process_handle.hh:61
sc_core::sc_unwind_exception::what
virtual const char * what() const
Definition: sc_process_handle.cc:39
sc_core::SC_METHOD_PROC_
@ SC_METHOD_PROC_
Definition: sc_process_handle.hh:87
sc_core::sc_curr_proc_info::sc_curr_proc_info
sc_curr_proc_info()
Definition: sc_process_handle.hh:145
sc_core::sc_process_handle::operator<
bool operator<(const sc_process_handle &) const
Definition: sc_process_handle.cc:130
sc_core::sc_process_handle::get_child_events
const std::vector< sc_event * > & get_child_events() const
Definition: sc_process_handle.cc:164
messages.hh
sc_core::sc_curr_proc_handle
const typedef sc_curr_proc_info * sc_curr_proc_handle
Definition: sc_process_handle.hh:147
sc_core::sc_descendent_inclusion_info
sc_descendent_inclusion_info
Definition: sc_process_handle.hh:92
sc_core::sc_process_handle::get_process_object
sc_object * get_process_object() const
Definition: sc_process_handle.cc:177
sc_gem5::ProcessMemberFuncWrapper::func
TFunc func
Definition: sc_process_handle.hh:54
sc_gem5::ExceptionWrapper::t
const T & t
Definition: sc_process_handle.hh:69
sc_gem5::Process
Definition: process.hh:62
sc_core::sc_object
Definition: sc_object.hh:50
sc_core::sc_curr_proc_info::process_handle
sc_process_b * process_handle
Definition: sc_process_handle.hh:143
sc_core::sc_process_handle::resume
void resume(sc_descendent_inclusion_info include_descendants=SC_NO_DESCENDANTS)
Definition: sc_process_handle.cc:217
sc_core::sc_process_handle::proc_kind
sc_curr_proc_kind proc_kind() const
Definition: sc_process_handle.cc:151
sc_core::sc_process_handle::enable
void enable(sc_descendent_inclusion_info include_descendants=SC_NO_DESCENDANTS)
Definition: sc_process_handle.cc:237
sc_core::SC_INCLUDE_DESCENDANTS
@ SC_INCLUDE_DESCENDANTS
Definition: sc_process_handle.hh:95
sc_core::SC_NO_DESCENDANTS
@ SC_NO_DESCENDANTS
Definition: sc_process_handle.hh:94
SC_REPORT_WARNING
#define SC_REPORT_WARNING(msg_type, msg)
Definition: sc_report_handler.hh:123
sc_gem5::ExceptionWrapper::ExceptionWrapper
ExceptionWrapper(const T &t)
Definition: sc_process_handle.hh:70
sc_core::sc_process_handle::~sc_process_handle
~sc_process_handle()
Definition: sc_process_handle.cc:91
sc_core::sc_process_handle::terminated
bool terminated() const
Definition: sc_process_handle.cc:189
sc_core::sc_get_curr_process_handle
sc_process_b * sc_get_curr_process_handle()
Definition: sc_process_handle.cc:69
sc_gem5::ExceptionWrapper::throw_it
void throw_it()
Definition: sc_process_handle.hh:72
sc_core::sc_is_unwinding
bool sc_is_unwinding()
Definition: sc_process_handle.cc:321
sc_core::sc_process_b::file
const char * file
Definition: sc_process_handle.hh:125
sc_gem5::ExceptionWrapperBase::throw_it
virtual void throw_it()=0
sc_core::sc_process_handle
Definition: sc_process_handle.hh:149
sc_gem5::ProcessMemberFuncWrapper::ProcessMemberFuncWrapper
ProcessMemberFuncWrapper(T *t, TFunc func)
Definition: sc_process_handle.hh:56
sc_core::sc_process_handle::valid
bool valid() const
Definition: sc_process_handle.cc:99
sc_core::sc_object::name
const char * name() const
Definition: sc_object.cc:44
sc_gem5::throw_it_wrapper
void throw_it_wrapper(Process *p, ExceptionWrapperBase &exc, bool inc_kids)
Definition: process.cc:419
sc_object.hh
sc_core::sc_process_b::sc_process_b
sc_process_b(const char *name)
Definition: sc_process_handle.hh:121
sc_core::sc_process_b::sc_process_b
sc_process_b()
Definition: sc_process_handle.hh:123
sc_gem5
Definition: sc_clock.cc:42
sc_core::sc_allow_process_control_corners
bool sc_allow_process_control_corners
Definition: sc_process_handle.cc:326
sc_gem5::ProcessMemberFuncWrapper::call
void call() override
Definition: sc_process_handle.hh:58
sc_core::sc_process_handle::terminated_event
const sc_event & terminated_event() const
Definition: sc_process_handle.cc:195
sc_core::SC_ID_EMPTY_PROCESS_HANDLE_
const char SC_ID_EMPTY_PROCESS_HANDLE_[]
Definition: messages.cc:154
sc_gem5::ProcessFuncWrapper::~ProcessFuncWrapper
virtual ~ProcessFuncWrapper()
Definition: sc_process_handle.hh:46
sc_core::sc_unwind_exception::is_reset
virtual bool is_reset() const
Definition: sc_process_handle.cc:45
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
sc_core::sc_curr_proc_info::kind
sc_curr_proc_kind kind
Definition: sc_process_handle.hh:144
sc_core::sc_process_handle::name
const char * name() const
Definition: sc_process_handle.cc:145
sc_core::sc_get_current_process_handle
sc_process_handle sc_get_current_process_handle()
Definition: sc_process_handle.cc:312
sc_gem5::ProcessFuncWrapper::call
virtual void call()=0
sc_core::sc_curr_proc_kind
sc_curr_proc_kind
Definition: sc_process_handle.hh:84
sc_core::sc_process_handle::_gem5_process
::sc_gem5::Process * _gem5_process
Definition: sc_process_handle.hh:152

Generated on Wed Sep 30 2020 14:02:15 for gem5 by doxygen 1.8.17