diff --git a/src/sim/init.cc b/src/sim/init.cc index 9d94618767..c8a545fe56 100644 --- a/src/sim/init.cc +++ b/src/sim/init.cc @@ -191,41 +191,4 @@ PYBIND11_EMBEDDED_MODULE(_m5, _m5) EmbeddedPyBind::initAll(_m5); } -/* - * Start up the M5 simulator. This mostly vectors into the python - * main function. - */ -int -gem5Main(int argc, char **argv) -{ - // Embedded python doesn't set up sys.argv, so we'll do that ourselves. - py::list py_argv; - auto sys = py::module::import("sys"); - if (py::hasattr(sys, "argv")) { - // sys.argv already exists, so grab that. - py_argv = sys.attr("argv"); - } else { - // sys.argv doesn't exist, so create it. - sys.add_object("argv", py_argv); - } - // Clear out argv just in case it has something in it. - py_argv.attr("clear")(); - - // Fill it with our argvs. - for (int i = 0; i < argc; i++) - py_argv.append(argv[i]); - - try { - py::module_::import("m5").attr("main")(); - } catch (py::error_already_set &e) { - if (e.matches(PyExc_SystemExit)) - return e.value().attr("code").cast(); - - std::cerr << e.what(); - return 1; - } - - return 0; -} - } // namespace gem5 diff --git a/src/sim/init.hh b/src/sim/init.hh index b4c248d4ef..95c597b8d4 100644 --- a/src/sim/init.hh +++ b/src/sim/init.hh @@ -98,8 +98,6 @@ class EmbeddedPyBind static std::map &getMap(); }; -int gem5Main(int argc, char **argv); - } // namespace gem5 #endif // __SIM_INIT_HH__ diff --git a/src/sim/main.cc b/src/sim/main.cc index c89e67ff39..0d9bcb7ed4 100644 --- a/src/sim/main.cc +++ b/src/sim/main.cc @@ -28,6 +28,8 @@ #include +#include + #include "pybind11/embed.h" #include "pybind11/pybind11.h" @@ -41,7 +43,7 @@ namespace py = pybind11; // main() is now pretty stripped down and just sets up python and then // calls EmbeddedPython::initAll which loads the various embedded python // modules into the python environment and then starts things running by -// calling gem5Main. +// running python's m5.main(). int main(int argc, char **argv) { @@ -63,5 +65,32 @@ main(int argc, char **argv) auto importer = py::module_::import("importer"); importer.attr("install")(); - return gem5Main(argc, argv); + // Embedded python doesn't set up sys.argv, so we'll do that ourselves. + py::list py_argv; + auto sys = py::module::import("sys"); + if (py::hasattr(sys, "argv")) { + // sys.argv already exists, so grab that. + py_argv = sys.attr("argv"); + } else { + // sys.argv doesn't exist, so create it. + sys.add_object("argv", py_argv); + } + // Clear out argv just in case it has something in it. + py_argv.attr("clear")(); + + // Fill it with our argvs. + for (int i = 0; i < argc; i++) + py_argv.append(argv[i]); + + try { + py::module_::import("m5").attr("main")(); + } catch (py::error_already_set &e) { + if (e.matches(PyExc_SystemExit)) + return e.value().attr("code").cast(); + + std::cerr << e.what(); + return 1; + } + + return 0; }