1/* 2 * Copyright (c) 2002-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 26 unchanged lines hidden (view full) --- 35#include <sys/stat.h> 36#include <errno.h> 37 38#include <fstream> 39#include <list> 40#include <string> 41#include <vector> 42 |
43#include "base/annotate.hh" |
44#include "base/inifile.hh" 45#include "base/misc.hh" 46#include "base/output.hh" 47#include "base/str.hh" 48#include "base/trace.hh" 49#include "sim/eventq.hh" 50#include "sim/serialize.hh" 51#include "sim/sim_events.hh" --- 122 unchanged lines hidden (view full) --- 174void 175paramOut(ostream &os, const std::string &name, const T ¶m) 176{ 177 os << name << "="; 178 showParam(os, param); 179 os << "\n"; 180} 181 |
182template <class T> 183void 184arrayParamOut(ostream &os, const std::string &name, 185 const std::vector<T> ¶m) 186{ 187 int size = param.size(); 188 os << name << "="; 189 if (size > 0) 190 showParam(os, param[0]); 191 for (int i = 1; i < size; ++i) { 192 os << " "; 193 showParam(os, param[i]); 194 } 195 os << "\n"; 196} |
197 |
198 |
199template <class T> 200void 201paramIn(Checkpoint *cp, const std::string §ion, 202 const std::string &name, T ¶m) 203{ 204 std::string str; 205 if (!cp->find(section, name, str) || !parseParam(str, param)) { 206 fatal("Can't unserialize '%s:%s'\n", section, name); --- 56 unchanged lines hidden (view full) --- 263 fatal(err); 264 } 265 266 // assign parsed value to vector 267 param[i] = scalar_value; 268 } 269} 270 |
271template <class T> 272void 273arrayParamIn(Checkpoint *cp, const std::string §ion, 274 const std::string &name, std::vector<T> ¶m) 275{ 276 std::string str; 277 if (!cp->find(section, name, str)) { 278 fatal("Can't unserialize '%s:%s'\n", section, name); 279 } |
280 |
281 // code below stolen from VectorParam<T>::parse(). 282 // it would be nice to unify these somehow... 283 284 vector<string> tokens; 285 286 tokenize(tokens, str, ' '); 287 288 // Need this if we were doing a vector 289 // value.resize(tokens.size()); 290 291 param.resize(tokens.size()); 292 293 for (int i = 0; i < tokens.size(); i++) { 294 // need to parse into local variable to handle vector<bool>, 295 // for which operator[] returns a special reference class 296 // that's not the same as 'bool&', (since it's a packed 297 // vector) 298 T scalar_value; 299 if (!parseParam(tokens[i], scalar_value)) { 300 string err("could not parse \""); 301 302 err += str; 303 err += "\""; 304 305 fatal(err); 306 } 307 308 // assign parsed value to vector 309 param[i] = scalar_value; 310 } 311} 312 313 314 |
315void 316objParamIn(Checkpoint *cp, const std::string §ion, 317 const std::string &name, SimObject * ¶m) 318{ 319 if (!cp->findObj(section, name, param)) { 320 fatal("Can't unserialize '%s:%s'\n", section, name); 321 } 322} --- 5 unchanged lines hidden (view full) --- 328template void \ 329paramIn(Checkpoint *cp, const std::string §ion, \ 330 const std::string &name, type & param); \ 331template void \ 332arrayParamOut(ostream &os, const std::string &name, \ 333 type const *param, int size); \ 334template void \ 335arrayParamIn(Checkpoint *cp, const std::string §ion, \ |
336 const std::string &name, type *param, int size); \ 337template void \ 338arrayParamOut(ostream &os, const std::string &name, \ 339 const std::vector<type> ¶m); \ 340template void \ 341arrayParamIn(Checkpoint *cp, const std::string §ion, \ 342 const std::string &name, std::vector<type> ¶m); |
343 344INSTANTIATE_PARAM_TEMPLATES(signed char) 345INSTANTIATE_PARAM_TEMPLATES(unsigned char) 346INSTANTIATE_PARAM_TEMPLATES(signed short) 347INSTANTIATE_PARAM_TEMPLATES(unsigned short) 348INSTANTIATE_PARAM_TEMPLATES(signed int) 349INSTANTIATE_PARAM_TEMPLATES(unsigned int) 350INSTANTIATE_PARAM_TEMPLATES(signed long) --- 53 unchanged lines hidden (view full) --- 404 fatal("couldn't mkdir %s\n", dir); 405 406 string cpt_file = dir + Checkpoint::baseFilename; 407 ofstream outstream(cpt_file.c_str()); 408 time_t t = time(NULL); 409 outstream << "// checkpoint generated: " << ctime(&t); 410 411 globals.serialize(outstream); |
412 Annotate::annotations.serialize(outstream); |
413 SimObject::serializeAll(outstream); 414} 415 416void 417Serializable::unserializeAll(const std::string &cpt_dir) 418{ 419 setCheckpointDir(cpt_dir); 420 string dir = Checkpoint::dir(); 421 string cpt_file = dir + Checkpoint::baseFilename; 422 string section = ""; 423 424 DPRINTFR(Config, "Loading checkpoint dir '%s'\n", 425 dir); 426 Checkpoint *cp = new Checkpoint(dir, section); 427 unserializeGlobals(cp); |
428 Annotate::annotations.unserialize(cp); |
429 SimObject::unserializeAll(cp); 430} 431 432void 433Serializable::unserializeGlobals(Checkpoint *cp) 434{ 435 globals.unserialize(cp); 436} --- 134 unchanged lines hidden --- |