summaryrefslogtreecommitdiff
path: root/src/sim/init.cc
diff options
context:
space:
mode:
authorNathan Binkert <nate@binkert.org>2011-04-15 10:44:59 -0700
committerNathan Binkert <nate@binkert.org>2011-04-15 10:44:59 -0700
commit8c97726266a83fda31f8a68860157f195d7466ea (patch)
treee5d0a6a412003a26a3d57b20cf3717e123640f8f /src/sim/init.cc
parent3182913e94674fcd101ec01c7ffb8245ec3046f8 (diff)
downloadgem5-8c97726266a83fda31f8a68860157f195d7466ea.tar.xz
python: cleanup python code so stuff doesn't automatically happen at startup
this allows things to be overridden at startup (e.g. for tests)
Diffstat (limited to 'src/sim/init.cc')
-rw-r--r--src/sim/init.cc34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/sim/init.cc b/src/sim/init.cc
index 4c795eac4..02361fd84 100644
--- a/src/sim/init.cc
+++ b/src/sim/init.cc
@@ -222,6 +222,16 @@ initM5Python()
}
/*
+ * Make the commands array weak so that they can be overridden (used
+ * by unit tests to specify a different python main function.
+ */
+const char * __attribute__((weak)) m5MainCommands[] = {
+ "import m5",
+ "m5.main()",
+ 0 // sentinel is required
+};
+
+/*
* Start up the M5 simulator. This mostly vectors into the python
* main function.
*/
@@ -238,20 +248,20 @@ m5Main(int argc, char **argv)
// import the main m5 module
PyObject *result;
- result = PyRun_String("import m5", Py_file_input, dict, dict);
- if (!result) {
- PyErr_Print();
- return 1;
- }
- Py_DECREF(result);
+ const char **command = m5MainCommands;
+
+ // evaluate each command in the m5MainCommands array (basically a
+ // bunch of python statements.
+ while (*command) {
+ result = PyRun_String(*command, Py_file_input, dict, dict);
+ if (!result) {
+ PyErr_Print();
+ return 1;
+ }
+ Py_DECREF(result);
- // Start m5
- result = PyRun_String("m5.main()", Py_file_input, dict, dict);
- if (!result) {
- PyErr_Print();
- return 1;
+ command++;
}
- Py_DECREF(result);
return 0;
}