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 --- 24 unchanged lines hidden (view full) --- 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" 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" 46#include "systemc/utils/report.hh" 47 |
48namespace sc_core 49{ 50 51namespace 52{ 53 |
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 --- 7 unchanged lines hidden (view full) --- 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(); |
126} 127 128const char *const * 129sc_argv() 130{ |
131 return ::sc_gem5::scMainFiber.argv(); |
132} 133 134void 135sc_start() 136{ 137 Tick now = ::sc_gem5::scheduler.getCurTick(); 138 sc_start(sc_time::from_value(MaxTick - now), SC_EXIT_ON_STARVATION); 139} --- 173 unchanged lines hidden --- |