serialize.cc (10907:94d5a1476c5b) serialize.cc (11072:6a447a3138ef)
1/*
2 * Copyright (c) 2015 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

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

440
441/// The one and only instance of the Globals class.
442Globals globals;
443
444void
445Globals::serialize(CheckpointOut &cp) const
446{
447 paramOut(cp, "curTick", curTick());
1/*
2 * Copyright (c) 2015 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

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

440
441/// The one and only instance of the Globals class.
442Globals globals;
443
444void
445Globals::serialize(CheckpointOut &cp) const
446{
447 paramOut(cp, "curTick", curTick());
448 paramOut(cp, "numMainEventQueues", numMainEventQueues);
449
450}
451
452void
453Globals::unserialize(CheckpointIn &cp)
454{
455 paramIn(cp, "curTick", unserializedCurTick);
448}
449
450void
451Globals::unserialize(CheckpointIn &cp)
452{
453 paramIn(cp, "curTick", unserializedCurTick);
456 paramIn(cp, "numMainEventQueues", numMainEventQueues);
457}
458
459Serializable::Serializable()
460{
461}
462
463Serializable::~Serializable()
464{

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

495 string cpt_file = dir + CheckpointIn::baseFilename;
496 ofstream outstream(cpt_file.c_str());
497 time_t t = time(NULL);
498 if (!outstream.is_open())
499 fatal("Unable to open file %s for writing\n", cpt_file.c_str());
500 outstream << "## checkpoint generated: " << ctime(&t);
501
502 globals.serializeSection(outstream, "Globals");
454}
455
456Serializable::Serializable()
457{
458}
459
460Serializable::~Serializable()
461{

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

492 string cpt_file = dir + CheckpointIn::baseFilename;
493 ofstream outstream(cpt_file.c_str());
494 time_t t = time(NULL);
495 if (!outstream.is_open())
496 fatal("Unable to open file %s for writing\n", cpt_file.c_str());
497 outstream << "## checkpoint generated: " << ctime(&t);
498
499 globals.serializeSection(outstream, "Globals");
503 for (uint32_t i = 0; i < numMainEventQueues; ++i)
504 mainEventQueue[i]->serializeSection(outstream, "MainEventQueue");
505
506 SimObject::serializeAll(outstream);
507}
508
509void
510Serializable::unserializeGlobals(CheckpointIn &cp)
511{
512 globals.unserializeSection(cp, "Globals");
513
500
501 SimObject::serializeAll(outstream);
502}
503
504void
505Serializable::unserializeGlobals(CheckpointIn &cp)
506{
507 globals.unserializeSection(cp, "Globals");
508
514 for (uint32_t i = 0; i < numMainEventQueues; ++i) {
509 for (uint32_t i = 0; i < numMainEventQueues; ++i)
515 mainEventQueue[i]->setCurTick(globals.unserializedCurTick);
510 mainEventQueue[i]->setCurTick(globals.unserializedCurTick);
516 mainEventQueue[i]->unserializeSection(cp, "MainEventQueue");
517 }
518}
519
520Serializable::ScopedCheckpointSection::~ScopedCheckpointSection()
521{
522 assert(!path.empty());
523 DPRINTF(Checkpoint, "Popping: %s\n", path.top());
524 path.pop();
525}

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

544}
545
546void
547debug_serialize(const string &cpt_dir)
548{
549 Serializable::serializeAll(cpt_dir);
550}
551
511}
512
513Serializable::ScopedCheckpointSection::~ScopedCheckpointSection()
514{
515 assert(!path.empty());
516 DPRINTF(Checkpoint, "Popping: %s\n", path.top());
517 path.pop();
518}

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

537}
538
539void
540debug_serialize(const string &cpt_dir)
541{
542 Serializable::serializeAll(cpt_dir);
543}
544
552
553////////////////////////////////////////////////////////////////////////
554//
555// SerializableClass member definitions
556//
557////////////////////////////////////////////////////////////////////////
558
559// Map of class names to SerializableBuilder creation functions.
560// Need to make this a pointer so we can force initialization on the
561// first reference; otherwise, some SerializableClass constructors
562// may be invoked before the classMap constructor.
563map<string, SerializableClass::CreateFunc> *SerializableClass::classMap = 0;
564
565// SerializableClass constructor: add mapping to classMap
566SerializableClass::SerializableClass(const string &className,
567 CreateFunc createFunc)
568{
569 if (classMap == NULL)
570 classMap = new map<string, SerializableClass::CreateFunc>();
571
572 if ((*classMap)[className])
573 fatal("Error: simulation object class %s redefined\n", className);
574
575 // add className --> createFunc to class map
576 (*classMap)[className] = createFunc;
577}
578
579//
580//
581Serializable *
582SerializableClass::createObject(CheckpointIn &cp, const string &section)
583{
584 string className;
585
586 if (!cp.find(section, "type", className)) {
587 fatal("Serializable::create: no 'type' entry in section '%s'.\n",
588 section);
589 }
590
591 CreateFunc createFunc = (*classMap)[className];
592
593 if (createFunc == NULL) {
594 fatal("Serializable::create: no create function for class '%s'.\n",
595 className);
596 }
597
598 Serializable *object = createFunc(cp, section);
599
600 assert(object != NULL);
601
602 return object;
603}
604
605const std::string &
606Serializable::currentSection()
607{
608 assert(!path.empty());
609
610 return path.top();
611}
612
545const std::string &
546Serializable::currentSection()
547{
548 assert(!path.empty());
549
550 return path.top();
551}
552
613Serializable *
614Serializable::create(CheckpointIn &cp, const string &section)
615{
616 Serializable *object = SerializableClass::createObject(cp, section);
617 object->unserializeSection(cp, section);
618 return object;
619}
620
621
622const char *CheckpointIn::baseFilename = "m5.cpt";
623
624string CheckpointIn::currentDirectory;
625
626string
627CheckpointIn::setDir(const string &name)
628{
629 // use csprintf to insert curTick() into directory name if it

--- 55 unchanged lines hidden ---
553const char *CheckpointIn::baseFilename = "m5.cpt";
554
555string CheckpointIn::currentDirectory;
556
557string
558CheckpointIn::setDir(const string &name)
559{
560 // use csprintf to insert curTick() into directory name if it

--- 55 unchanged lines hidden ---