serialize.hh (13414:1b5387dccec3) serialize.hh (13415:dfba7ea400e2)
1/*
2 * Copyright (c) 2015, 2018 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 271 unchanged lines hidden (view full) ---

280
281template <class T>
282void
283showParam(CheckpointOut &os, const T &value)
284{
285 os << value;
286}
287
1/*
2 * Copyright (c) 2015, 2018 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 271 unchanged lines hidden (view full) ---

280
281template <class T>
282void
283showParam(CheckpointOut &os, const T &value)
284{
285 os << value;
286}
287
288template <class T>
289bool
290parseParam(const std::string &s, BitUnionType<T> &value)
291{
292 auto storage = static_cast<BitUnionBaseType<T>>(value);
293 auto res = to_number(s, storage);
294 value = storage;
295 return res;
296}
297
298template <class T>
299void
300showParam(CheckpointOut &os, const BitUnionType<T> &value)
301{
302 auto storage = static_cast<BitUnionBaseType<T>>(value);
303
304 // For a BitUnion8, the storage type is an unsigned char.
305 // Since we want to serialize a number we need to cast to
306 // unsigned int
307 os << ((sizeof(storage) == 1) ?
308 static_cast<unsigned int>(storage) : storage);
309}
310
288// Treat 8-bit ints (chars) as ints on output, not as chars
289template <>
290inline void
291showParam(CheckpointOut &os, const char &value)
292{
293 os << (int)value;
294}
295

--- 53 unchanged lines hidden (view full) ---

349void
350paramOut(CheckpointOut &os, const std::string &name, const T &param)
351{
352 os << name << "=";
353 showParam(os, param);
354 os << "\n";
355}
356
311// Treat 8-bit ints (chars) as ints on output, not as chars
312template <>
313inline void
314showParam(CheckpointOut &os, const char &value)
315{
316 os << (int)value;
317}
318

--- 53 unchanged lines hidden (view full) ---

372void
373paramOut(CheckpointOut &os, const std::string &name, const T &param)
374{
375 os << name << "=";
376 showParam(os, param);
377 os << "\n";
378}
379
357template <typename T>
358void
359paramOut(CheckpointOut &cp, const std::string &name, const BitUnionType<T> &p)
360{
361 paramOut(cp, name, static_cast<BitUnionBaseType<T> >(p));
362}
363
364template <class T>
365void
366paramIn(CheckpointIn &cp, const std::string &name, T &param)
367{
368 const std::string &section(Serializable::currentSection());
369 std::string str;
370 if (!cp.find(section, name, str) || !parseParam(str, param)) {
371 fatal("Can't unserialize '%s:%s'\n", section, name);
372 }
373}
374
380template <class T>
381void
382paramIn(CheckpointIn &cp, const std::string &name, T &param)
383{
384 const std::string &section(Serializable::currentSection());
385 std::string str;
386 if (!cp.find(section, name, str) || !parseParam(str, param)) {
387 fatal("Can't unserialize '%s:%s'\n", section, name);
388 }
389}
390
375template <typename T>
376void
377paramIn(CheckpointIn &cp, const std::string &name, BitUnionType<T> &p)
378{
379 BitUnionBaseType<T> b;
380 paramIn(cp, name, b);
381 p = b;
382}
383
384template <class T>
385bool
386optParamIn(CheckpointIn &cp, const std::string &name,
387 T &param, bool warn = true)
388{
389 const std::string &section(Serializable::currentSection());
390 std::string str;
391 if (!cp.find(section, name, str) || !parseParam(str, param)) {
392 if (warn)
393 warn("optional parameter %s:%s not present\n", section, name);
394 return false;
395 } else {
396 return true;
397 }
398}
399
391template <class T>
392bool
393optParamIn(CheckpointIn &cp, const std::string &name,
394 T &param, bool warn = true)
395{
396 const std::string &section(Serializable::currentSection());
397 std::string str;
398 if (!cp.find(section, name, str) || !parseParam(str, param)) {
399 if (warn)
400 warn("optional parameter %s:%s not present\n", section, name);
401 return false;
402 } else {
403 return true;
404 }
405}
406
400template <typename T>
401bool
402optParamIn(CheckpointIn &cp, const std::string &name,
403 BitUnionType<T> &p, bool warn = true)
404{
405 BitUnionBaseType<T> b;
406 if (optParamIn(cp, name, b, warn)) {
407 p = b;
408 return true;
409 } else {
410 return false;
411 }
412}
413
414template <class T>
415void
416arrayParamOut(CheckpointOut &os, const std::string &name,
417 const std::vector<T> &param)
418{
419 typename std::vector<T>::size_type size = param.size();
420 os << name << "=";
421 if (size > 0)

--- 201 unchanged lines hidden (view full) ---

623 fatal(err);
624 }
625
626 // assign parsed value to vector
627 param.insert(scalar_value);
628 }
629}
630
407template <class T>
408void
409arrayParamOut(CheckpointOut &os, const std::string &name,
410 const std::vector<T> &param)
411{
412 typename std::vector<T>::size_type size = param.size();
413 os << name << "=";
414 if (size > 0)

--- 201 unchanged lines hidden (view full) ---

616 fatal(err);
617 }
618
619 // assign parsed value to vector
620 param.insert(scalar_value);
621 }
622}
623
631template <class T>
632static void
633arrayParamOut(CheckpointOut &cp, const std::string &name,
634 const BitUnionType<T> *param, unsigned size)
635{
636 // We copy the array into a vector. This is needed since we cannot
637 // directly typecast a pointer to BitUnionType<T> into a pointer
638 // of BitUnionBaseType<T> but we can typecast BitUnionType<T>
639 // to BitUnionBaseType<T> since we overloaded the typecast operator
640 std::vector<BitUnionBaseType<T>> bitunion_vec(param, param + size);
641
642 arrayParamOut(cp, name, bitunion_vec);
643}
644
645template <class T>
646static void
647arrayParamIn(CheckpointIn &cp, const std::string &name,
648 BitUnionType<T> *param, unsigned size)
649{
650 std::vector<BitUnionBaseType<T>> bitunion_vec(size);
651
652 arrayParamIn(cp, name, bitunion_vec);
653 std::copy(bitunion_vec.begin(), bitunion_vec.end(), param);
654}
655
656void
657debug_serialize(const std::string &cpt_dir);
658
659void
660objParamIn(CheckpointIn &cp, const std::string &name, SimObject * &param);
661
662//
663// These macros are streamlined to use in serialize/unserialize

--- 50 unchanged lines hidden ---
624void
625debug_serialize(const std::string &cpt_dir);
626
627void
628objParamIn(CheckpointIn &cp, const std::string &name, SimObject * &param);
629
630//
631// These macros are streamlined to use in serialize/unserialize

--- 50 unchanged lines hidden ---