summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiacomo Travaglini <giacomo.travaglini@arm.com>2018-09-24 16:45:30 +0100
committerGiacomo Travaglini <giacomo.travaglini@arm.com>2018-10-01 08:16:33 +0000
commitcf20e8211e2c3f1b2085c949a1e992a1f5d1071c (patch)
tree6d4489eb579e813c69732f224ed4d0687467f39a
parenta43e3108b4a9bd34cf382588e2e3bc0b81381623 (diff)
downloadgem5-cf20e8211e2c3f1b2085c949a1e992a1f5d1071c.tar.xz
sim: Extend (UN)SERIALIZE_ARRAY to BitUnions
This patch is making it possible to use SERIALIZE_ARRAY and UNSERIALIZE array for serializing arrays of BitUnions. Change-Id: I682766b472585f70a89338f373fb94dff5db53c3 Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com> Reviewed-on: https://gem5-review.googlesource.com/12924 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
-rw-r--r--src/sim/serialize.hh28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh
index 024d29cbb..b3081ad5a 100644
--- a/src/sim/serialize.hh
+++ b/src/sim/serialize.hh
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015 ARM Limited
+ * Copyright (c) 2015, 2018 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
@@ -51,6 +51,7 @@
#define __SERIALIZE_HH__
+#include <algorithm>
#include <iostream>
#include <list>
#include <map>
@@ -144,6 +145,31 @@ void arrayParamIn(CheckpointIn &cp, const std::string &name,
void
objParamIn(CheckpointIn &cp, const std::string &name, SimObject * &param);
+template <class T>
+static void
+arrayParamOut(CheckpointOut &cp, const std::string &name,
+ const BitUnionType<T> *param, unsigned size)
+{
+ // We copy the array into a vector. This is needed since we cannot
+ // directly typecast a pointer to BitUnionType<T> into a pointer
+ // of BitUnionBaseType<T> but we can typecast BitUnionType<T>
+ // to BitUnionBaseType<T> since we overloaded the typecast operator
+ std::vector<BitUnionBaseType<T>> bitunion_vec(param, param + size);
+
+ arrayParamOut(cp, name, bitunion_vec);
+}
+
+template <class T>
+static void
+arrayParamIn(CheckpointIn &cp, const std::string &name,
+ BitUnionType<T> *param, unsigned size)
+{
+ std::vector<BitUnionBaseType<T>> bitunion_vec(size);
+
+ arrayParamIn(cp, name, bitunion_vec);
+ std::copy(bitunion_vec.begin(), bitunion_vec.end(), param);
+}
+
//
// These macros are streamlined to use in serialize/unserialize
// functions. It's assumed that serialize() has a parameter 'os' for