main.cc (2737:f712ccc4b1f9) main.cc (2738:5d7a31c7fa29)
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;

--- 43 unchanged lines hidden (view full) ---

52#include "base/misc.hh"
53#include "base/output.hh"
54#include "base/pollevent.hh"
55#include "base/statistics.hh"
56#include "base/str.hh"
57#include "base/time.hh"
58#include "cpu/base.hh"
59#include "cpu/smt.hh"
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;

--- 43 unchanged lines hidden (view full) ---

52#include "base/misc.hh"
53#include "base/output.hh"
54#include "base/pollevent.hh"
55#include "base/statistics.hh"
56#include "base/str.hh"
57#include "base/time.hh"
58#include "cpu/base.hh"
59#include "cpu/smt.hh"
60#include "mem/mem_object.hh"
61#include "mem/port.hh"
60#include "sim/async.hh"
61#include "sim/builder.hh"
62#include "sim/async.hh"
63#include "sim/builder.hh"
62#include "sim/configfile.hh"
63#include "sim/host.hh"
64#include "sim/sim_events.hh"
65#include "sim/sim_exit.hh"
66#include "sim/sim_object.hh"
67#include "sim/stat_control.hh"
68#include "sim/stats.hh"
69#include "sim/root.hh"
70

--- 58 unchanged lines hidden (view full) ---

129" -p, --path <path> prepends <path> to PYTHONPATH instead of using\n"
130" built-in zip archive. Useful when developing/debugging\n"
131" changes to built-in Python libraries, as the new Python\n"
132" can be tested without building a new m5 binary.\n\n"
133" -i, --interactive forces entry into interactive mode after the supplied\n"
134" script is executed (just like the -i option to the\n"
135" Python interpreter).\n\n"
136" -h Prints this help\n\n"
64#include "sim/host.hh"
65#include "sim/sim_events.hh"
66#include "sim/sim_exit.hh"
67#include "sim/sim_object.hh"
68#include "sim/stat_control.hh"
69#include "sim/stats.hh"
70#include "sim/root.hh"
71

--- 58 unchanged lines hidden (view full) ---

130" -p, --path <path> prepends <path> to PYTHONPATH instead of using\n"
131" built-in zip archive. Useful when developing/debugging\n"
132" changes to built-in Python libraries, as the new Python\n"
133" can be tested without building a new m5 binary.\n\n"
134" -i, --interactive forces entry into interactive mode after the supplied\n"
135" script is executed (just like the -i option to the\n"
136" Python interpreter).\n\n"
137" -h Prints this help\n\n"
137" <configfile> config file name which ends in .py. (Normally you can\n"
138" run <configfile> --help to get help on that config files\n"
139" parameters.\n\n",
138" <configfile> config file name (ends in .py)\n\n",
140 prog);
141
142}
143
144const char *briefCopyright =
145"Copyright (c) 2001-2006\n"
146"The Regents of The University of Michigan\n"
147"All Rights Reserved\n";

--- 145 unchanged lines hidden (view full) ---

293
294 PyRun_InteractiveLoop(stdin, "stdin");
295 }
296
297 // clean up Python intepreter.
298 Py_Finalize();
299}
300
139 prog);
140
141}
142
143const char *briefCopyright =
144"Copyright (c) 2001-2006\n"
145"The Regents of The University of Michigan\n"
146"All Rights Reserved\n";

--- 145 unchanged lines hidden (view full) ---

