From: Curtis Dunham Date: Wed, 2 Sep 2015 20:19:44 +0000 (-0500) Subject: sim: support checkpointing std::set's X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=62e0344aefd56cb1878cdbc27dbed11d6cc73ba4;p=gem5.git sim: support checkpointing std::set's This is in support of tag-based checkpoint versioning; the version tags are stored in string sets. This commit adds such support. --- diff --git a/src/sim/serialize.cc b/src/sim/serialize.cc index 0ecf45b6d..0904b1375 100644 --- a/src/sim/serialize.cc +++ b/src/sim/serialize.cc @@ -210,6 +210,24 @@ arrayParamOut(CheckpointOut &os, const string &name, const list ¶m) os << "\n"; } +template +void +arrayParamOut(CheckpointOut &os, const string &name, const set ¶m) +{ + typename set::const_iterator it = param.begin(); + + os << name << "="; + if (param.size() > 0) + showParam(os, *it); + it++; + while (it != param.end()) { + os << " "; + showParam(os, *it); + it++; + } + os << "\n"; +} + template void paramIn(CheckpointIn &cp, const string &name, T ¶m) @@ -368,6 +386,36 @@ arrayParamIn(CheckpointIn &cp, const string &name, list ¶m) } } +template +void +arrayParamIn(CheckpointIn &cp, const string &name, set ¶m) +{ + const string §ion(Serializable::currentSection()); + string str; + if (!cp.find(section, name, str)) { + fatal("Can't unserialize '%s:%s'\n", section, name); + } + param.clear(); + + vector tokens; + tokenize(tokens, str, ' '); + + for (vector::size_type i = 0; i < tokens.size(); i++) { + T scalar_value; + if (!parseParam(tokens[i], scalar_value)) { + string err("could not parse \""); + + err += str; + err += "\""; + + fatal(err); + } + + // assign parsed value to vector + param.insert(scalar_value); + } +} + void objParamIn(CheckpointIn &cp, const string &name, SimObject * ¶m) @@ -423,6 +471,11 @@ INSTANTIATE_PARAM_TEMPLATES(double) INSTANTIATE_PARAM_TEMPLATES(string) INSTANTIATE_PARAM_TEMPLATES(Pixel) +// set is only used with strings and furthermore doesn't agree with Pixel +template void +arrayParamOut(CheckpointOut &, const string &, const set &); +template void +arrayParamIn(CheckpointIn &, const string &, set &); ///////////////////////////// diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh index e3b761f10..4a2cc04e9 100644 --- a/src/sim/serialize.hh +++ b/src/sim/serialize.hh @@ -55,6 +55,7 @@ #include #include #include +#include #include #include "base/bitunion.hh" @@ -123,6 +124,10 @@ template void arrayParamOut(CheckpointOut &cp, const std::string &name, const std::list ¶m); +template +void arrayParamOut(CheckpointOut &cp, const std::string &name, + const std::set ¶m); + template void arrayParamIn(CheckpointIn &cp, const std::string &name, T *param, unsigned size); @@ -135,6 +140,10 @@ template void arrayParamIn(CheckpointIn &cp, const std::string &name, std::list ¶m); +template +void arrayParamIn(CheckpointIn &cp, const std::string &name, + std::set ¶m); + void objParamIn(CheckpointIn &cp, const std::string &name, SimObject * ¶m);