X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fsim%2Fserialize.hh;h=5ea632ea4b5bdeee7138103b9437dc4f3b967e57;hb=a368fba7d4fa01b58d5c2d9b3cafd56e1102287c;hp=4c5f399e6bfbc1d08a28755915f369aebceac1ec;hpb=3a3e356f4e61e86f6f1427dd85cf1e41fa9125c0;p=gem5.git diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh index 4c5f399e6..5ea632ea4 100644 --- a/src/sim/serialize.hh +++ b/src/sim/serialize.hh @@ -43,7 +43,7 @@ #include #include -#include "sim/host.hh" +#include "base/types.hh" class IniFile; class Serializable; @@ -57,9 +57,13 @@ template void paramIn(Checkpoint *cp, const std::string §ion, const std::string &name, T ¶m); +template +bool optParamIn(Checkpoint *cp, const std::string §ion, + const std::string &name, T ¶m); + template void arrayParamOut(std::ostream &os, const std::string &name, - const T *param, int size); + const T *param, unsigned size); template void arrayParamOut(std::ostream &os, const std::string &name, @@ -67,7 +71,7 @@ void arrayParamOut(std::ostream &os, const std::string &name, template void arrayParamIn(Checkpoint *cp, const std::string §ion, - const std::string &name, T *param, int size); + const std::string &name, T *param, unsigned size); template void arrayParamIn(Checkpoint *cp, const std::string §ion, @@ -85,6 +89,7 @@ objParamIn(Checkpoint *cp, const std::string §ion, #define SERIALIZE_SCALAR(scalar) paramOut(os, #scalar, scalar) #define UNSERIALIZE_SCALAR(scalar) paramIn(cp, section, #scalar, scalar) +#define UNSERIALIZE_OPT_SCALAR(scalar) optParamIn(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) @@ -121,23 +126,21 @@ class Serializable void nameOut(std::ostream &os, const std::string &_name); public: - Serializable() {} - virtual ~Serializable() {} + Serializable(); + virtual ~Serializable(); // manditory virtual function, so objects must provide names virtual const std::string name() const = 0; - virtual void serialize(std::ostream &os) {} - virtual void unserialize(Checkpoint *cp, const std::string §ion) {} + virtual void serialize(std::ostream &os); + virtual void unserialize(Checkpoint *cp, const std::string §ion); - static Serializable *create(Checkpoint *cp, - const std::string §ion); + static Serializable *create(Checkpoint *cp, const std::string §ion); static int ckptCount; static int ckptMaxCount; static int ckptPrevCount; static void serializeAll(const std::string &cpt_dir); - static void unserializeAll(const std::string &cpt_dir); static void unserializeGlobals(Checkpoint *cp); }; @@ -215,19 +218,14 @@ class SerializableClass SerializableClass the##OBJ_CLASS##Class(CLASS_NAME, \ OBJ_CLASS::createForUnserialize); -void -setCheckpointDir(const std::string &name); - class Checkpoint { private: IniFile *db; - const std::string basePath; - std::map objMap; public: - Checkpoint(const std::string &cpt_dir, const std::string &path); + Checkpoint(const std::string &cpt_dir); const std::string cptDir; @@ -241,7 +239,20 @@ class Checkpoint // The following static functions have to do with checkpoint // creation rather than restoration. This class makes a handy - // namespace for them though. + // namespace for them though. Currently no Checkpoint object is + // created on serialization (only unserialization) so we track the + // directory name as a global. It would be nice to change this + // someday + + private: + // current directory we're serializing into. + static std::string currentDirectory; + + public: + // Set the current directory. This function takes care of + // inserting curTick() if there's a '%d' in the argument, and + // appends a '/' if necessary. The final name is returned. + static std::string setDir(const std::string &base_name); // Export current checkpoint directory name so other objects can // derive filenames from it (e.g., memory). The return value is