From e8e92a12af8cc499659ad840c84c99e293ff1e96 Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Wed, 17 Oct 2018 18:08:30 +0100 Subject: sim: Move BitUnion overloading to show/parseParams This patch is moving template overloading for BitUnions into the showParam, parseParams functions. Henceforth BitUnion types will use the common param wrapper. This patch implicitly implements (UN)SERIALIZE_CONTAINER for BitUnions. Change-Id: I0e1faadb4afd4dc9de5dc5fca40041e349c9ba73 Signed-off-by: Giacomo Travaglini Reviewed-on: https://gem5-review.googlesource.com/c/13636 Reviewed-by: Andreas Sandberg Maintainer: Andreas Sandberg --- src/sim/serialize.hh | 78 ++++++++++++++++------------------------------------ 1 file changed, 23 insertions(+), 55 deletions(-) diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh index adaefdd84..543477726 100644 --- a/src/sim/serialize.hh +++ b/src/sim/serialize.hh @@ -285,6 +285,29 @@ showParam(CheckpointOut &os, const T &value) os << value; } +template +bool +parseParam(const std::string &s, BitUnionType &value) +{ + auto storage = static_cast>(value); + auto res = to_number(s, storage); + value = storage; + return res; +} + +template +void +showParam(CheckpointOut &os, const BitUnionType &value) +{ + auto storage = static_cast>(value); + + // For a BitUnion8, the storage type is an unsigned char. + // Since we want to serialize a number we need to cast to + // unsigned int + os << ((sizeof(storage) == 1) ? + static_cast(storage) : storage); +} + // Treat 8-bit ints (chars) as ints on output, not as chars template <> inline void @@ -354,13 +377,6 @@ paramOut(CheckpointOut &os, const std::string &name, const T ¶m) os << "\n"; } -template -void -paramOut(CheckpointOut &cp, const std::string &name, const BitUnionType &p) -{ - paramOut(cp, name, static_cast >(p)); -} - template void paramIn(CheckpointIn &cp, const std::string &name, T ¶m) @@ -372,15 +388,6 @@ paramIn(CheckpointIn &cp, const std::string &name, T ¶m) } } -template -void -paramIn(CheckpointIn &cp, const std::string &name, BitUnionType &p) -{ - BitUnionBaseType b; - paramIn(cp, name, b); - p = b; -} - template bool optParamIn(CheckpointIn &cp, const std::string &name, @@ -397,20 +404,6 @@ optParamIn(CheckpointIn &cp, const std::string &name, } } -template -bool -optParamIn(CheckpointIn &cp, const std::string &name, - BitUnionType &p, bool warn = true) -{ - BitUnionBaseType b; - if (optParamIn(cp, name, b, warn)) { - p = b; - return true; - } else { - return false; - } -} - template void arrayParamOut(CheckpointOut &os, const std::string &name, @@ -628,31 +621,6 @@ arrayParamIn(CheckpointIn &cp, const std::string &name, std::set ¶m) } } -template -static void -arrayParamOut(CheckpointOut &cp, const std::string &name, - const BitUnionType *param, unsigned size) -{ - // We copy the array into a vector. This is needed since we cannot - // directly typecast a pointer to BitUnionType into a pointer - // of BitUnionBaseType but we can typecast BitUnionType - // to BitUnionBaseType since we overloaded the typecast operator - std::vector> bitunion_vec(param, param + size); - - arrayParamOut(cp, name, bitunion_vec); -} - -template -static void -arrayParamIn(CheckpointIn &cp, const std::string &name, - BitUnionType *param, unsigned size) -{ - std::vector> bitunion_vec(size); - - arrayParamIn(cp, name, bitunion_vec); - std::copy(bitunion_vec.begin(), bitunion_vec.end(), param); -} - void debug_serialize(const std::string &cpt_dir); -- cgit v1.2.3