Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/36276 )

Change subject: sim: Implement optParamIn using paramIn.
......................................................................

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 <[email protected]>
Reviewed-by: Andreas Sandberg <[email protected]>
Maintainer: Giacomo Travaglini <[email protected]>
Maintainer: Andreas Sandberg <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/sim/serialize.hh
1 file changed, 37 insertions(+), 34 deletions(-)

Approvals:
  Andreas Sandberg: Looks good to me, approved; Looks good to me, approved
  Giacomo Travaglini: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh
index bbc91d7..6c06eeb 100644
--- a/src/sim/serialize.hh
+++ b/src/sim/serialize.hh
@@ -471,6 +471,41 @@
     os << "\n";
 }

+template <class T>
+bool
+paramInImpl(CheckpointIn &cp, const std::string &name, T &param)
+{
+    const std::string &section(Serializable::currentSection());
+    std::string str;
+    return cp.find(section, name, str) && parseParam(str, param);
+}
+
+/**
+ * This function is used for restoring optional parameters from the
+ * checkpoint.
+ * @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 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.
+ *
+ * @ingroup api_serialize
+ */
+template <class T>
+bool
+optParamIn(CheckpointIn &cp, const std::string &name, T &param,
+           bool do_warn=true)
+{
+    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.
@@ -482,40 +517,8 @@
 void
 paramIn(CheckpointIn &cp, const std::string &name, T &param)
 {
-    const std::string &section(Serializable::currentSection());
-    std::string str;
-    if (!cp.find(section, name, str) || !parseParam(str, param)) {
-        fatal("Can't unserialize '%s:%s'\n", section, name);
-    }
-}
-
-/**
- * This function is used for restoring optional parameters from the
- * checkpoint.
- * @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.
- * @return If the parameter we are searching for does not exist
- * the function returns false else it returns true.
- *
- * @ingroup api_serialize
- */
-template <class T>
-bool
-optParamIn(CheckpointIn &cp, const std::string &name,
-           T &param, bool warn = true)
-{
-    const std::string &section(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 {
-        return true;
-    }
+    fatal_if(!paramInImpl(cp, name, param),
+        "Can't unserialize '%s:%s'", Serializable::currentSection(), name);
 }

 /**

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/36276
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Id124a05d04e1c0897121d0e13dd46efe90e8eed0
Gerrit-Change-Number: 36276
Gerrit-PatchSet: 3
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Ciro Santilli <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to