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 --- 14 unchanged lines hidden (view full) --- 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#include <cstring> |
31#include <string> |
32 33#include "base/fiber.hh" 34#include "base/logging.hh" 35#include "base/types.hh" 36#include "sim/core.hh" 37#include "sim/eventq.hh" 38#include "sim/init.hh" 39#include "systemc/core/kernel.hh" --- 13 unchanged lines hidden (view full) --- 53 54bool scMainCalled = false; 55 56int _argc = 0; 57char **_argv = NULL; 58 59class ScMainFiber : public Fiber 60{ |
61 public: 62 std::string resultStr; 63 int resultInt; 64 65 ScMainFiber() : resultInt(1) {} 66 |
67 void 68 main() 69 { 70 if (::sc_main) { |
71 try { 72 resultInt = ::sc_main(_argc, _argv); 73 if (resultInt) 74 resultStr = "sc_main returned non-zero"; 75 else 76 resultStr = "sc_main finished"; 77 // Make sure no systemc events/notifications are scheduled 78 // after sc_main returns. 79 } catch (const sc_report &r) { 80 // There was an exception nobody caught. 81 resultStr = r.what(); 82 } |
83 ::sc_gem5::Kernel::scMainFinished(true); 84 ::sc_gem5::scheduler.clear(); 85 } else { 86 // If python tries to call sc_main but no sc_main was defined... 87 fatal("sc_main called but not defined.\n"); 88 } 89 } 90}; --- 35 unchanged lines hidden (view full) --- 126 127 // At this point we're going to call the c++ sc_main, so we can't try 128 // again later. 129 scMainCalled = true; 130 131 scMainFiber.run(); 132} 133 |
134int 135sc_main_result_code() 136{ 137 return scMainFiber.resultInt; 138} 139 140std::string 141sc_main_result_str() 142{ 143 return scMainFiber.resultStr; 144} 145 |
146// Make our sc_main wrapper available in the internal _m5 python module under 147// the systemc submodule. 148 149struct InstallScMain : public ::sc_gem5::PythonInitFunc 150{ 151 void 152 run(pybind11::module &systemc) override 153 { 154 systemc.def("sc_main", &sc_main); |
155 systemc.def("sc_main_result_code", &sc_main_result_code); 156 systemc.def("sc_main_result_str", &sc_main_result_str); |
157 } 158} installScMain; 159 160sc_stop_mode _stop_mode = SC_STOP_FINISH_DELTA; 161 162} // anonymous namespace 163 164int --- 181 unchanged lines hidden --- |