diff options
author | Steve Reinhardt <stever@eecs.umich.edu> | 2003-10-29 21:45:39 -0800 |
---|---|---|
committer | Steve Reinhardt <stever@eecs.umich.edu> | 2003-10-29 21:45:39 -0800 |
commit | 5a1eb9049d16d37448282362529d462d73558181 (patch) | |
tree | fb1d5a05dad6869173a352abb16ddca7b3a1667f /sim/serialize.hh | |
parent | 976429121c7fddbf8de18b2a347a53546fe14264 (diff) | |
download | gem5-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.hh')
-rw-r--r-- | sim/serialize.hh | 88 |
1 files changed, 53 insertions, 35 deletions
diff --git a/sim/serialize.hh b/sim/serialize.hh index 4e0dbd1bd..b615e6527 100644 --- a/sim/serialize.hh +++ b/sim/serialize.hh @@ -41,13 +41,14 @@ #include "sim/host.hh" #include "sim/configfile.hh" -class IniFile; +class Serializeable; +class Checkpoint; template <class T> void paramOut(std::ostream &os, const std::string &name, const T& param); template <class T> -void paramIn(const IniFile *db, const std::string §ion, +void paramIn(Checkpoint *cp, const std::string §ion, const std::string &name, T& param); template <class T> @@ -55,16 +56,21 @@ void arrayParamOut(std::ostream &os, const std::string &name, const T *param, int size); template <class T> -void arrayParamIn(const IniFile *db, const std::string §ion, +void arrayParamIn(Checkpoint *cp, const std::string §ion, const std::string &name, T *param, int size); +void +objParamIn(Checkpoint *cp, const std::string §ion, + const std::string &name, Serializeable * ¶m); + + // // These macros are streamlined to use in serialize/unserialize // functions. It's assumed that serialize() has a parameter 'os' for -// the ostream, and unserialize() has parameters 'db' and 'section'. +// the ostream, and unserialize() has parameters 'cp' and 'section'. #define SERIALIZE_SCALAR(scalar) paramOut(os, #scalar, scalar) -#define UNSERIALIZE_SCALAR(scalar) paramIn(db, section, #scalar, scalar) +#define UNSERIALIZE_SCALAR(scalar) paramIn(cp, section, #scalar, scalar) // ENUMs are like SCALARs, but we cast them to ints on the way out #define SERIALIZE_ENUM(scalar) paramOut(os, #scalar, (int)scalar) @@ -72,7 +78,7 @@ void arrayParamIn(const IniFile *db, const std::string §ion, #define UNSERIALIZE_ENUM(scalar) \ do { \ int tmp; \ - paramIn(db, section, #scalar, tmp); \ + paramIn(cp, section, #scalar, tmp); \ scalar = (typeof(scalar))tmp; \ } while (0) @@ -80,7 +86,16 @@ void arrayParamIn(const IniFile *db, const std::string §ion, arrayParamOut(os, #member, member, size) #define UNSERIALIZE_ARRAY(member, size) \ - arrayParamIn(db, section, #member, member, size) + arrayParamIn(cp, section, #member, member, size) + +#define SERIALIZE_OBJPTR(objptr) paramOut(os, #objptr, (objptr)->name()) + +#define UNSERIALIZE_OBJPTR(objptr) \ + do { \ + Serializeable *sptr; \ + objParamIn(cp, section, #objptr, sptr); \ + objptr = dynamic_cast<typeof(objptr)>(sptr); \ + } while (0) /* * Basic support for object serialization. @@ -113,7 +128,10 @@ class Serializeable virtual void nameChildren() {} virtual void serialize(std::ostream& os) {} - virtual void unserialize(const IniFile *db, const std::string §ion) {} + virtual void unserialize(Checkpoint *cp, const std::string §ion) {} + + static Serializeable *create(Checkpoint *cp, + const std::string §ion); }; class Serializer @@ -187,7 +205,8 @@ class SerializeableClass // for the object (specified by the second string argument), and // an optional config hierarchy node (specified by the third // argument). A pointer to the new SerializeableBuilder is returned. - typedef SerializeableBuilder *(*CreateFunc)(); + typedef Serializeable *(*CreateFunc)(Checkpoint *cp, + const std::string §ion); static std::map<std::string,CreateFunc> *classMap; @@ -200,9 +219,8 @@ class SerializeableClass // create Serializeable given name of class and pointer to // configuration hierarchy node - static Serializeable *createObject(IniFile &configDB, - const std::string &configClassName); - + static Serializeable *createObject(Checkpoint *cp, + const std::string §ion); }; // @@ -210,29 +228,29 @@ class SerializeableClass // SerializeableBuilder and SerializeableClass objects // -#define CREATE_SERIALIZEABLE(OBJ_CLASS) \ -OBJ_CLASS *OBJ_CLASS##Builder::create() - -#define REGISTER_SERIALIZEABLE(CLASS_NAME, OBJ_CLASS) \ -class OBJ_CLASS##Builder : public SerializeableBuilder \ -{ \ - public: \ - \ - OBJ_CLASS##Builder() {} \ - virtual ~OBJ_CLASS##Builder() {} \ - \ - OBJ_CLASS *create(); \ -}; \ - \ - \ -SerializeableBuilder * \ -new##OBJ_CLASS##Builder() \ -{ \ - return new OBJ_CLASS##Builder(); \ -} \ - \ -SerializeableClass the##OBJ_CLASS##Class(CLASS_NAME, \ - new##OBJ_CLASS##Builder); +#define REGISTER_SERIALIZEABLE(CLASS_NAME, OBJ_CLASS) \ +SerializeableClass the##OBJ_CLASS##Class(CLASS_NAME, \ + OBJ_CLASS::createForUnserialize); + +class Checkpoint +{ + private: + + IniFile *db; + const std::string basePath; + const ConfigNode *configNode; + std::map<std::string, Serializeable*> objMap; + + public: + Checkpoint(const std::string &filename, const std::string &path, + const ConfigNode *_configNode); + + bool find(const std::string §ion, const std::string &entry, + std::string &value); + + bool findObj(const std::string §ion, const std::string &entry, + Serializeable *&value); +}; // |