From: Gabe Black Date: Wed, 21 Oct 2020 01:46:02 +0000 (-0700) Subject: sim: Implement optParamIn using paramIn. X-Git-Tag: develop-gem5-snapshot~593 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=368e5a492b0f6cba8478d9242d38e556a68e5fb0;p=gem5.git sim: Implement optParamIn using paramIn. This means only paramIn needs to be specialized, and then optParamIn will be as well for free. It also removes some duplicate implementation. Change-Id: Id124a05d04e1c0897121d0e13dd46efe90e8eed0 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/36276 Reviewed-by: Giacomo Travaglini Reviewed-by: Andreas Sandberg Maintainer: Giacomo Travaglini Maintainer: Andreas Sandberg Tested-by: kokoro --- diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh index bbc91d7b5..6c06eeb25 100644 --- a/src/sim/serialize.hh +++ b/src/sim/serialize.hh @@ -471,22 +471,13 @@ paramOut(CheckpointOut &os, const std::string &name, const T ¶m) os << "\n"; } -/** - * This function is used for restoring parameters from a checkpoint. - * @param os The checkpoint to be restored from. - * @param name Name of the parameter to be set. - * @param param Value of the parameter to be restored. - * @ingroup api_serialize - */ template -void -paramIn(CheckpointIn &cp, const std::string &name, T ¶m) +bool +paramInImpl(CheckpointIn &cp, const std::string &name, T ¶m) { const std::string §ion(Serializable::currentSection()); std::string str; - if (!cp.find(section, name, str) || !parseParam(str, param)) { - fatal("Can't unserialize '%s:%s'\n", section, name); - } + return cp.find(section, name, str) && parseParam(str, param); } /** @@ -495,8 +486,8 @@ paramIn(CheckpointIn &cp, const std::string &name, T ¶m) * @param cp The checkpoint to be written to. * @param name Name of the parameter to be written. * @param param Value of the parameter to be written. - * @param warn If the warn is set to true then the function prints the warning - * message. + * @param do_warn If the do_warn is set to true then the function prints the + * warning message. * @return If the parameter we are searching for does not exist * the function returns false else it returns true. * @@ -504,18 +495,30 @@ paramIn(CheckpointIn &cp, const std::string &name, T ¶m) */ template bool -optParamIn(CheckpointIn &cp, const std::string &name, - T ¶m, bool warn = true) +optParamIn(CheckpointIn &cp, const std::string &name, T ¶m, + bool do_warn=true) { - const std::string §ion(Serializable::currentSection()); - std::string str; - if (!cp.find(section, name, str) || !parseParam(str, param)) { - if (warn) - warn("optional parameter %s:%s not present\n", section, name); - return false; - } else { + if (paramInImpl(cp, name, param)) return true; - } + + warn_if(do_warn, "optional parameter %s:%s not present", + Serializable::currentSection(), name); + return false; +} + +/** + * This function is used for restoring parameters from a checkpoint. + * @param os The checkpoint to be restored from. + * @param name Name of the parameter to be set. + * @param param Value of the parameter to be restored. + * @ingroup api_serialize + */ +template +void +paramIn(CheckpointIn &cp, const std::string &name, T ¶m) +{ + fatal_if(!paramInImpl(cp, name, param), + "Can't unserialize '%s:%s'", Serializable::currentSection(), name); } /**