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