main.cc (2868:6a7e69fa92d3) | main.cc (2889:9e367e03d656) |
---|---|
1/* 2 * Copyright (c) 2000-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 101 unchanged lines hidden (view full) --- 110 cerr << "Program aborted at cycle " << curTick << endl; 111 112#if TRACING_ON 113 // dump trace buffer, if there is one 114 Trace::theLog.dump(cerr); 115#endif 116} 117 | 1/* 2 * Copyright (c) 2000-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 101 unchanged lines hidden (view full) --- 110 cerr << "Program aborted at cycle " << curTick << endl; 111 112#if TRACING_ON 113 // dump trace buffer, if there is one 114 Trace::theLog.dump(cerr); 115#endif 116} 117 |
118/// Simulator executable name 119char *myProgName = ""; 120 121/// Show brief help message. 122void 123showBriefHelp(ostream &out) 124{ 125 char *prog = basename(myProgName); 126 127 ccprintf(out, "Usage:\n"); 128 ccprintf(out, 129"%s [-p <path>] [-i ] [-h] <config file>\n" 130"\n" 131" -p, --path <path> prepends <path> to PYTHONPATH instead of using\n" 132" built-in zip archive. Useful when developing/debugging\n" 133" changes to built-in Python libraries, as the new Python\n" 134" can be tested without building a new m5 binary.\n\n" 135" -i, --interactive forces entry into interactive mode after the supplied\n" 136" script is executed (just like the -i option to the\n" 137" Python interpreter).\n\n" 138" -h Prints this help\n\n" 139" <configfile> config file name which ends in .py. (Normally you can\n" 140" run <configfile> --help to get help on that config files\n" 141" parameters.\n\n", 142 prog); 143 144} 145 146const char *briefCopyright = 147"Copyright (c) 2001-2006\n" 148"The Regents of The University of Michigan\n" 149"All Rights Reserved\n"; 150 151/// Print welcome message. 152void 153sayHello(ostream &out) 154{ 155 extern const char *compileDate; // from date.cc 156 157 ccprintf(out, "M5 Simulator System\n"); 158 // display copyright 159 ccprintf(out, "%s\n", briefCopyright); 160 ccprintf(out, "M5 compiled %d\n", compileDate); 161 ccprintf(out, "M5 started %s\n", Time::start); 162 163 char *host = getenv("HOSTNAME"); 164 if (!host) 165 host = getenv("HOST"); 166 167 if (host) 168 ccprintf(out, "M5 executing on %s\n", host); 169} 170 171 | |
172extern "C" { void init_cc_main(); } 173 174int 175main(int argc, char **argv) 176{ | 118extern "C" { void init_cc_main(); } 119 120int 121main(int argc, char **argv) 122{ |
177 // Saze off program name 178 myProgName = argv[0]; 179 180 sayHello(cerr); 181 | |
182 signal(SIGFPE, SIG_IGN); // may occur on misspeculated paths 183 signal(SIGTRAP, SIG_IGN); 184 signal(SIGUSR1, dumpStatsHandler); // dump intermediate stats 185 signal(SIGUSR2, dumprstStatsHandler); // dump and reset stats 186 signal(SIGINT, exitNowHandler); // dump final stats and exit 187 signal(SIGABRT, abortHandler); 188 189 Py_SetProgramName(argv[0]); 190 191 // default path to m5 python code is the currently executing | 123 signal(SIGFPE, SIG_IGN); // may occur on misspeculated paths 124 signal(SIGTRAP, SIG_IGN); 125 signal(SIGUSR1, dumpStatsHandler); // dump intermediate stats 126 signal(SIGUSR2, dumprstStatsHandler); // dump and reset stats 127 signal(SIGINT, exitNowHandler); // dump final stats and exit 128 signal(SIGABRT, abortHandler); 129 130 Py_SetProgramName(argv[0]); 131 132 // default path to m5 python code is the currently executing |
192 // file... Python ZipImporter will find embedded zip archive 193 char *pythonpath = argv[0]; | 133 // file... Python ZipImporter will find embedded zip archive. 134 // The M5_ARCHIVE environment variable can be used to override this. 135 char *m5_archive = getenv("M5_ARCHIVE"); 136 string pythonpath = m5_archive ? m5_archive : argv[0]; |
194 | 137 |
195 bool interactive = false; 196 bool show_help = false; 197 bool getopt_done = false; 198 int opt_index = 0; 199 200 static struct option long_options[] = { 201 {"python", 1, 0, 'p'}, 202 {"interactive", 0, 0, 'i'}, 203 {"help", 0, 0, 'h'}, 204 {0,0,0,0} 205 }; 206 207 do { 208 switch (getopt_long(argc, argv, "+p:ih", long_options, &opt_index)) { 209 // -p <path> prepends <path> to PYTHONPATH instead of 210 // using built-in zip archive. Useful when 211 // developing/debugging changes to built-in Python 212 // libraries, as the new Python can be tested without 213 // building a new m5 binary. 214 case 'p': 215 pythonpath = optarg; 216 break; 217 218 // -i forces entry into interactive mode after the 219 // supplied script is executed (just like the -i option to 220 // the Python interpreter). 221 case 'i': 222 interactive = true; 223 break; 224 225 case 'h': 226 show_help = true; 227 break; 228 case -1: 229 getopt_done = true; 230 break; 231 232 default: 233 fatal("Unrecognized option %c\n", optopt); 234 } 235 } while (!getopt_done); 236 237 if (show_help) { 238 showBriefHelp(cerr); 239 exit(1); 240 } 241 242 // Fix up argc & argv to hide arguments we just processed. 243 // getopt() sets optind to the index of the first non-processed 244 // argv element. 245 argc -= optind; 246 argv += optind; 247 248 // Set up PYTHONPATH to make sure the m5 module is found 249 string newpath(pythonpath); 250 | |
251 char *oldpath = getenv("PYTHONPATH"); 252 if (oldpath != NULL) { | 138 char *oldpath = getenv("PYTHONPATH"); 139 if (oldpath != NULL) { |
253 newpath += ":"; 254 newpath += oldpath; | 140 pythonpath += ":"; 141 pythonpath += oldpath; |
255 } 256 | 142 } 143 |
257 if (setenv("PYTHONPATH", newpath.c_str(), true) == -1) | 144 if (setenv("PYTHONPATH", pythonpath.c_str(), true) == -1) |
258 fatal("setenv: %s\n", strerror(errno)); 259 260 // initialize embedded Python interpreter 261 Py_Initialize(); 262 PySys_SetArgv(argc, argv); 263 264 // initialize SWIG 'cc_main' module 265 init_cc_main(); 266 | 145 fatal("setenv: %s\n", strerror(errno)); 146 147 // initialize embedded Python interpreter 148 Py_Initialize(); 149 PySys_SetArgv(argc, argv); 150 151 // initialize SWIG 'cc_main' module 152 init_cc_main(); 153 |
267 if (argc > 0) { 268 // extra arg(s): first is script file, remaining ones are args 269 // to script file 270 char *filename = argv[0]; 271 FILE *fp = fopen(filename, "r"); 272 if (!fp) { 273 fatal("cannot open file '%s'\n", filename); 274 } | 154 PyRun_SimpleString("import m5"); 155 PyRun_SimpleString("m5.main()"); |
275 | 156 |
276 PyRun_AnyFile(fp, filename); 277 } else { 278 // no script file argument... force interactive prompt 279 interactive = true; 280 } 281 282 if (interactive) { 283 // The following code to import readline was copied from Python 284 // 2.4.3's Modules/main.c. 285 // Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 286 // Python Software Foundation; All Rights Reserved 287 // We should only enable this if we're actually using an 288 // interactive prompt. 289 PyObject *v; 290 v = PyImport_ImportModule("readline"); 291 if (v == NULL) 292 PyErr_Clear(); 293 else 294 Py_DECREF(v); 295 296 PyRun_InteractiveLoop(stdin, "stdin"); 297 } 298 | |
299 // clean up Python intepreter. 300 Py_Finalize(); 301} 302 303 304void 305setOutputDir(const string &dir) 306{ --- 290 unchanged lines hidden --- | 157 // clean up Python intepreter. 158 Py_Finalize(); 159} 160 161 162void 163setOutputDir(const string &dir) 164{ --- 290 unchanged lines hidden --- |