summaryrefslogtreecommitdiff
path: root/sim/serialize.cc
diff options
context:
space:
mode:
authorSteve Reinhardt <stever@eecs.umich.edu>2003-10-29 21:45:39 -0800
committerSteve Reinhardt <stever@eecs.umich.edu>2003-10-29 21:45:39 -0800
commit5a1eb9049d16d37448282362529d462d73558181 (patch)
treefb1d5a05dad6869173a352abb16ddca7b3a1667f /sim/serialize.cc
parent976429121c7fddbf8de18b2a347a53546fe14264 (diff)
downloadgem5-5a1eb9049d16d37448282362529d462d73558181.tar.xz
Support for Serializable non-SimObject things like events.
Can now serialize & unserialize DmaRequestEvents and DmaTransferEvents. Also support serialize/unserialize of pointers to SimObjects and other Serializable objects. arch/alpha/alpha_memory.cc: arch/alpha/alpha_memory.hh: arch/alpha/isa_traits.hh: cpu/exec_context.cc: cpu/exec_context.hh: cpu/simple_cpu/simple_cpu.hh: dev/alpha_access.h: dev/alpha_console.cc: dev/alpha_console.hh: dev/console.cc: dev/console.hh: unserialize() now takes a Checkpoint* instead of an IniFile*. cpu/simple_cpu/simple_cpu.cc: unserialize() now takes a Checkpoint* instead of an IniFile*. Put ExecContext in its own section so its _status fields doesn't conflict. sim/eventq.cc: sim/eventq.hh: unserialize() now takes a Checkpoint* instead of an IniFile*. Events get serialized by the event queue only if they're marked as AutoSerialize... others are assumed to be serialized by something else (e.g. an owning SimObject) or to not matter. sim/param.cc: Shift 'const' in case T is a ptr type. sim/serialize.cc: sim/serialize.hh: Define Checkpoint object to encapsulate everything you need to know about a checkpoint. Use it to allow lookups of named Serializable objects (and SimObjects) during unserialization. unserialize() now takes a Checkpoint* instead of an IniFile*. --HG-- extra : convert_revision : 8e6baab32405f8f548bb67a097b2f713296537a5
Diffstat (limited to 'sim/serialize.cc')
-rw-r--r--sim/serialize.cc108
1 files changed, 76 insertions, 32 deletions
diff --git a/sim/serialize.cc b/sim/serialize.cc
index f838acc8d..dfd495a32 100644
--- a/sim/serialize.cc
+++ b/sim/serialize.cc
@@ -43,6 +43,7 @@
#include "sim/sim_events.hh"
#include "sim/sim_object.hh"
#include "base/trace.hh"
+#include "sim/config_node.hh"
using namespace std;
@@ -88,11 +89,11 @@ paramOut(ostream &os, const std::string &name, const T& param)
template <class T>
void
-paramIn(const IniFile *db, const std::string &section,
+paramIn(Checkpoint *cp, const std::string &section,
const std::string &name, T& param)
{
std::string str;
- if (!db->find(section, name, str) || !parseParam(str, param)) {
+ if (!cp->find(section, name, str) || !parseParam(str, param)) {
fatal("Can't unserialize '%s:%s'\n", section, name);
}
}
@@ -116,11 +117,11 @@ arrayParamOut(ostream &os, const std::string &name,
template <class T>
void
-arrayParamIn(const IniFile *db, const std::string &section,
+arrayParamIn(Checkpoint *cp, const std::string &section,
const std::string &name, T *param, int size)
{
std::string str;
- if (!db->find(section, name, str)) {
+ if (!cp->find(section, name, str)) {
fatal("Can't unserialize '%s:%s'\n", section, name);
}
@@ -159,17 +160,27 @@ arrayParamIn(const IniFile *db, const std::string &section,
}
+void
+objParamIn(Checkpoint *cp, const std::string &section,
+ const std::string &name, Serializeable * &param)
+{
+ if (!cp->findObj(section, name, param)) {
+ fatal("Can't unserialize '%s:%s'\n", section, name);
+ }
+}
+
+
#define INSTANTIATE_PARAM_TEMPLATES(type) \
template void \
-paramOut(ostream &os, const std::string &name, const type &param); \
+paramOut(ostream &os, const std::string &name, type const &param); \
template void \
-paramIn(const IniFile *db, const std::string &section, \
+paramIn(Checkpoint *cp, const std::string &section, \
const std::string &name, type & param); \
template void \
arrayParamOut(ostream &os, const std::string &name, \
- const type *param, int size); \
+ type const *param, int size); \
template void \
-arrayParamIn(const IniFile *db, const std::string &section, \
+arrayParamIn(Checkpoint *cp, const std::string &section, \
const std::string &name, type *param, int size);
@@ -421,41 +432,74 @@ SerializeableClass::SerializeableClass(const string &className,
//
//
Serializeable *
-SerializeableClass::createObject(IniFile &configDB,
- const string &configClassName)
+SerializeableClass::createObject(Checkpoint *cp,
+ const std::string &section)
{
- // find simulation object class name from configuration class
- // (specified by 'type=' parameter)
- string simObjClassName;
+ string className;
- if (!configDB.findDefault(configClassName, "type", simObjClassName)) {
- cerr << "Configuration class '" << configClassName << "' not found."
- << endl;
- abort();
+ if (!cp->find(section, "type", className)) {
+ fatal("Serializeable::create: no 'type' entry in section '%s'.\n",
+ section);
}
- // look up className to get appropriate createFunc
- if (classMap->find(simObjClassName) == classMap->end()) {
- cerr << "Simulator object class '" << simObjClassName << "' not found."
- << endl;
- abort();
+ CreateFunc createFunc = (*classMap)[className];
+
+ if (createFunc == NULL) {
+ fatal("Serializeable::create: no create function for class '%s'.\n",
+ className);
}
- CreateFunc createFunc = (*classMap)[simObjClassName];
+ Serializeable *object = createFunc(cp, section);
- // builder instance
- SerializeableBuilder *objectBuilder = (*createFunc)();
+ assert(object != NULL);
- assert(objectBuilder != NULL);
+ return object;
+}
- // now create the actual simulation object
- Serializeable *object = objectBuilder->create();
- assert(object != NULL);
+Serializeable *
+Serializeable::create(Checkpoint *cp, const std::string &section)
+{
+ Serializeable *object = SerializeableClass::createObject(cp, section);
+ object->unserialize(cp, section);
+ return object;
+}
- // done with the SerializeableBuilder now
- delete objectBuilder;
- return object;
+Checkpoint::Checkpoint(const std::string &filename, const std::string &path,
+ const ConfigNode *_configNode)
+ : db(new IniFile), basePath(path), configNode(_configNode)
+{
+ if (!db->load(filename)) {
+ fatal("Can't load checkpoint file '%s'\n", filename);
+ }
+
+ mainEventQueue.unserialize(this, "MainEventQueue");
+}
+
+
+bool
+Checkpoint::find(const std::string &section, const std::string &entry,
+ std::string &value)
+{
+ return db->find(section, entry, value);
}
+
+bool
+Checkpoint::findObj(const std::string &section, const std::string &entry,
+ Serializeable *&value)
+{
+ string path;
+
+ if (!db->find(section, entry, path))
+ return false;
+
+ if ((value = configNode->resolveSimObject(path)) != NULL)
+ return true;
+
+ if ((value = objMap[path]) != NULL)
+ return true;
+
+ return false;
+}