sc_main.cc (12861:6cd674bd189a) | sc_main.cc (12862:df3aaa5bda42) |
---|---|
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 --- 15 unchanged lines hidden (view full) --- 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 <cstring> 31 | 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 --- 15 unchanged lines hidden (view full) --- 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 <cstring> 31 |
32#include "base/fiber.hh" |
|
32#include "base/logging.hh" | 33#include "base/logging.hh" |
34#include "base/types.hh" |
|
33#include "python/pybind11/pybind.hh" | 35#include "python/pybind11/pybind.hh" |
36#include "sim/eventq.hh" |
|
34#include "sim/init.hh" 35#include "systemc/ext/core/sc_main.hh" 36#include "systemc/ext/utils/sc_report_handler.hh" 37 38// A default version of this function in case one isn't otherwise defined. 39// This ensures everything will link properly whether or not the user defined 40// a custom sc_main function. If they didn't but still try to call it, throw 41// an error and die. --- 10 unchanged lines hidden (view full) --- 52namespace 53{ 54 55bool scMainCalled = false; 56 57int _argc = 0; 58char **_argv = NULL; 59 | 37#include "sim/init.hh" 38#include "systemc/ext/core/sc_main.hh" 39#include "systemc/ext/utils/sc_report_handler.hh" 40 41// A default version of this function in case one isn't otherwise defined. 42// This ensures everything will link properly whether or not the user defined 43// a custom sc_main function. If they didn't but still try to call it, throw 44// an error and die. --- 10 unchanged lines hidden (view full) --- 55namespace 56{ 57 58bool scMainCalled = false; 59 60int _argc = 0; 61char **_argv = NULL; 62 |
63class ScMainFiber : public Fiber 64{ 65 void 66 main() 67 { 68 ::sc_main(_argc, _argv); 69 } 70}; 71 72ScMainFiber scMainFiber; 73 |
|
60// This wrapper adapts the python version of sc_main to the c++ version. 61void 62sc_main(pybind11::args args) 63{ 64 panic_if(scMainCalled, "sc_main called more than once."); 65 66 _argc = args.size(); 67 _argv = new char *[_argc]; --- 21 unchanged lines hidden (view full) --- 89 _argc = 0; 90 throw; 91 } 92 93 // At this point we're going to call the c++ sc_main, so we can't try 94 // again later. 95 scMainCalled = true; 96 | 74// This wrapper adapts the python version of sc_main to the c++ version. 75void 76sc_main(pybind11::args args) 77{ 78 panic_if(scMainCalled, "sc_main called more than once."); 79 80 _argc = args.size(); 81 _argv = new char *[_argc]; --- 21 unchanged lines hidden (view full) --- 103 _argc = 0; 104 throw; 105 } 106 107 // At this point we're going to call the c++ sc_main, so we can't try 108 // again later. 109 scMainCalled = true; 110 |
97 //TODO Start a new fiber to call sc_main from. 98 ::sc_main(_argc, _argv); | 111 scMainFiber.run(); |
99} 100 101// Make our sc_main wrapper available in the internal _m5 python module under 102// the systemc submodule. 103void 104systemc_pybind(pybind11::module &m_internal) 105{ 106 pybind11::module m = m_internal.def_submodule("systemc"); 107 m.def("sc_main", &sc_main); 108} 109EmbeddedPyBind embed_("systemc", &systemc_pybind); 110 111sc_stop_mode _stop_mode = SC_STOP_FINISH_DELTA; 112sc_status _status = SC_ELABORATION; 113 | 112} 113 114// Make our sc_main wrapper available in the internal _m5 python module under 115// the systemc submodule. 116void 117systemc_pybind(pybind11::module &m_internal) 118{ 119 pybind11::module m = m_internal.def_submodule("systemc"); 120 m.def("sc_main", &sc_main); 121} 122EmbeddedPyBind embed_("systemc", &systemc_pybind); 123 124sc_stop_mode _stop_mode = SC_STOP_FINISH_DELTA; 125sc_status _status = SC_ELABORATION; 126 |
127Tick _max_tick = MaxTick; 128sc_starvation_policy _starvation = SC_EXIT_ON_STARVATION; 129 |
|
114uint64_t _deltaCycles = 0; 115 116} // anonymous namespace 117 118int 119sc_argc() 120{ 121 return _argc; 122} 123 124const char *const * 125sc_argv() 126{ 127 return _argv; 128} 129 130void 131sc_start() 132{ | 130uint64_t _deltaCycles = 0; 131 132} // anonymous namespace 133 134int 135sc_argc() 136{ 137 return _argc; 138} 139 140const char *const * 141sc_argv() 142{ 143 return _argv; 144} 145 146void 147sc_start() 148{ |
133 warn("%s not implemented.\n", __PRETTY_FUNCTION__); | 149 _max_tick = MaxTick; 150 _starvation = SC_EXIT_ON_STARVATION; 151 152 // Switch back gem5. 153 Fiber::primaryFiber()->run(); |
134} 135 136void 137sc_pause() 138{ 139 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 140} 141 142void 143sc_start(const sc_time &time, sc_starvation_policy p) 144{ | 154} 155 156void 157sc_pause() 158{ 159 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 160} 161 162void 163sc_start(const sc_time &time, sc_starvation_policy p) 164{ |
145 warn("%s not implemented.\n", __PRETTY_FUNCTION__); | 165 Tick now = curEventQueue() ? curEventQueue()->getCurTick() : 0; 166 _max_tick = now + time.value(); 167 _starvation = p; 168 169 // Switch back to gem5. 170 Fiber::primaryFiber()->run(); |
146} 147 148void 149sc_set_stop_mode(sc_stop_mode mode) 150{ 151 if (sc_is_running()) { 152 SC_REPORT_ERROR("attempt to set sc_stop mode " 153 "after start will be ignored", ""); --- 71 unchanged lines hidden --- | 171} 172 173void 174sc_set_stop_mode(sc_stop_mode mode) 175{ 176 if (sc_is_running()) { 177 SC_REPORT_ERROR("attempt to set sc_stop mode " 178 "after start will be ignored", ""); --- 71 unchanged lines hidden --- |