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_SPAWN_HH__ 31#define __SYSTEMC_EXT_CORE_SC_SPAWN_HH__ 32 33#include <vector> 34
| 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_SPAWN_HH__ 31#define __SYSTEMC_EXT_CORE_SC_SPAWN_HH__ 32 33#include <vector> 34
|
| 35#include "sc_join.hh"
|
35#include "sc_process_handle.hh" 36 37namespace sc_core 38{ 39 40class sc_spawn_options; 41 42} // namespace sc_core 43 44namespace sc_gem5 45{ 46 47class Process; 48 49template <typename T> 50struct ProcessObjFuncWrapper : public ProcessFuncWrapper 51{ 52 T t; 53 54 ProcessObjFuncWrapper(T t) : t(t) {} 55 56 void call() override { t(); } 57}; 58 59template <typename T, typename R> 60struct ProcessObjRetFuncWrapper : public ProcessFuncWrapper 61{ 62 T t; 63 R *r; 64 65 ProcessObjRetFuncWrapper(T t, R *r) : t(t), r(r) {} 66 67 void call() override { *r = t(); } 68}; 69 70Process *spawnWork(ProcessFuncWrapper *func, const char *name, 71 const ::sc_core::sc_spawn_options *); 72 73} // namespace sc_gem5 74 75namespace sc_core 76{ 77 78template <class T> 79class sc_in; 80template <class T> 81class sc_inout; 82template <class T> 83class sc_out; 84template <class T> 85class sc_signal_in_if; 86 87class sc_event; 88class sc_event_finder; 89class sc_export_base; 90class sc_interface; 91class sc_port_base; 92 93class sc_spawn_options 94{ 95 public: 96 friend ::sc_gem5::Process *::sc_gem5::spawnWork( 97 ::sc_gem5::ProcessFuncWrapper *, const char *, 98 const sc_spawn_options *); 99 100 sc_spawn_options(); 101 102 void spawn_method(); 103 void dont_initialize(); 104 void set_stack_size(int); 105 106 void set_sensitivity(const sc_event *); 107 void set_sensitivity(sc_port_base *); 108 void set_sensitivity(sc_export_base *); 109 void set_sensitivity(sc_interface *); 110 void set_sensitivity(sc_event_finder *); 111 112 void reset_signal_is(const sc_in<bool> &, bool); 113 void reset_signal_is(const sc_inout<bool> &, bool); 114 void reset_signal_is(const sc_out<bool> &, bool); 115 void reset_signal_is(const sc_signal_in_if<bool> &, bool); 116 117 void async_reset_signal_is(const sc_in<bool> &, bool); 118 void async_reset_signal_is(const sc_inout<bool> &, bool); 119 void async_reset_signal_is(const sc_out<bool> &, bool); 120 void async_reset_signal_is(const sc_signal_in_if<bool> &, bool); 121 122 private: 123 bool _spawnMethod; 124 bool _dontInitialize; 125 int _stackSize; 126 std::vector<const sc_event *> _events; 127 std::vector<sc_port_base *> _ports; 128 std::vector<sc_export_base *> _exports; 129 std::vector<sc_interface *> _interfaces; 130 std::vector<sc_event_finder *> _finders; 131 132 // Disabled 133 sc_spawn_options(const sc_spawn_options &) {} 134 sc_spawn_options &operator = (const sc_spawn_options &) { return *this; } 135}; 136 137void sc_spawn_warn_unimpl(const char *func); 138 139template <typename T> 140sc_process_handle 141sc_spawn(T object, const char *name_p=nullptr, 142 const sc_spawn_options *opt_p=nullptr) 143{ 144 auto func = new ::sc_gem5::ProcessObjFuncWrapper<T>(object); 145 ::sc_gem5::Process *p = spawnWork(func, name_p, opt_p); 146 return sc_process_handle() = p; 147} 148 149template <typename T> 150sc_process_handle 151sc_spawn(typename T::result_type *r_p, T object, const char *name_p=nullptr, 152 const sc_spawn_options *opt_p=nullptr) 153{ 154 auto func = new ::sc_gem5::ProcessObjRetFuncWrapper< 155 T, typename T::result_type>(object, r_p); 156 ::sc_gem5::Process *p = spawnWork(func, name_p, opt_p); 157 return sc_process_handle() = p; 158} 159 160#define sc_bind boost::bind 161#define sc_ref(r) boost::ref(r) 162#define sc_cref(r) boost::cref(r) 163 164#define SC_FORK \ 165{ \ 166 ::sc_core::sc_process_handle forkees[] = { 167 168#define SC_JOIN \
| 36#include "sc_process_handle.hh" 37 38namespace sc_core 39{ 40 41class sc_spawn_options; 42 43} // namespace sc_core 44 45namespace sc_gem5 46{ 47 48class Process; 49 50template <typename T> 51struct ProcessObjFuncWrapper : public ProcessFuncWrapper 52{ 53 T t; 54 55 ProcessObjFuncWrapper(T t) : t(t) {} 56 57 void call() override { t(); } 58}; 59 60template <typename T, typename R> 61struct ProcessObjRetFuncWrapper : public ProcessFuncWrapper 62{ 63 T t; 64 R *r; 65 66 ProcessObjRetFuncWrapper(T t, R *r) : t(t), r(r) {} 67 68 void call() override { *r = t(); } 69}; 70 71Process *spawnWork(ProcessFuncWrapper *func, const char *name, 72 const ::sc_core::sc_spawn_options *); 73 74} // namespace sc_gem5 75 76namespace sc_core 77{ 78 79template <class T> 80class sc_in; 81template <class T> 82class sc_inout; 83template <class T> 84class sc_out; 85template <class T> 86class sc_signal_in_if; 87 88class sc_event; 89class sc_event_finder; 90class sc_export_base; 91class sc_interface; 92class sc_port_base; 93 94class sc_spawn_options 95{ 96 public: 97 friend ::sc_gem5::Process *::sc_gem5::spawnWork( 98 ::sc_gem5::ProcessFuncWrapper *, const char *, 99 const sc_spawn_options *); 100 101 sc_spawn_options(); 102 103 void spawn_method(); 104 void dont_initialize(); 105 void set_stack_size(int); 106 107 void set_sensitivity(const sc_event *); 108 void set_sensitivity(sc_port_base *); 109 void set_sensitivity(sc_export_base *); 110 void set_sensitivity(sc_interface *); 111 void set_sensitivity(sc_event_finder *); 112 113 void reset_signal_is(const sc_in<bool> &, bool); 114 void reset_signal_is(const sc_inout<bool> &, bool); 115 void reset_signal_is(const sc_out<bool> &, bool); 116 void reset_signal_is(const sc_signal_in_if<bool> &, bool); 117 118 void async_reset_signal_is(const sc_in<bool> &, bool); 119 void async_reset_signal_is(const sc_inout<bool> &, bool); 120 void async_reset_signal_is(const sc_out<bool> &, bool); 121 void async_reset_signal_is(const sc_signal_in_if<bool> &, bool); 122 123 private: 124 bool _spawnMethod; 125 bool _dontInitialize; 126 int _stackSize; 127 std::vector<const sc_event *> _events; 128 std::vector<sc_port_base *> _ports; 129 std::vector<sc_export_base *> _exports; 130 std::vector<sc_interface *> _interfaces; 131 std::vector<sc_event_finder *> _finders; 132 133 // Disabled 134 sc_spawn_options(const sc_spawn_options &) {} 135 sc_spawn_options &operator = (const sc_spawn_options &) { return *this; } 136}; 137 138void sc_spawn_warn_unimpl(const char *func); 139 140template <typename T> 141sc_process_handle 142sc_spawn(T object, const char *name_p=nullptr, 143 const sc_spawn_options *opt_p=nullptr) 144{ 145 auto func = new ::sc_gem5::ProcessObjFuncWrapper<T>(object); 146 ::sc_gem5::Process *p = spawnWork(func, name_p, opt_p); 147 return sc_process_handle() = p; 148} 149 150template <typename T> 151sc_process_handle 152sc_spawn(typename T::result_type *r_p, T object, const char *name_p=nullptr, 153 const sc_spawn_options *opt_p=nullptr) 154{ 155 auto func = new ::sc_gem5::ProcessObjRetFuncWrapper< 156 T, typename T::result_type>(object, r_p); 157 ::sc_gem5::Process *p = spawnWork(func, name_p, opt_p); 158 return sc_process_handle() = p; 159} 160 161#define sc_bind boost::bind 162#define sc_ref(r) boost::ref(r) 163#define sc_cref(r) boost::cref(r) 164 165#define SC_FORK \ 166{ \ 167 ::sc_core::sc_process_handle forkees[] = { 168 169#define SC_JOIN \
|
169 }; /* TODO wait for the forkees. */ \
| 170 }; \ 171 ::sc_core::sc_join join; \ 172 for (int i = 0; i < sizeof(forkees) / sizeof(forkees[0]); i++) \ 173 join.add_process(forkees[i]); \ 174 join.wait(); \
|
170} 171 172// Non-standard
| 175} 176 177// Non-standard
|
173#define SC_CJOIN SC_JOIN
| 178#define SC_CJOIN \ 179 }; \ 180 ::sc_core::sc_join join; \ 181 for (int i = 0; i < sizeof(forkees) / sizeof(forkees[0]); i++) \ 182 join.add_process(forkees[i]); \ 183 join.wait_clocked(); \ 184}
|
174
| 185
|
| 186
|
175} // namespace sc_core 176 177namespace sc_unnamed 178{ 179 180typedef int ImplementationDefined; 181extern ImplementationDefined _1; 182extern ImplementationDefined _2; 183extern ImplementationDefined _3; 184extern ImplementationDefined _4; 185extern ImplementationDefined _5; 186extern ImplementationDefined _6; 187extern ImplementationDefined _7; 188extern ImplementationDefined _8; 189extern ImplementationDefined _9; 190 191} // namespace sc_unnamed 192 193#endif //__SYSTEMC_EXT_CORE_SC_SPAWN_HH__
| 187} // namespace sc_core 188 189namespace sc_unnamed 190{ 191 192typedef int ImplementationDefined; 193extern ImplementationDefined _1; 194extern ImplementationDefined _2; 195extern ImplementationDefined _3; 196extern ImplementationDefined _4; 197extern ImplementationDefined _5; 198extern ImplementationDefined _6; 199extern ImplementationDefined _7; 200extern ImplementationDefined _8; 201extern ImplementationDefined _9; 202 203} // namespace sc_unnamed 204 205#endif //__SYSTEMC_EXT_CORE_SC_SPAWN_HH__
|