1a2,13
> * Copyright (c) 2015 ARM Limited
> * All rights reserved
> *
> * The license below extends only to copyright in the software and shall
> * not be construed as granting a license to any other intellectual
> * property including but not limited to intellectual property relating
> * to a hardware implementation of the functionality of the software
> * licensed hereunder. You may use the software subject to the license
> * terms below provided that you ensure that this notice is replicated
> * unmodified and in its entirety in all distributions of the software,
> * modified or unmodified, in source code or in binary form.
> *
30a43
> * Andreas Sandberg
43a57
> #include <stack>
51c65
< class Checkpoint;
---
> class CheckpointIn;
54a69,71
> typedef std::ostream CheckpointOut;
>
>
65c82
< void paramOut(std::ostream &os, const std::string &name, const T &param);
---
> void paramOut(CheckpointOut &cp, const std::string &name, const T &param);
68c85
< void paramOut(std::ostream &os, const std::string &name,
---
> void paramOut(CheckpointOut &cp, const std::string &name,
71c88
< paramOut(os, name, p.__data);
---
> paramOut(cp, name, p.__data);
75,76c92
< void paramIn(Checkpoint *cp, const std::string &section,
< const std::string &name, T &param);
---
> void paramIn(CheckpointIn &cp, const std::string &name, T &param);
79,80c95
< void paramIn(Checkpoint *cp, const std::string &section,
< const std::string &name,
---
> void paramIn(CheckpointIn &cp, const std::string &name,
83c98
< paramIn(cp, section, name, p.__data);
---
> paramIn(cp, name, p.__data);
87,88c102
< bool optParamIn(Checkpoint *cp, const std::string &section,
< const std::string &name, T &param);
---
> bool optParamIn(CheckpointIn &cp, const std::string &name, T &param);
91,92c105
< bool optParamIn(Checkpoint *cp, const std::string &section,
< const std::string &name,
---
> bool optParamIn(CheckpointIn &cp, const std::string &name,
95c108
< return optParamIn(cp, section, name, p.__data);
---
> return optParamIn(cp, name, p.__data);
99c112
< void arrayParamOut(std::ostream &os, const std::string &name,
---
> void arrayParamOut(CheckpointOut &cp, const std::string &name,
103c116
< void arrayParamOut(std::ostream &os, const std::string &name,
---
> void arrayParamOut(CheckpointOut &cp, const std::string &name,
107c120
< void arrayParamOut(std::ostream &os, const std::string &name,
---
> void arrayParamOut(CheckpointOut &cp, const std::string &name,
111,112c124,125
< void arrayParamIn(Checkpoint *cp, const std::string &section,
< const std::string &name, T *param, unsigned size);
---
> void arrayParamIn(CheckpointIn &cp, const std::string &name,
> T *param, unsigned size);
115,116c128,129
< void arrayParamIn(Checkpoint *cp, const std::string &section,
< const std::string &name, std::vector<T> &param);
---
> void arrayParamIn(CheckpointIn &cp, const std::string &name,
> std::vector<T> &param);
119,120c132,133
< void arrayParamIn(Checkpoint *cp, const std::string &section,
< const std::string &name, std::list<T> &param);
---
> void arrayParamIn(CheckpointIn &cp, const std::string &name,
> std::list<T> &param);
123,124c136
< objParamIn(Checkpoint *cp, const std::string &section,
< const std::string &name, SimObject * &param);
---
> objParamIn(CheckpointIn &cp, const std::string &name, SimObject * &param);
142c154
< #define SERIALIZE_SCALAR(scalar) paramOut(os, #scalar, scalar)
---
> #define SERIALIZE_SCALAR(scalar) paramOut(cp, #scalar, scalar)
144,145c156,157
< #define UNSERIALIZE_SCALAR(scalar) paramIn(cp, section, #scalar, scalar)
< #define UNSERIALIZE_OPT_SCALAR(scalar) optParamIn(cp, section, #scalar, scalar)
---
> #define UNSERIALIZE_SCALAR(scalar) paramIn(cp, #scalar, scalar)
> #define UNSERIALIZE_OPT_SCALAR(scalar) optParamIn(cp, #scalar, scalar)
148c160
< #define SERIALIZE_ENUM(scalar) paramOut(os, #scalar, (int)scalar)
---
> #define SERIALIZE_ENUM(scalar) paramOut(cp, #scalar, (int)scalar)
153,154c165,166
< paramIn(cp, section, #scalar, tmp); \
< fromInt(scalar, tmp); \
---
> paramIn(cp, #scalar, tmp); \
> fromInt(scalar, tmp); \
158c170
< arrayParamOut(os, #member, member, size)
---
> arrayParamOut(cp, #member, member, size)
161c173
< arrayParamIn(cp, section, #member, member, size)
---
> arrayParamIn(cp, #member, member, size)
164c176
< arrayParamOut(os, #member, member)
---
> arrayParamOut(cp, #member, member)
167c179
< arrayParamIn(cp, section, #member, member)
---
> arrayParamIn(cp, #member, member)
169c181
< #define SERIALIZE_OBJPTR(objptr) paramOut(os, #objptr, (objptr)->name())
---
> #define SERIALIZE_OBJPTR(objptr) paramOut(cp, #objptr, (objptr)->name())
174c186
< objParamIn(cp, section, #objptr, sptr); \
---
> objParamIn(cp, #objptr, sptr); \
180a193,213
> * Objects that support serialization should derive from this
> * class. Such objects can largely be divided into two categories: 1)
> * True SimObjects (deriving from SimObject), and 2) child objects
> * (non-SimObjects).
> *
> * SimObjects are serialized automatically into their own sections
> * automatically by the SimObject base class (see
> * SimObject::serializeAll().
> *
> * SimObjects can contain other serializable objects that are not
> * SimObjects. Much like normal serialized members are not serialized
> * automatically, these objects will not be serialized automatically
> * and it is expected that the objects owning such serializable
> * objects call the required serialization/unserialization methods on
> * child objects. The preferred method to serialize a child object is
> * to call serializeSection() on the child, which serializes the
> * object into a new subsection in the current section. Another option
> * is to call serialize() directly, which serializes the object into
> * the current section. The latter is not recommended as it can lead
> * to naming clashes between objects.
> *
190,191c223,246
< void nameOut(std::ostream &os);
< void nameOut(std::ostream &os, const std::string &_name);
---
> /**
> * Scoped checkpoint section helper class
> *
> * This helper class creates a section within a checkpoint without
> * the need for a separate serializeable object. It is mainly used
> * within the Serializable class when serializing or unserializing
> * section (see serializeSection() and unserializeSection()). It
> * can also be used to maintain backwards compatibility in
> * existing code that serializes structs that are not inheriting
> * from Serializable into subsections.
> *
> * When the class is instantiated, it appends a name to the active
> * path in a checkpoint. The old path is later restored when the
> * instance is destroyed. For example, serializeSection() could be
> * implemented by instantiating a ScopedCheckpointSection and then
> * calling serialize() on an object.
> */
> class ScopedCheckpointSection {
> public:
> template<class CP>
> ScopedCheckpointSection(CP &cp, const char *name) {
> pushName(name);
> nameOut(cp);
> }
192a248,268
> template<class CP>
> ScopedCheckpointSection(CP &cp, const std::string &name) {
> pushName(name.c_str());
> nameOut(cp);
> }
>
> ~ScopedCheckpointSection();
>
> ScopedCheckpointSection() = delete;
> ScopedCheckpointSection(const ScopedCheckpointSection &) = delete;
> ScopedCheckpointSection &operator=(
> const ScopedCheckpointSection &) = delete;
> ScopedCheckpointSection &operator=(
> ScopedCheckpointSection &&) = delete;
>
> private:
> void pushName(const char *name);
> void nameOut(CheckpointOut &cp);
> void nameOut(CheckpointIn &cp) {};
> };
>
197,198c273,280
< // manditory virtual function, so objects must provide names
< virtual const std::string name() const = 0;
---
> /**
> * Serialize an object
> *
> * Output an object's state into the current checkpoint section.
> *
> * @param cp Checkpoint state
> */
> virtual void serialize(CheckpointOut &cp) const = 0;
200,201c282,289
< virtual void serialize(std::ostream &os);
< virtual void unserialize(Checkpoint *cp, const std::string &section);
---
> /**
> * Unserialize an object
> *
> * Read an object's state from the current checkpoint section.
> *
> * @param cp Checkpoint state
> */
> virtual void unserialize(CheckpointIn &cp) = 0;
203c291,302
< static Serializable *create(Checkpoint *cp, const std::string &section);
---
> /**
> * Serialize an object into a new section
> *
> * This method creates a new section in a checkpoint and calls
> * serialize() to serialize the current object into that
> * section. The name of the section is appended to the current
> * checkpoint path.
> *
> * @param cp Checkpoint state
> * @param name Name to append to the active path
> */
> void serializeSection(CheckpointOut &cp, const char *name) const;
204a304,354
> void serializeSection(CheckpointOut &cp, const std::string &name) const {
> serializeSection(cp, name.c_str());
> }
>
> /**
> * Unserialize an a child object
> *
> * This method loads a child object from a checkpoint. The object
> * name is appended to the active path to form a fully qualified
> * section name and unserialize() is called.
> *
> * @param cp Checkpoint state
> * @param name Name to append to the active path
> */
> void unserializeSection(CheckpointIn &cp, const char *name);
>
> void unserializeSection(CheckpointIn &cp, const std::string &name) {
> unserializeSection(cp, name.c_str());
> }
>
> /**
> * @{
> * @name Legacy interface
> *
> * Interface for objects that insist on changing their state when
> * serializing. Such state change should be done in drain(),
> * memWriteback(), or memInvalidate() and not in the serialization
> * method. In general, if state changes occur in serialize, it
> * complicates testing since it breaks assumptions about draining
> * and serialization. It potentially also makes components more
> * fragile since they there are no ordering guarantees when
> * serializing SimObjects.
> *
> * @warn This interface is considered deprecated and should never
> * be used.
> */
>
> virtual void serializeOld(CheckpointOut &cp) {
> serialize(cp);
> }
> void serializeSectionOld(CheckpointOut &cp, const char *name);
> void serializeSectionOld(CheckpointOut &cp, const std::string &name) {
> serializeSectionOld(cp, name.c_str());
> }
> /** @} */
>
> /** Get the fully-qualified name of the active section */
> static const std::string &currentSection();
>
> static Serializable *create(CheckpointIn &cp, const std::string &section);
>
209c359,362
< static void unserializeGlobals(Checkpoint *cp);
---
> static void unserializeGlobals(CheckpointIn &cp);
>
> private:
> static std::stack<std::string> path;
261c414
< typedef Serializable *(*CreateFunc)(Checkpoint *cp,
---
> typedef Serializable *(*CreateFunc)(CheckpointIn &cp,
275c428
< static Serializable *createObject(Checkpoint *cp,
---
> static Serializable *createObject(CheckpointIn &cp,
300c453
< class Checkpoint
---
> class CheckpointIn
309,310c462,463
< Checkpoint(const std::string &cpt_dir, SimObjectResolver &resolver);
< ~Checkpoint();
---
> CheckpointIn(const std::string &cpt_dir, SimObjectResolver &resolver);
> ~CheckpointIn();