2 * Copyright 2018 Google, Inc.
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.
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.
30 #ifndef __SYSTEMC_EXT_CORE_SC_PROCESS_HANDLE_HH__
31 #define __SYSTEMC_EXT_CORE_SC_PROCESS_HANDLE_HH__
36 #include "systemc/ext/core/sc_object.hh"
43 struct ProcessFuncWrapper
45 virtual void call() = 0;
46 virtual ~ProcessFuncWrapper() {}
50 struct ProcessMemberFuncWrapper : public ProcessFuncWrapper
52 typedef void (T::*TFunc)();
56 ProcessMemberFuncWrapper(T *t, TFunc func) : t(t), func(func) {}
58 void call() override { (t->*func)(); }
61 struct ExceptionWrapperBase
63 virtual void throw_it() = 0;
67 struct ExceptionWrapper : public ExceptionWrapperBase
70 ExceptionWrapper(const T &t) : t(t) {}
72 void throw_it() { throw t; }
75 void throw_it_wrapper(Process *p, ExceptionWrapperBase &exc, bool inc_kids);
77 } // namespace sc_gem5
84 enum sc_curr_proc_kind
92 enum sc_descendent_inclusion_info
95 SC_INCLUDE_DESCENDANTS
98 class sc_unwind_exception : public std::exception
101 virtual const char *what() const throw();
102 virtual bool is_reset() const;
105 // These should be protected, but I think this is to enable catch by
108 sc_unwind_exception(const sc_unwind_exception &);
109 virtual ~sc_unwind_exception() throw();
113 sc_unwind_exception();
117 // An incomplete version of sc_process_b to satisfy the tests.
118 class sc_process_b : public sc_object
121 sc_process_b(const char *name) : sc_object(name), file(nullptr), lineno(0)
123 sc_process_b() : sc_object(), file(nullptr), lineno(0) {}
130 void sc_set_location(const char *file, int lineno);
133 sc_process_b *sc_get_curr_process_handle();
134 static inline sc_process_b *
135 sc_get_current_process_b()
137 return sc_get_curr_process_handle();
140 // Deprecated/nonstandard
141 struct sc_curr_proc_info
143 sc_process_b *process_handle;
144 sc_curr_proc_kind kind;
145 sc_curr_proc_info() : process_handle(NULL), kind(SC_NO_PROC_) {}
147 typedef const sc_curr_proc_info *sc_curr_proc_handle;
149 class sc_process_handle
152 ::sc_gem5::Process *_gem5_process;
156 sc_process_handle(const sc_process_handle &);
157 explicit sc_process_handle(sc_object *);
158 ~sc_process_handle();
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; }
165 operator = (::sc_gem5::Process *p)
173 sc_process_handle &operator = (const sc_process_handle &);
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 &);
179 const char *name() const;
180 sc_curr_proc_kind proc_kind() const;
181 const std::vector<sc_object *> &get_child_objects() const;
182 const std::vector<sc_event *> &get_child_events() 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;
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=
202 const sc_event &reset_event() const;
204 void sync_reset_on(sc_descendent_inclusion_info include_descendants=
206 void sync_reset_off(sc_descendent_inclusion_info include_descendants=
209 template <typename T>
211 throw_it(const T &user_defined_exception,
212 sc_descendent_inclusion_info include_descendants=
215 ::sc_gem5::ExceptionWrapper<T> exc(user_defined_exception);
216 ::sc_gem5::throw_it_wrapper(_gem5_process, exc,
217 include_descendants == SC_INCLUDE_DESCENDANTS);
221 sc_process_handle sc_get_current_process_handle();
222 bool sc_is_unwinding();
225 // See Accellera's kernel/sim_context.cpp for an explanation of what this is
226 // supposed to do. It essentially selects what happens during certain
227 // undefined situations.
228 extern bool sc_allow_process_control_corners;
230 } // namespace sc_core
232 #endif //__SYSTEMC_EXT_CORE_SC_PROCESS_HANDLE_HH__