X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fsim%2Fserialize.hh;h=12b787a5e1e81109c3c0d24690fd373853d975bc;hb=0ed3c84c7b05d7d3c9d5f0e3f1c05c20afef93b9;hp=1eb721cf4f1798674a31587d38bf7bf275a7a3da;hpb=cb0cf2dd8ab1cd60ef13de925ac862268c07297f;p=gem5.git diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh index 1eb721cf4..12b787a5e 100644 --- a/src/sim/serialize.hh +++ b/src/sim/serialize.hh @@ -25,7 +25,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * Authors: Erik Hallnor + * Authors: Nathan Binkert + * Erik Hallnor * Steve Reinhardt */ @@ -37,15 +38,17 @@ #define __SERIALIZE_HH__ -#include #include +#include #include +#include -#include "sim/host.hh" -#include "sim/configfile.hh" +#include "base/types.hh" +class IniFile; class Serializable; class Checkpoint; +class SimObject; template void paramOut(std::ostream &os, const std::string &name, const T ¶m); @@ -54,50 +57,71 @@ 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, unsigned size); + +template +void arrayParamOut(std::ostream &os, const std::string &name, + const std::vector ¶m); + template void arrayParamOut(std::ostream &os, const std::string &name, - const T *param, int size); + const std::list ¶m); 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, + const std::string &name, std::vector ¶m); + +template +void arrayParamIn(Checkpoint *cp, const std::string §ion, + const std::string &name, std::list ¶m); void objParamIn(Checkpoint *cp, const std::string §ion, - const std::string &name, Serializable * ¶m); + const std::string &name, SimObject * ¶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 'cp' and 'section'. -#define SERIALIZE_SCALAR(scalar) paramOut(os, #scalar, scalar) +#define SERIALIZE_SCALAR(scalar) paramOut(os, #scalar, scalar) -#define UNSERIALIZE_SCALAR(scalar) paramIn(cp, section, #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) +#define SERIALIZE_ENUM(scalar) paramOut(os, #scalar, (int)scalar) -#define UNSERIALIZE_ENUM(scalar) \ - do { \ - int tmp; \ - paramIn(cp, section, #scalar, tmp); \ - scalar = (typeof(scalar))tmp; \ +#define UNSERIALIZE_ENUM(scalar) \ + do { \ + int tmp; \ + paramIn(cp, section, #scalar, tmp); \ + scalar = (typeof(scalar))tmp; \ } while (0) -#define SERIALIZE_ARRAY(member, size) \ +#define SERIALIZE_ARRAY(member, size) \ arrayParamOut(os, #member, member, size) -#define UNSERIALIZE_ARRAY(member, size) \ +#define UNSERIALIZE_ARRAY(member, size) \ arrayParamIn(cp, section, #member, member, size) -#define SERIALIZE_OBJPTR(objptr) paramOut(os, #objptr, (objptr)->name()) +#define SERIALIZE_OBJPTR(objptr) paramOut(os, #objptr, (objptr)->name()) -#define UNSERIALIZE_OBJPTR(objptr) \ - do { \ - Serializable *sptr; \ - objParamIn(cp, section, #objptr, sptr); \ - objptr = dynamic_cast(sptr); \ +#define UNSERIALIZE_OBJPTR(objptr) \ + do { \ + SimObject *sptr; \ + objParamIn(cp, section, #objptr, sptr); \ + objptr = dynamic_cast(sptr); \ } while (0) /* @@ -110,22 +134,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(); + static void serializeAll(const std::string &cpt_dir); static void unserializeGlobals(Checkpoint *cp); }; @@ -177,7 +200,7 @@ class SerializableClass // an optional config hierarchy node (specified by the third // argument). A pointer to the new SerializableBuilder is returned. typedef Serializable *(*CreateFunc)(Checkpoint *cp, - const std::string §ion); + const std::string §ion); static std::map *classMap; @@ -191,7 +214,7 @@ class SerializableClass // create Serializable given name of class and pointer to // configuration hierarchy node static Serializable *createObject(Checkpoint *cp, - const std::string §ion); + const std::string §ion); }; // @@ -199,8 +222,8 @@ class SerializableClass // SerializableBuilder and SerializableClass objects // -#define REGISTER_SERIALIZEABLE(CLASS_NAME, OBJ_CLASS) \ -SerializableClass the##OBJ_CLASS##Class(CLASS_NAME, \ +#define REGISTER_SERIALIZEABLE(CLASS_NAME, OBJ_CLASS) \ +SerializableClass the##OBJ_CLASS##Class(CLASS_NAME, \ OBJ_CLASS::createForUnserialize); class Checkpoint @@ -208,13 +231,9 @@ class Checkpoint private: IniFile *db; - const std::string basePath; - const ConfigNode *configNode; - std::map objMap; public: - Checkpoint(const std::string &cpt_dir, const std::string &path, - const ConfigNode *_configNode); + Checkpoint(const std::string &cpt_dir); const std::string cptDir; @@ -222,13 +241,26 @@ class Checkpoint std::string &value); bool findObj(const std::string §ion, const std::string &entry, - Serializable *&value); + SimObject *&value); bool sectionExists(const std::string §ion); // 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 @@ -238,9 +270,6 @@ class Checkpoint // Filename for base checkpoint file within directory. static const char *baseFilename; - - // Set up a checkpoint creation event or series of events. - static void setup(Tick when, Tick period = 0); }; #endif // __SERIALIZE_HH__