292
293 PyRun_InteractiveLoop(stdin, "stdin");
294 }
295
296 // clean up Python intepreter.
297 Py_Finalize();
298}
299
300IniFile inifile;
301
301
302/// Initialize C++ configuration. Exported to Python via SWIG; invoked
303/// from m5.instantiate().
302SimObject *
303createSimObject(const string &name)
304{
305 return SimObjectClass::createObject(inifile, name);
306}
307
308
309/**
310 * Pointer to the Python function that maps names to SimObjects.
311 */
312PyObject *resolveFunc = NULL;
313
314/**
315 * Convert a pointer to the Python object that SWIG wraps around a C++
316 * SimObject pointer back to the actual C++ pointer. See main.i.
317 */
318extern "C" SimObject *convertSwigSimObjectPtr(PyObject *);
319
320
321SimObject *
322resolveSimObject(const string &name)
323{
324 PyObject *pyPtr = PyEval_CallFunction(resolveFunc, "(s)", name.c_str());
325 if (pyPtr == NULL) {
326 PyErr_Print();
327 panic("resolveSimObject: failure on call to Python for %s", name);
328 }
329
330 SimObject *simObj = convertSwigSimObjectPtr(pyPtr);
331 if (simObj == NULL)
332 panic("resolveSimObject: failure on pointer conversion for %s", name);
333
334 return simObj;
335}
336
337
338/**
339 * Load config.ini into C++ database. Exported to Python via SWIG;
340 * invoked from m5.instantiate().
341 */
304void
342void
305initialize()
343loadIniFile(PyObject *_resolveFunc)
306{
344{
345 resolveFunc = _resolveFunc;
307 configStream = simout.find("config.out");
308
309 // The configuration database is now complete; start processing it.
346 configStream = simout.find("config.out");
347
348 // The configuration database is now complete; start processing it.
310 IniFile inifile;
311 inifile.load("config.ini");
312
313 // Initialize statistics database
314 Stats::InitSimStats();
349 inifile.load("config.ini");
350
351 // Initialize statistics database
352 Stats::InitSimStats();
353}
315
354
316 // Now process the configuration hierarchy and create the SimObjects.
317 ConfigHierarchy configHierarchy(inifile);
318 configHierarchy.build();
319 configHierarchy.createSimObjects();
320
355
356/**
357 * Look up a MemObject port. Helper function for connectPorts().
358 */
359Port *
360lookupPort(SimObject *so, const std::string &name, int i)
361{
362 MemObject *mo = dynamic_cast<MemObject *>(so);
363 if (mo == NULL) {
364 warn("error casting SimObject %s to MemObject", so->name());
365 return NULL;
366 }
367
368 Port *p = mo->getPort(name, i);
369 if (p == NULL)
370 warn("error looking up port %s on object %s", name, so->name());
371 return p;
372}
373
374
375/**
376 * Connect the described MemObject ports. Called from Python via SWIG.
377 */
378int
379connectPorts(SimObject *o1, const std::string &name1, int i1,
380 SimObject *o2, const std::string &name2, int i2)
381{
382 Port *p1 = lookupPort(o1, name1, i1);
383 Port *p2 = lookupPort(o2, name2, i2);
384
385 if (p1 == NULL || p2 == NULL) {
386 warn("connectPorts: port lookup error");
387 return 0;
388 }
389
390 p1->setPeer(p2);
391 p2->setPeer(p1);
392
393 return 1;
394}
395
396/**
397 * Do final initialization steps after object construction but before
398 * start of simulation.
399 */
400void
401finalInit()
402{
321 // Parse and check all non-config-hierarchy parameters.
322 ParamContext::parseAllContexts(inifile);
323 ParamContext::checkAllContexts();
324
325 // Echo all parameter settings to stats file as well.
326 ParamContext::showAllContexts(*configStream);
327
403 // Parse and check all non-config-hierarchy parameters.
404 ParamContext::parseAllContexts(inifile);
405 ParamContext::checkAllContexts();
406
407 // Echo all parameter settings to stats file as well.
408 ParamContext::showAllContexts(*configStream);
409
328 // Any objects that can't connect themselves until after construction should
329 // do so now
330 SimObject::connectAll();
331
332 // Do a second pass to finish initializing the sim objects
333 SimObject::initAll();
334
335 // Restore checkpointed state, if any.
410 // Do a second pass to finish initializing the sim objects
411 SimObject::initAll();
412
413 // Restore checkpointed state, if any.
414#if 0
336 configHierarchy.unserializeSimObjects();
415 configHierarchy.unserializeSimObjects();
416#endif
337
417
338 // Done processing the configuration database.
339 // Check for unreferenced entries.
340 if (inifile.printUnreferenced())
341 panic("unreferenced sections/entries in the intermediate ini file");
342
343 SimObject::regAllStats();
344
345 // uncomment the following to get PC-based execution-time profile
346#ifdef DO_PROFILE
347 init_profile((char *)&_init, (char *)&_fini);
348#endif
349
350 // Check to make sure that the stats package is properly initialized

--- 124 unchanged lines hidden ---
418 SimObject::regAllStats();
419
420 // uncomment the following to get PC-based execution-time profile
421#ifdef DO_PROFILE
422 init_profile((char *)&_init, (char *)&_fini);
423#endif
424
425 // Check to make sure that the stats package is properly initialized

--- 124 unchanged lines hidden ---