sc_main.cc (13077:0037323cb4dd) | sc_main.cc (13081:fd1b50840830) |
---|---|
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> | 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> |
|
31 32#include "base/fiber.hh" 33#include "base/logging.hh" 34#include "base/types.hh" 35#include "sim/core.hh" 36#include "sim/eventq.hh" 37#include "sim/init.hh" 38#include "systemc/core/kernel.hh" --- 13 unchanged lines hidden (view full) --- 52 53bool scMainCalled = false; 54 55int _argc = 0; 56char **_argv = NULL; 57 58class ScMainFiber : public Fiber 59{ | 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 |
|
60 void 61 main() 62 { 63 if (::sc_main) { | 67 void 68 main() 69 { 70 if (::sc_main) { |
64 ::sc_main(_argc, _argv); 65 // Make sure no systemc events/notifications are scheduled 66 // after sc_main returns. | 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 } |
67 ::sc_gem5::Kernel::scMainFinished(true); 68 ::sc_gem5::scheduler.clear(); 69 } else { 70 // If python tries to call sc_main but no sc_main was defined... 71 fatal("sc_main called but not defined.\n"); 72 } 73 } 74}; --- 35 unchanged lines hidden (view full) --- 110 111 // At this point we're going to call the c++ sc_main, so we can't try 112 // again later. 113 scMainCalled = true; 114 115 scMainFiber.run(); 116} 117 | 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 |
|
118// Make our sc_main wrapper available in the internal _m5 python module under 119// the systemc submodule. 120 121struct InstallScMain : public ::sc_gem5::PythonInitFunc 122{ 123 void 124 run(pybind11::module &systemc) override 125 { 126 systemc.def("sc_main", &sc_main); | 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); |
|
127 } 128} installScMain; 129 130sc_stop_mode _stop_mode = SC_STOP_FINISH_DELTA; 131 132} // anonymous namespace 133 134int --- 181 unchanged lines hidden --- | 157 } 158} installScMain; 159 160sc_stop_mode _stop_mode = SC_STOP_FINISH_DELTA; 161 162} // anonymous namespace 163 164int --- 181 unchanged lines hidden --- |