From 2af584096f5db137cccb6f507db166b240dd2823 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Tue, 17 Aug 2021 04:16:34 -0700 Subject: [PATCH] sim: Collapse gem5Main into main. gem5Main is short and simple and only calls into python's m5.main() function. It's also only called from one place and only makes sense to call from one place, so lets just put it there inline and keep everything together. Change-Id: I17e303e3a29d5473f0f31cd51d7fb367f6c81f9e Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/49417 Reviewed-by: Gabe Black Maintainer: Gabe Black Tested-by: kokoro --- src/sim/init.cc | 37 ------------------------------------- src/sim/init.hh | 2 -- src/sim/main.cc | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 41 deletions(-) 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; }