serialize.hh revision 12452
12SN/A/*
210905Sandreas.sandberg@arm.com * Copyright (c) 2015 ARM Limited
310905Sandreas.sandberg@arm.com * All rights reserved
410905Sandreas.sandberg@arm.com *
510905Sandreas.sandberg@arm.com * The license below extends only to copyright in the software and shall
610905Sandreas.sandberg@arm.com * not be construed as granting a license to any other intellectual
710905Sandreas.sandberg@arm.com * property including but not limited to intellectual property relating
810905Sandreas.sandberg@arm.com * to a hardware implementation of the functionality of the software
910905Sandreas.sandberg@arm.com * licensed hereunder.  You may use the software subject to the license
1010905Sandreas.sandberg@arm.com * terms below provided that you ensure that this notice is replicated
1110905Sandreas.sandberg@arm.com * unmodified and in its entirety in all distributions of the software,
1210905Sandreas.sandberg@arm.com * modified or unmodified, in source code or in binary form.
1310905Sandreas.sandberg@arm.com *
141762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
152SN/A * All rights reserved.
162SN/A *
172SN/A * Redistribution and use in source and binary forms, with or without
182SN/A * modification, are permitted provided that the following conditions are
192SN/A * met: redistributions of source code must retain the above copyright
202SN/A * notice, this list of conditions and the following disclaimer;
212SN/A * redistributions in binary form must reproduce the above copyright
222SN/A * notice, this list of conditions and the following disclaimer in the
232SN/A * documentation and/or other materials provided with the distribution;
242SN/A * neither the name of the copyright holders nor the names of its
252SN/A * contributors may be used to endorse or promote products derived from
262SN/A * this software without specific prior written permission.
272SN/A *
282SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392665Ssaidi@eecs.umich.edu *
402760Sbinkertn@umich.edu * Authors: Nathan Binkert
412760Sbinkertn@umich.edu *          Erik Hallnor
422665Ssaidi@eecs.umich.edu *          Steve Reinhardt
4310905Sandreas.sandberg@arm.com *          Andreas Sandberg
442SN/A */
452SN/A
462SN/A/* @file
472SN/A * Serialization Interface Declarations
482SN/A */
492SN/A
502SN/A#ifndef __SERIALIZE_HH__
512SN/A#define __SERIALIZE_HH__
522SN/A
532SN/A
548229Snate@binkert.org#include <iostream>
552SN/A#include <list>
568229Snate@binkert.org#include <map>
5710905Sandreas.sandberg@arm.com#include <stack>
5811076SCurtis.Dunham@arm.com#include <set>
594841Ssaidi@eecs.umich.edu#include <vector>
602SN/A
6110459SAndreas.Sandberg@ARM.com#include "base/bitunion.hh"
622SN/A
6311800Sbrandon.potter@amd.comclass CheckpointIn;
642738Sstever@eecs.umich.educlass IniFile;
65395SN/Aclass Serializable;
664000Ssaidi@eecs.umich.educlass SimObject;
6711067Sandreas.sandberg@arm.comclass SimObjectResolver;
682SN/A
6910905Sandreas.sandberg@arm.comtypedef std::ostream CheckpointOut;
7010905Sandreas.sandberg@arm.com
7110905Sandreas.sandberg@arm.com
72217SN/Atemplate <class T>
7310905Sandreas.sandberg@arm.comvoid paramOut(CheckpointOut &cp, const std::string &name, const T &param);
74217SN/A
7512452Sgabeblack@google.comtemplate <typename T>
7612452Sgabeblack@google.comvoid
7712452Sgabeblack@google.comparamOut(CheckpointOut &cp, const std::string &name, const BitUnionType<T> &p)
7810459SAndreas.Sandberg@ARM.com{
7912452Sgabeblack@google.com    paramOut(cp, name, static_cast<BitUnionBaseType<T> >(p));
8010459SAndreas.Sandberg@ARM.com}
8110459SAndreas.Sandberg@ARM.com
82217SN/Atemplate <class T>
8310905Sandreas.sandberg@arm.comvoid paramIn(CheckpointIn &cp, const std::string &name, T &param);
84217SN/A
8512452Sgabeblack@google.comtemplate <typename T>
8612452Sgabeblack@google.comvoid
8712452Sgabeblack@google.comparamIn(CheckpointIn &cp, const std::string &name, BitUnionType<T> &p)
8810459SAndreas.Sandberg@ARM.com{
8912452Sgabeblack@google.com    BitUnionBaseType<T> b;
9012452Sgabeblack@google.com    paramIn(cp, name, b);
9112452Sgabeblack@google.com    p = b;
9210459SAndreas.Sandberg@ARM.com}
9310459SAndreas.Sandberg@ARM.com
94217SN/Atemplate <class T>
9511075SCurtis.Dunham@arm.combool optParamIn(CheckpointIn &cp, const std::string &name, T &param,
9611075SCurtis.Dunham@arm.com                bool warn = true);
976820SLisa.Hsu@amd.com
9812452Sgabeblack@google.comtemplate <typename T>
9912452Sgabeblack@google.combool
10012452Sgabeblack@google.comoptParamIn(CheckpointIn &cp, const std::string &name,
10112452Sgabeblack@google.com           BitUnionType<T> &p, bool warn = true)
10210459SAndreas.Sandberg@ARM.com{
10312452Sgabeblack@google.com    BitUnionBaseType<T> b;
10412452Sgabeblack@google.com    if (optParamIn(cp, name, b, warn)) {
10512452Sgabeblack@google.com        p = b;
10612452Sgabeblack@google.com        return true;
10712452Sgabeblack@google.com    } else {
10812452Sgabeblack@google.com        return false;
10912452Sgabeblack@google.com    }
11010459SAndreas.Sandberg@ARM.com}
11110459SAndreas.Sandberg@ARM.com
1126820SLisa.Hsu@amd.comtemplate <class T>
11310905Sandreas.sandberg@arm.comvoid arrayParamOut(CheckpointOut &cp, const std::string &name,
1146227Snate@binkert.org                   const T *param, unsigned size);
115217SN/A
116217SN/Atemplate <class T>
11710905Sandreas.sandberg@arm.comvoid arrayParamOut(CheckpointOut &cp, const std::string &name,
1184841Ssaidi@eecs.umich.edu                   const std::vector<T> &param);
1194841Ssaidi@eecs.umich.edu
1204841Ssaidi@eecs.umich.edutemplate <class T>
12110905Sandreas.sandberg@arm.comvoid arrayParamOut(CheckpointOut &cp, const std::string &name,
1227948SAli.Saidi@ARM.com                   const std::list<T> &param);
1237948SAli.Saidi@ARM.com
1247948SAli.Saidi@ARM.comtemplate <class T>
12511076SCurtis.Dunham@arm.comvoid arrayParamOut(CheckpointOut &cp, const std::string &name,
12611076SCurtis.Dunham@arm.com                   const std::set<T> &param);
12711076SCurtis.Dunham@arm.com
12811076SCurtis.Dunham@arm.comtemplate <class T>
12910905Sandreas.sandberg@arm.comvoid arrayParamIn(CheckpointIn &cp, const std::string &name,
13010905Sandreas.sandberg@arm.com                  T *param, unsigned size);
131217SN/A
1324841Ssaidi@eecs.umich.edutemplate <class T>
13310905Sandreas.sandberg@arm.comvoid arrayParamIn(CheckpointIn &cp, const std::string &name,
13410905Sandreas.sandberg@arm.com                  std::vector<T> &param);
1354841Ssaidi@eecs.umich.edu
1367948SAli.Saidi@ARM.comtemplate <class T>
13710905Sandreas.sandberg@arm.comvoid arrayParamIn(CheckpointIn &cp, const std::string &name,
13810905Sandreas.sandberg@arm.com                  std::list<T> &param);
1397948SAli.Saidi@ARM.com
14011076SCurtis.Dunham@arm.comtemplate <class T>
14111076SCurtis.Dunham@arm.comvoid arrayParamIn(CheckpointIn &cp, const std::string &name,
14211076SCurtis.Dunham@arm.com                  std::set<T> &param);
14311076SCurtis.Dunham@arm.com
144237SN/Avoid
14510905Sandreas.sandberg@arm.comobjParamIn(CheckpointIn &cp, const std::string &name, SimObject * &param);
146237SN/A
147217SN/A//
148217SN/A// These macros are streamlined to use in serialize/unserialize
149217SN/A// functions.  It's assumed that serialize() has a parameter 'os' for
150237SN/A// the ostream, and unserialize() has parameters 'cp' and 'section'.
15110905Sandreas.sandberg@arm.com#define SERIALIZE_SCALAR(scalar)        paramOut(cp, #scalar, scalar)
152217SN/A
15310905Sandreas.sandberg@arm.com#define UNSERIALIZE_SCALAR(scalar)      paramIn(cp, #scalar, scalar)
15410905Sandreas.sandberg@arm.com#define UNSERIALIZE_OPT_SCALAR(scalar)      optParamIn(cp, #scalar, scalar)
155217SN/A
156223SN/A// ENUMs are like SCALARs, but we cast them to ints on the way out
15710905Sandreas.sandberg@arm.com#define SERIALIZE_ENUM(scalar)          paramOut(cp, #scalar, (int)scalar)
158223SN/A
15911068Sandreas.sandberg@arm.com#define UNSERIALIZE_ENUM(scalar)                        \
16011068Sandreas.sandberg@arm.com    do {                                                \
16111068Sandreas.sandberg@arm.com        int tmp;                                        \
16211068Sandreas.sandberg@arm.com        paramIn(cp, #scalar, tmp);                      \
16311068Sandreas.sandberg@arm.com        scalar = static_cast<decltype(scalar)>(tmp);    \
16411068Sandreas.sandberg@arm.com    } while (0)
165223SN/A
1665543Ssaidi@eecs.umich.edu#define SERIALIZE_ARRAY(member, size)           \
16710905Sandreas.sandberg@arm.com        arrayParamOut(cp, #member, member, size)
168217SN/A
1695543Ssaidi@eecs.umich.edu#define UNSERIALIZE_ARRAY(member, size)         \
17010905Sandreas.sandberg@arm.com        arrayParamIn(cp, #member, member, size)
171237SN/A
17210903Sandreas.sandberg@arm.com#define SERIALIZE_CONTAINER(member)             \
17310905Sandreas.sandberg@arm.com        arrayParamOut(cp, #member, member)
17410903Sandreas.sandberg@arm.com
17510903Sandreas.sandberg@arm.com#define UNSERIALIZE_CONTAINER(member)           \
17610905Sandreas.sandberg@arm.com        arrayParamIn(cp, #member, member)
17710903Sandreas.sandberg@arm.com
17810906Sandreas.sandberg@arm.com#define SERIALIZE_EVENT(event) event.serializeSection(cp, #event);
17910906Sandreas.sandberg@arm.com
18010906Sandreas.sandberg@arm.com#define UNSERIALIZE_EVENT(event)                        \
18110906Sandreas.sandberg@arm.com    do {                                                \
18210906Sandreas.sandberg@arm.com        event.unserializeSection(cp, #event);           \
18310906Sandreas.sandberg@arm.com        eventQueue()->checkpointReschedule(&event);     \
18411321Ssteve.reinhardt@amd.com    } while (0)
18510906Sandreas.sandberg@arm.com
18610908Sandreas.sandberg@arm.com#define SERIALIZE_OBJ(obj) obj.serializeSection(cp, #obj)
18710908Sandreas.sandberg@arm.com#define UNSERIALIZE_OBJ(obj) obj.unserializeSection(cp, #obj)
18810906Sandreas.sandberg@arm.com
18910905Sandreas.sandberg@arm.com#define SERIALIZE_OBJPTR(objptr)        paramOut(cp, #objptr, (objptr)->name())
190237SN/A
1915543Ssaidi@eecs.umich.edu#define UNSERIALIZE_OBJPTR(objptr)                      \
19211068Sandreas.sandberg@arm.com    do {                                                \
19311068Sandreas.sandberg@arm.com        SimObject *sptr;                                \
19411068Sandreas.sandberg@arm.com        objParamIn(cp, #objptr, sptr);                  \
19511068Sandreas.sandberg@arm.com        objptr = dynamic_cast<decltype(objptr)>(sptr);  \
19611068Sandreas.sandberg@arm.com    } while (0)
197217SN/A
1989342SAndreas.Sandberg@arm.com/**
1992SN/A * Basic support for object serialization.
2009342SAndreas.Sandberg@arm.com *
20110905Sandreas.sandberg@arm.com * Objects that support serialization should derive from this
20210905Sandreas.sandberg@arm.com * class. Such objects can largely be divided into two categories: 1)
20310905Sandreas.sandberg@arm.com * True SimObjects (deriving from SimObject), and 2) child objects
20410905Sandreas.sandberg@arm.com * (non-SimObjects).
20510905Sandreas.sandberg@arm.com *
20610905Sandreas.sandberg@arm.com * SimObjects are serialized automatically into their own sections
20710905Sandreas.sandberg@arm.com * automatically by the SimObject base class (see
20810905Sandreas.sandberg@arm.com * SimObject::serializeAll().
20910905Sandreas.sandberg@arm.com *
21010905Sandreas.sandberg@arm.com * SimObjects can contain other serializable objects that are not
21110905Sandreas.sandberg@arm.com * SimObjects. Much like normal serialized members are not serialized
21210905Sandreas.sandberg@arm.com * automatically, these objects will not be serialized automatically
21310905Sandreas.sandberg@arm.com * and it is expected that the objects owning such serializable
21410905Sandreas.sandberg@arm.com * objects call the required serialization/unserialization methods on
21510905Sandreas.sandberg@arm.com * child objects. The preferred method to serialize a child object is
21610905Sandreas.sandberg@arm.com * to call serializeSection() on the child, which serializes the
21710905Sandreas.sandberg@arm.com * object into a new subsection in the current section. Another option
21810905Sandreas.sandberg@arm.com * is to call serialize() directly, which serializes the object into
21910905Sandreas.sandberg@arm.com * the current section. The latter is not recommended as it can lead
22010905Sandreas.sandberg@arm.com * to naming clashes between objects.
22110905Sandreas.sandberg@arm.com *
2229342SAndreas.Sandberg@arm.com * @note Many objects that support serialization need to be put in a
2239342SAndreas.Sandberg@arm.com * consistent state when serialization takes place. We refer to the
2249342SAndreas.Sandberg@arm.com * action of forcing an object into a consistent state as
2259342SAndreas.Sandberg@arm.com * 'draining'. Objects that need draining inherit from Drainable. See
2269342SAndreas.Sandberg@arm.com * Drainable for more information.
2272SN/A */
228395SN/Aclass Serializable
2292SN/A{
2302SN/A  protected:
23110905Sandreas.sandberg@arm.com    /**
23210905Sandreas.sandberg@arm.com     * Scoped checkpoint section helper class
23310905Sandreas.sandberg@arm.com     *
23410905Sandreas.sandberg@arm.com     * This helper class creates a section within a checkpoint without
23510905Sandreas.sandberg@arm.com     * the need for a separate serializeable object. It is mainly used
23610905Sandreas.sandberg@arm.com     * within the Serializable class when serializing or unserializing
23710905Sandreas.sandberg@arm.com     * section (see serializeSection() and unserializeSection()). It
23810905Sandreas.sandberg@arm.com     * can also be used to maintain backwards compatibility in
23910905Sandreas.sandberg@arm.com     * existing code that serializes structs that are not inheriting
24010905Sandreas.sandberg@arm.com     * from Serializable into subsections.
24110905Sandreas.sandberg@arm.com     *
24210905Sandreas.sandberg@arm.com     * When the class is instantiated, it appends a name to the active
24310905Sandreas.sandberg@arm.com     * path in a checkpoint. The old path is later restored when the
24410905Sandreas.sandberg@arm.com     * instance is destroyed. For example, serializeSection() could be
24510905Sandreas.sandberg@arm.com     * implemented by instantiating a ScopedCheckpointSection and then
24610905Sandreas.sandberg@arm.com     * calling serialize() on an object.
24710905Sandreas.sandberg@arm.com     */
24810905Sandreas.sandberg@arm.com    class ScopedCheckpointSection {
24910905Sandreas.sandberg@arm.com      public:
25010905Sandreas.sandberg@arm.com        template<class CP>
25110905Sandreas.sandberg@arm.com        ScopedCheckpointSection(CP &cp, const char *name) {
25210905Sandreas.sandberg@arm.com            pushName(name);
25310905Sandreas.sandberg@arm.com            nameOut(cp);
25410905Sandreas.sandberg@arm.com        }
25510905Sandreas.sandberg@arm.com
25610905Sandreas.sandberg@arm.com        template<class CP>
25710905Sandreas.sandberg@arm.com        ScopedCheckpointSection(CP &cp, const std::string &name) {
25810905Sandreas.sandberg@arm.com            pushName(name.c_str());
25910905Sandreas.sandberg@arm.com            nameOut(cp);
26010905Sandreas.sandberg@arm.com        }
26110905Sandreas.sandberg@arm.com
26210905Sandreas.sandberg@arm.com        ~ScopedCheckpointSection();
26310905Sandreas.sandberg@arm.com
26410905Sandreas.sandberg@arm.com        ScopedCheckpointSection() = delete;
26510905Sandreas.sandberg@arm.com        ScopedCheckpointSection(const ScopedCheckpointSection &) = delete;
26610905Sandreas.sandberg@arm.com        ScopedCheckpointSection &operator=(
26710905Sandreas.sandberg@arm.com            const ScopedCheckpointSection &) = delete;
26810905Sandreas.sandberg@arm.com        ScopedCheckpointSection &operator=(
26910905Sandreas.sandberg@arm.com            ScopedCheckpointSection &&) = delete;
27010905Sandreas.sandberg@arm.com
27110905Sandreas.sandberg@arm.com      private:
27210905Sandreas.sandberg@arm.com        void pushName(const char *name);
27310905Sandreas.sandberg@arm.com        void nameOut(CheckpointOut &cp);
27410905Sandreas.sandberg@arm.com        void nameOut(CheckpointIn &cp) {};
27510905Sandreas.sandberg@arm.com    };
2762SN/A
2772SN/A  public:
2785739Snate@binkert.org    Serializable();
2795739Snate@binkert.org    virtual ~Serializable();
2802SN/A
28110905Sandreas.sandberg@arm.com    /**
28210905Sandreas.sandberg@arm.com     * Serialize an object
28310905Sandreas.sandberg@arm.com     *
28410905Sandreas.sandberg@arm.com     * Output an object's state into the current checkpoint section.
28510905Sandreas.sandberg@arm.com     *
28610905Sandreas.sandberg@arm.com     * @param cp Checkpoint state
28710905Sandreas.sandberg@arm.com     */
28810905Sandreas.sandberg@arm.com    virtual void serialize(CheckpointOut &cp) const = 0;
2892SN/A
29010905Sandreas.sandberg@arm.com    /**
29110905Sandreas.sandberg@arm.com     * Unserialize an object
29210905Sandreas.sandberg@arm.com     *
29310905Sandreas.sandberg@arm.com     * Read an object's state from the current checkpoint section.
29410905Sandreas.sandberg@arm.com     *
29510905Sandreas.sandberg@arm.com     * @param cp Checkpoint state
29610905Sandreas.sandberg@arm.com     */
29710905Sandreas.sandberg@arm.com    virtual void unserialize(CheckpointIn &cp) = 0;
298237SN/A
29910905Sandreas.sandberg@arm.com    /**
30010905Sandreas.sandberg@arm.com     * Serialize an object into a new section
30110905Sandreas.sandberg@arm.com     *
30210905Sandreas.sandberg@arm.com     * This method creates a new section in a checkpoint and calls
30310905Sandreas.sandberg@arm.com     * serialize() to serialize the current object into that
30410905Sandreas.sandberg@arm.com     * section. The name of the section is appended to the current
30510905Sandreas.sandberg@arm.com     * checkpoint path.
30610905Sandreas.sandberg@arm.com     *
30710905Sandreas.sandberg@arm.com     * @param cp Checkpoint state
30810905Sandreas.sandberg@arm.com     * @param name Name to append to the active path
30910905Sandreas.sandberg@arm.com     */
31010905Sandreas.sandberg@arm.com    void serializeSection(CheckpointOut &cp, const char *name) const;
31110905Sandreas.sandberg@arm.com
31210905Sandreas.sandberg@arm.com    void serializeSection(CheckpointOut &cp, const std::string &name) const {
31310905Sandreas.sandberg@arm.com        serializeSection(cp, name.c_str());
31410905Sandreas.sandberg@arm.com    }
31510905Sandreas.sandberg@arm.com
31610905Sandreas.sandberg@arm.com    /**
31710905Sandreas.sandberg@arm.com     * Unserialize an a child object
31810905Sandreas.sandberg@arm.com     *
31910905Sandreas.sandberg@arm.com     * This method loads a child object from a checkpoint. The object
32010905Sandreas.sandberg@arm.com     * name is appended to the active path to form a fully qualified
32110905Sandreas.sandberg@arm.com     * section name and unserialize() is called.
32210905Sandreas.sandberg@arm.com     *
32310905Sandreas.sandberg@arm.com     * @param cp Checkpoint state
32410905Sandreas.sandberg@arm.com     * @param name Name to append to the active path
32510905Sandreas.sandberg@arm.com     */
32610905Sandreas.sandberg@arm.com    void unserializeSection(CheckpointIn &cp, const char *name);
32710905Sandreas.sandberg@arm.com
32810905Sandreas.sandberg@arm.com    void unserializeSection(CheckpointIn &cp, const std::string &name) {
32910905Sandreas.sandberg@arm.com        unserializeSection(cp, name.c_str());
33010905Sandreas.sandberg@arm.com    }
33110905Sandreas.sandberg@arm.com
33210905Sandreas.sandberg@arm.com    /** Get the fully-qualified name of the active section */
33310905Sandreas.sandberg@arm.com    static const std::string &currentSection();
33410905Sandreas.sandberg@arm.com
3352287SN/A    static int ckptCount;
3362287SN/A    static int ckptMaxCount;
3372287SN/A    static int ckptPrevCount;
3382868Sktlim@umich.edu    static void serializeAll(const std::string &cpt_dir);
33910905Sandreas.sandberg@arm.com    static void unserializeGlobals(CheckpointIn &cp);
34010905Sandreas.sandberg@arm.com
34110905Sandreas.sandberg@arm.com  private:
34210905Sandreas.sandberg@arm.com    static std::stack<std::string> path;
3432SN/A};
3442SN/A
3459554Sandreas.hansson@arm.comvoid debug_serialize(const std::string &cpt_dir);
3469554Sandreas.hansson@arm.com
34710453SAndrew.Bardsley@arm.com
34810905Sandreas.sandberg@arm.comclass CheckpointIn
349237SN/A{
350237SN/A  private:
351237SN/A
352237SN/A    IniFile *db;
353237SN/A
35410453SAndrew.Bardsley@arm.com    SimObjectResolver &objNameResolver;
35510453SAndrew.Bardsley@arm.com
356237SN/A  public:
35710905Sandreas.sandberg@arm.com    CheckpointIn(const std::string &cpt_dir, SimObjectResolver &resolver);
35810905Sandreas.sandberg@arm.com    ~CheckpointIn();
359237SN/A
360937SN/A    const std::string cptDir;
361937SN/A
362237SN/A    bool find(const std::string &section, const std::string &entry,
363237SN/A              std::string &value);
364237SN/A
365237SN/A    bool findObj(const std::string &section, const std::string &entry,
3664000Ssaidi@eecs.umich.edu                 SimObject *&value);
367304SN/A
36811655Sandreas.sandberg@arm.com
36911655Sandreas.sandberg@arm.com    bool entryExists(const std::string &section, const std::string &entry);
370304SN/A    bool sectionExists(const std::string &section);
371449SN/A
372449SN/A    // The following static functions have to do with checkpoint
373449SN/A    // creation rather than restoration.  This class makes a handy
3747491Ssteve.reinhardt@amd.com    // namespace for them though.  Currently no Checkpoint object is
3757491Ssteve.reinhardt@amd.com    // created on serialization (only unserialization) so we track the
3767491Ssteve.reinhardt@amd.com    // directory name as a global.  It would be nice to change this
3777491Ssteve.reinhardt@amd.com    // someday
3787491Ssteve.reinhardt@amd.com
3797491Ssteve.reinhardt@amd.com  private:
3807491Ssteve.reinhardt@amd.com    // current directory we're serializing into.
3817491Ssteve.reinhardt@amd.com    static std::string currentDirectory;
3827491Ssteve.reinhardt@amd.com
3837491Ssteve.reinhardt@amd.com  public:
3847491Ssteve.reinhardt@amd.com    // Set the current directory.  This function takes care of
3857823Ssteve.reinhardt@amd.com    // inserting curTick() if there's a '%d' in the argument, and
3867491Ssteve.reinhardt@amd.com    // appends a '/' if necessary.  The final name is returned.
3877491Ssteve.reinhardt@amd.com    static std::string setDir(const std::string &base_name);
388449SN/A
389449SN/A    // Export current checkpoint directory name so other objects can
390449SN/A    // derive filenames from it (e.g., memory).  The return value is
391449SN/A    // guaranteed to end in '/' so filenames can be directly appended.
392449SN/A    // This function is only valid while a checkpoint is being created.
393449SN/A    static std::string dir();
394449SN/A
395449SN/A    // Filename for base checkpoint file within directory.
396449SN/A    static const char *baseFilename;
397237SN/A};
3982SN/A
3992SN/A#endif // __SERIALIZE_HH__
400