sc_main.cc (13403:cebee63981d3) | sc_main.cc (13404:5da37c38d749) |
---|---|
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 --- 13 unchanged lines hidden (view full) --- 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 | 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 --- 13 unchanged lines hidden (view full) --- 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#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" | 30#include "base/types.hh" 31#include "sim/core.hh" 32#include "sim/eventq.hh" |
38#include "sim/init.hh" | |
39#include "systemc/core/kernel.hh" | 33#include "systemc/core/kernel.hh" |
40#include "systemc/core/python.hh" | |
41#include "systemc/core/sc_main_fiber.hh" 42#include "systemc/core/scheduler.hh" 43#include "systemc/ext/core/messages.hh" 44#include "systemc/ext/core/sc_main.hh" 45#include "systemc/ext/utils/sc_report_handler.hh" | 34#include "systemc/core/sc_main_fiber.hh" 35#include "systemc/core/scheduler.hh" 36#include "systemc/ext/core/messages.hh" 37#include "systemc/ext/core/sc_main.hh" 38#include "systemc/ext/utils/sc_report_handler.hh" |
46#include "systemc/utils/report.hh" | |
47 48namespace sc_core 49{ 50 51namespace 52{ 53 | 39 40namespace sc_core 41{ 42 43namespace 44{ 45 |
54// This wrapper adapts the python version of sc_main to the c++ version. 55void 56sc_main(pybind11::args args) 57{ 58 panic_if(::sc_gem5::scMainFiber.called(), 59 "sc_main called more than once."); 60 61 int argc = args.size(); 62 char **argv = new char *[argc]; 63 64 // Initialize all the argvs to NULL so we can delete [] them 65 // unconditionally. 66 for (int idx = 0; idx < argc; idx++) 67 argv[idx] = NULL; 68 69 // Attempt to convert all the arguments to strings. If that fails, clean 70 // up after ourselves. Also don't count this as a call to sc_main since 71 // we never got to the c++ version of that function. 72 try { 73 for (int idx = 0; idx < argc; idx++) { 74 std::string arg = args[idx].cast<std::string>(); 75 argv[idx] = new char[arg.length() + 1]; 76 strcpy(argv[idx], arg.c_str()); 77 } 78 } catch (...) { 79 // If that didn't work for some reason (probably a conversion error) 80 // blow away argv and argc and pass on the exception. 81 for (int idx = 0; idx < argc; idx++) 82 delete [] argv[idx]; 83 delete [] argv; 84 argc = 0; 85 throw; 86 } 87 88 ::sc_gem5::scMainFiber.setArgs(argc, argv); 89 ::sc_gem5::scMainFiber.run(); 90} 91 92int 93sc_main_result_code() 94{ 95 return ::sc_gem5::scMainFiber.resultInt(); 96} 97 98std::string 99sc_main_result_str() 100{ 101 return ::sc_gem5::scMainFiber.resultStr(); 102} 103 104// Make our sc_main wrapper available in the internal _m5 python module under 105// the systemc submodule. 106 107struct InstallScMain : public ::sc_gem5::PythonInitFunc 108{ 109 void 110 run(pybind11::module &systemc) override 111 { 112 systemc.def("sc_main", &sc_main); 113 systemc.def("sc_main_result_code", &sc_main_result_code); 114 systemc.def("sc_main_result_str", &sc_main_result_str); 115 } 116} installScMain; 117 | |
118sc_stop_mode _stop_mode = SC_STOP_FINISH_DELTA; 119 120} // anonymous namespace 121 122int 123sc_argc() 124{ 125 return ::sc_gem5::scMainFiber.argc(); --- 187 unchanged lines hidden --- | 46sc_stop_mode _stop_mode = SC_STOP_FINISH_DELTA; 47 48} // anonymous namespace 49 50int 51sc_argc() 52{ 53 return ::sc_gem5::scMainFiber.argc(); --- 187 unchanged lines hidden --- |