summaryrefslogtreecommitdiff
path: root/src/sim/main.cc
diff options
context:
space:
mode:
authorSteve Reinhardt <stever@eecs.umich.edu>2006-06-13 23:19:42 -0400
committerSteve Reinhardt <stever@eecs.umich.edu>2006-06-13 23:19:42 -0400
commit185ec39f792386d8b30f3288f2c2e4eaf0b43d02 (patch)
treebd06995cf95f7085d4c328fed2f1cec2aec1a01a /src/sim/main.cc
parent7709e6ba93be4b67b22e2f3f9c853a3e1ab4458b (diff)
parente981a97dec3df921f3800fd9ae5ec01ed4e9d2b1 (diff)
downloadgem5-185ec39f792386d8b30f3288f2c2e4eaf0b43d02.tar.xz
Merge zizzer:/bk/newmem
into vm1.(none):/home/stever/bk/newmem --HG-- extra : convert_revision : 6ebb12890c516a11733a04041f29c9964267a5ca
Diffstat (limited to 'src/sim/main.cc')
-rw-r--r--src/sim/main.cc113
1 files changed, 95 insertions, 18 deletions
diff --git a/src/sim/main.cc b/src/sim/main.cc
index f3b74489d..f63aec9cc 100644
--- a/src/sim/main.cc
+++ b/src/sim/main.cc
@@ -57,9 +57,10 @@
#include "base/time.hh"
#include "cpu/base.hh"
#include "cpu/smt.hh"
+#include "mem/mem_object.hh"
+#include "mem/port.hh"
#include "sim/async.hh"
#include "sim/builder.hh"
-#include "sim/configfile.hh"
#include "sim/host.hh"
#include "sim/sim_events.hh"
#include "sim/sim_exit.hh"
@@ -296,26 +297,109 @@ main(int argc, char **argv)
Py_Finalize();
}
+IniFile inifile;
-/// Initialize C++ configuration. Exported to Python via SWIG; invoked
-/// from m5.instantiate().
+SimObject *
+createSimObject(const string &name)
+{
+ return SimObjectClass::createObject(inifile, name);
+}
+
+
+/**
+ * Pointer to the Python function that maps names to SimObjects.
+ */
+PyObject *resolveFunc = NULL;
+
+/**
+ * Convert a pointer to the Python object that SWIG wraps around a C++
+ * SimObject pointer back to the actual C++ pointer. See main.i.
+ */
+extern "C" SimObject *convertSwigSimObjectPtr(PyObject *);
+
+
+SimObject *
+resolveSimObject(const string &name)
+{
+ PyObject *pyPtr = PyEval_CallFunction(resolveFunc, "(s)", name.c_str());
+ if (pyPtr == NULL) {
+ PyErr_Print();
+ panic("resolveSimObject: failure on call to Python for %s", name);
+ }
+
+ SimObject *simObj = convertSwigSimObjectPtr(pyPtr);
+ if (simObj == NULL)
+ panic("resolveSimObject: failure on pointer conversion for %s", name);
+
+ return simObj;
+}
+
+
+/**
+ * Load config.ini into C++ database. Exported to Python via SWIG;
+ * invoked from m5.instantiate().
+ */
void
-initialize()
+loadIniFile(PyObject *_resolveFunc)
{
+ resolveFunc = _resolveFunc;
configStream = simout.find("config.out");
// The configuration database is now complete; start processing it.
- IniFile inifile;
inifile.load("config.ini");
// Initialize statistics database
Stats::InitSimStats();
+}
+
+
+/**
+ * Look up a MemObject port. Helper function for connectPorts().
+ */
+Port *
+lookupPort(SimObject *so, const std::string &name, int i)
+{
+ MemObject *mo = dynamic_cast<MemObject *>(so);
+ if (mo == NULL) {
+ warn("error casting SimObject %s to MemObject", so->name());
+ return NULL;
+ }
+
+ Port *p = mo->getPort(name, i);
+ if (p == NULL)
+ warn("error looking up port %s on object %s", name, so->name());
+ return p;
+}
- // Now process the configuration hierarchy and create the SimObjects.
- ConfigHierarchy configHierarchy(inifile);
- configHierarchy.build();
- configHierarchy.createSimObjects();
+/**
+ * Connect the described MemObject ports. Called from Python via SWIG.
+ */
+int
+connectPorts(SimObject *o1, const std::string &name1, int i1,
+ SimObject *o2, const std::string &name2, int i2)
+{
+ Port *p1 = lookupPort(o1, name1, i1);
+ Port *p2 = lookupPort(o2, name2, i2);
+
+ if (p1 == NULL || p2 == NULL) {
+ warn("connectPorts: port lookup error");
+ return 0;
+ }
+
+ p1->setPeer(p2);
+ p2->setPeer(p1);
+
+ return 1;
+}
+
+/**
+ * Do final initialization steps after object construction but before
+ * start of simulation.
+ */
+void
+finalInit()
+{
// Parse and check all non-config-hierarchy parameters.
ParamContext::parseAllContexts(inifile);
ParamContext::checkAllContexts();
@@ -323,20 +407,13 @@ initialize()
// Echo all parameter settings to stats file as well.
ParamContext::showAllContexts(*configStream);
- // Any objects that can't connect themselves until after construction should
- // do so now
- SimObject::connectAll();
-
// Do a second pass to finish initializing the sim objects
SimObject::initAll();
// Restore checkpointed state, if any.
+#if 0
configHierarchy.unserializeSimObjects();
-
- // Done processing the configuration database.
- // Check for unreferenced entries.
- if (inifile.printUnreferenced())
- panic("unreferenced sections/entries in the intermediate ini file");
+#endif
SimObject::regAllStats();