Gabe Black has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/49417 )
(
30 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the
submitted one.
)Change subject: sim: Collapse gem5Main into main.
......................................................................
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 <[email protected]>
Maintainer: Gabe Black <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/sim/main.cc
M src/sim/init.cc
M src/sim/init.hh
3 files changed, 49 insertions(+), 41 deletions(-)
Approvals:
Gabe Black: Looks good to me, approved; Looks good to me, approved
kokoro: Regressions pass
diff --git a/src/sim/init.cc b/src/sim/init.cc
index 9d94618..c8a545f 100644
--- a/src/sim/init.cc
+++ b/src/sim/init.cc
@@ -191,41 +191,4 @@
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<int>();
-
- std::cerr << e.what();
- return 1;
- }
-
- return 0;
-}
-
} // namespace gem5
diff --git a/src/sim/init.hh b/src/sim/init.hh
index b4c248d..95c597b 100644
--- a/src/sim/init.hh
+++ b/src/sim/init.hh
@@ -98,8 +98,6 @@
static std::map<std::string, EmbeddedPyBind *> &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 c89e67f..0d9bcb7 100644
--- a/src/sim/main.cc
+++ b/src/sim/main.cc
@@ -28,6 +28,8 @@
#include <Python.h>
+#include <iostream>
+
#include "pybind11/embed.h"
#include "pybind11/pybind11.h"
@@ -41,7 +43,7 @@
// 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 @@
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<int>();
+
+ std::cerr << e.what();
+ return 1;
+ }
+
+ return 0;
}
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/49417
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I17e303e3a29d5473f0f31cd51d7fb367f6c81f9e
Gerrit-Change-Number: 49417
Gerrit-PatchSet: 33
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s