Go to the documentation of this file.
45 #ifndef __SERIALIZE_HH__
46 #define __SERIALIZE_HH__
54 #include <type_traits>
55 #include <unordered_map>
90 bool find(
const std::string §ion,
const std::string &entry,
93 bool findObj(
const std::string §ion,
const std::string &entry,
96 bool entryExists(
const std::string §ion,
const std::string &entry);
123 static std::string
setDir(
const std::string &base_name);
135 static std::string
dir();
321 static std::stack<std::string>
path;
369 warn_if(do_warn,
"optional parameter %s:%s not present",
392 template <
class InputIterator>
395 InputIterator start, InputIterator end)
399 using Elem = std::remove_cv_t<std::remove_reference_t<decltype(*it)>>;
413 decltype(std::begin(std::declval<const T&>()),
414 std::end(std::declval<const T&>()),
void())
428 const T *param,
unsigned size)
445 template <
class T,
class InsertIterator>
448 InsertIterator inserter, ssize_t fixed_size=-1)
453 "Can't unserialize '%s:%s'.", section,
name);
458 fatal_if(fixed_size >= 0 && tokens.size() != fixed_size,
459 "Array size mismatch on %s:%s (Got %u, expected %u)'\n",
460 section,
name, tokens.size(), fixed_size);
462 for (
const auto &
token: tokens) {
465 "Could not parse \"%s\".", str);
474 decltype(std::declval<T>().insert(std::declval<typename T::value_type>()),
479 arrayParamIn<typename T::value_type>(
480 cp,
name, std::inserter(param, param.begin()));
487 decltype(std::declval<T>().push_back(std::declval<typename T::value_type>()),
492 arrayParamIn<typename T::value_type>(
cp,
name, std::back_inserter(param));
501 T *param,
unsigned size)
509 arrayParamIn<T>(
cp,
name, insert_it, size);
533 const char*
const names[],
const T *param,
unsigned size)
536 for (
unsigned i = 0;
i < size; ++
i) {
547 const char*
const names[], T *param,
unsigned size)
550 std::unordered_map<std::string, size_t> name_to_index;
551 for (
size_t i = 0;
i < size;
i++) {
552 name_to_index[names[
i]] =
i;
554 for (
size_t i = 0;
i < size;
i++) {
555 auto& key = names[
i];
558 param[name_to_index[key]] = value;
563 [name_to_index](
const std::string& key,
const std::string&
val)
565 if (!name_to_index.count(key)) {
566 warn(
"unknown entry found in checkpoint: %s %s %s\n",
567 Serializable::currentSection(), key, val);
584 #define SERIALIZE_SCALAR(scalar) paramOut(cp, #scalar, scalar)
591 #define UNSERIALIZE_SCALAR(scalar) paramIn(cp, #scalar, scalar)
598 #define UNSERIALIZE_OPT_SCALAR(scalar) optParamIn(cp, #scalar, scalar)
607 #define SERIALIZE_ENUM(scalar) paramOut(cp, #scalar, (int)scalar)
614 #define UNSERIALIZE_ENUM(scalar) \
617 paramIn(cp, #scalar, tmp); \
618 scalar = static_cast<decltype(scalar)>(tmp); \
626 #define SERIALIZE_ARRAY(member, size) \
627 arrayParamOut(cp, #member, member, size)
634 #define UNSERIALIZE_ARRAY(member, size) \
635 arrayParamIn(cp, #member, member, size)
642 #define SERIALIZE_CONTAINER(member) \
643 arrayParamOut(cp, #member, member)
650 #define UNSERIALIZE_CONTAINER(member) \
651 arrayParamIn(cp, #member, member)
658 #define SERIALIZE_EVENT(event) event.serializeSection(cp, #event);
665 #define UNSERIALIZE_EVENT(event) \
667 event.unserializeSection(cp, #event); \
668 eventQueue()->checkpointReschedule(&event); \
676 #define SERIALIZE_OBJ(obj) obj.serializeSection(cp, #obj)
683 #define UNSERIALIZE_OBJ(obj) obj.unserializeSection(cp, #obj)
690 #define SERIALIZE_OBJPTR(objptr) paramOut(cp, #objptr, (objptr)->name())
697 #define UNSERIALIZE_OBJPTR(objptr) \
700 objParamIn(cp, #objptr, sptr); \
701 objptr = dynamic_cast<decltype(objptr)>(sptr); \
707 #define SERIALIZE_MAPPING(member, names, size) \
708 mappingParamOut(cp, #member, names, member, size)
713 #define UNSERIALIZE_MAPPING(member, names, size) \
714 mappingParamIn(cp, #member, names, member, size)
716 #endif // __SERIALIZE_HH__
void nameOut(CheckpointOut &cp)
Base class to wrap object resolving functionality.
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
SimObjectResolver & objNameResolver
CheckpointIn(const std::string &cpt_dir, SimObjectResolver &resolver)
void visitSection(const std::string §ion, IniFile::VisitSectionCallback cb)
~ScopedCheckpointSection()
Basic support for object serialization.
bool sectionExists(const std::string §ion)
void tokenize(std::vector< std::string > &v, const std::string &s, char token, bool ignore)
This class represents the contents of a ".ini" file.
void unserializeSection(CheckpointIn &cp, const std::string &name)
bool findObj(const std::string §ion, const std::string &entry, SimObject *&value)
void arrayParamIn(CheckpointIn &cp, const std::string &name, InsertIterator inserter, ssize_t fixed_size=-1)
Extract values stored in the checkpoint, and assign them to the provided array container.
void paramIn(CheckpointIn &cp, const std::string &name, T ¶m)
This function is used for restoring parameters from a checkpoint.
bool find(const std::string §ion, const std::string &entry, std::string &value)
ScopedCheckpointSection(CP &cp, const std::string &name)
void serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
std::function< void(const std::string &, const std::string &)> VisitSectionCallback
Visitor callback that receives key/value pairs.
void nameOut(CheckpointIn &cp)
bool optParamIn(CheckpointIn &cp, const std::string &name, T ¶m, bool do_warn=true)
This function is used for restoring optional parameters from the checkpoint.
decltype(std::begin(std::declval< const T & >()), std::end(std::declval< const T & >()), void()) arrayParamOut(CheckpointOut &os, const std::string &name, const T ¶m)
virtual void serialize(CheckpointOut &cp) const =0
Serialize an object.
void debug_serialize(const std::string &cpt_dir)
void pushName(const char *name)
static std::string currentDirectory
static const char * baseFilename
static void unserializeGlobals(CheckpointIn &cp)
static std::string setDir(const std::string &base_name)
Set the current directory.
const std::string _cptDir
void mappingParamIn(CheckpointIn &cp, const char *sectionName, const char *const names[], T *param, unsigned size)
Restore mappingParamOut.
ScopedCheckpointSection(CP &cp, const char *name)
This is the constructor for Scoped checkpoint section helper class.
const std::string & name()
virtual void unserialize(CheckpointIn &cp)=0
Unserialize an object.
#define warn_if(cond,...)
Conditional warning macro that checks the supplied condition and only prints a warning if the conditi...
const std::string getCptDir()
Temp operator*(Temp l, Temp r)
bool entryExists(const std::string §ion, const std::string &entry)
Overload hash function for BasicBlockRange type.
static void serializeAll(const std::string &cpt_dir)
Serializes all the SimObjects.
std::ostream CheckpointOut
ScopedCheckpointSection & operator=(const ScopedCheckpointSection &)=delete
static const std::string & currentSection()
Gets the fully-qualified name of the active section.
void mappingParamOut(CheckpointOut &os, const char *sectionName, const char *const names[], const T *param, unsigned size)
Serialize a mapping represented as two arrays: one containing names and the other containing values.
static std::string dir()
Get the current checkout directory name.
void objParamIn(CheckpointIn &cp, const std::string &name, SimObject *¶m)
void serializeSection(CheckpointOut &cp, const std::string &name) const
void paramOut(CheckpointOut &os, const std::string &name, const T ¶m)
This function is used for writing parameters to a checkpoint.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
static void show(std::ostream &os, const T &value)
bool paramInImpl(CheckpointIn &cp, const std::string &name, T ¶m)
static std::stack< std::string > path
ScopedCheckpointSection()=delete
Abstract superclass for simulation objects.
Generated on Tue Mar 23 2021 19:41:28 for gem5 by doxygen 1.8.17