summaryrefslogtreecommitdiff
path: root/src/sim/init.cc
diff options
context:
space:
mode:
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;
}