From 8c97726266a83fda31f8a68860157f195d7466ea Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Fri, 15 Apr 2011 10:44:59 -0700 Subject: python: cleanup python code so stuff doesn't automatically happen at startup this allows things to be overridden at startup (e.g. for tests) --- src/sim/init.cc | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'src/sim/init.cc') 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 @@ -221,6 +221,16 @@ initM5Python() return EmbeddedPython::initAll(); } +/* + * 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; } -- cgit v1.2.3