Support for Serializable non-SimObject things like events.
Can now serialize & unserialize DmaRequestEvents and DmaTransferEvents. Also support serialize/unserialize of pointers to SimObjects and other Serializable objects. arch/alpha/alpha_memory.cc: arch/alpha/alpha_memory.hh: arch/alpha/isa_traits.hh: cpu/exec_context.cc: cpu/exec_context.hh: cpu/simple_cpu/simple_cpu.hh: dev/alpha_access.h: dev/alpha_console.cc: dev/alpha_console.hh: dev/console.cc: dev/console.hh: unserialize() now takes a Checkpoint* instead of an IniFile*. cpu/simple_cpu/simple_cpu.cc: unserialize() now takes a Checkpoint* instead of an IniFile*. Put ExecContext in its own section so its _status fields doesn't conflict. sim/eventq.cc: sim/eventq.hh: unserialize() now takes a Checkpoint* instead of an IniFile*. Events get serialized by the event queue only if they're marked as AutoSerialize... others are assumed to be serialized by something else (e.g. an owning SimObject) or to not matter. sim/param.cc: Shift 'const' in case T is a ptr type. sim/serialize.cc: sim/serialize.hh: Define Checkpoint object to encapsulate everything you need to know about a checkpoint. Use it to allow lookups of named Serializable objects (and SimObjects) during unserialization. unserialize() now takes a Checkpoint* instead of an IniFile*. --HG-- extra : convert_revision : 8e6baab32405f8f548bb67a097b2f713296537a5
This commit is contained in:
parent
976429121c
commit
5a1eb9049d
17 changed files with 193 additions and 113 deletions
|
@ -204,13 +204,13 @@ AlphaTlb::serialize(ostream &os)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
AlphaTlb::unserialize(const IniFile *db, const string §ion)
|
AlphaTlb::unserialize(Checkpoint *cp, const string §ion)
|
||||||
{
|
{
|
||||||
UNSERIALIZE_SCALAR(size);
|
UNSERIALIZE_SCALAR(size);
|
||||||
UNSERIALIZE_SCALAR(nlu);
|
UNSERIALIZE_SCALAR(nlu);
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
table[i].unserialize(db, csprintf("%s.PTE%d", section, i));
|
table[i].unserialize(cp, csprintf("%s.PTE%d", section, i));
|
||||||
if (table[i].valid) {
|
if (table[i].valid) {
|
||||||
lookupTable.insert(make_pair(table[i].tag, i));
|
lookupTable.insert(make_pair(table[i].tag, i));
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ class AlphaTlb : public SimObject
|
||||||
|
|
||||||
// Checkpointing
|
// Checkpointing
|
||||||
virtual void serialize(std::ostream &os);
|
virtual void serialize(std::ostream &os);
|
||||||
virtual void unserialize(const IniFile *db, const std::string §ion);
|
virtual void unserialize(Checkpoint *cp, const std::string §ion);
|
||||||
};
|
};
|
||||||
|
|
||||||
class AlphaItb : public AlphaTlb
|
class AlphaItb : public AlphaTlb
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
#include "base/misc.hh"
|
#include "base/misc.hh"
|
||||||
|
|
||||||
class FullCPU;
|
class FullCPU;
|
||||||
class IniFile;
|
class Checkpoint;
|
||||||
|
|
||||||
#define TARGET_ALPHA
|
#define TARGET_ALPHA
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ class AlphaISA
|
||||||
uint8_t opcode, ra; // current instruction details (for intr's)
|
uint8_t opcode, ra; // current instruction details (for intr's)
|
||||||
|
|
||||||
void serialize(std::ostream &os);
|
void serialize(std::ostream &os);
|
||||||
void unserialize(const IniFile *db, const std::string §ion);
|
void unserialize(Checkpoint *cp, const std::string §ion);
|
||||||
};
|
};
|
||||||
|
|
||||||
static StaticInstPtr<AlphaISA> decodeInst(MachInst);
|
static StaticInstPtr<AlphaISA> decodeInst(MachInst);
|
||||||
|
|
|
@ -108,10 +108,10 @@ ExecContext::serialize(ostream &os)
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ExecContext::unserialize(const IniFile *db, const std::string §ion)
|
ExecContext::unserialize(Checkpoint *cp, const std::string §ion)
|
||||||
{
|
{
|
||||||
UNSERIALIZE_ENUM(_status);
|
UNSERIALIZE_ENUM(_status);
|
||||||
regs.unserialize(db, section);
|
regs.unserialize(cp, section);
|
||||||
// thread_num and cpu_id are deterministic from the config
|
// thread_num and cpu_id are deterministic from the config
|
||||||
UNSERIALIZE_SCALAR(func_exe_insn);
|
UNSERIALIZE_SCALAR(func_exe_insn);
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ class ExecContext
|
||||||
void regStats(const std::string &name);
|
void regStats(const std::string &name);
|
||||||
|
|
||||||
void serialize(std::ostream &os);
|
void serialize(std::ostream &os);
|
||||||
void unserialize(const IniFile *db, const std::string §ion);
|
void unserialize(Checkpoint *cp, const std::string §ion);
|
||||||
|
|
||||||
#ifdef FULL_SYSTEM
|
#ifdef FULL_SYSTEM
|
||||||
bool validInstAddr(Addr addr) { return true; }
|
bool validInstAddr(Addr addr) { return true; }
|
||||||
|
|
|
@ -262,6 +262,7 @@ SimpleCPU::serialize(ostream &os)
|
||||||
{
|
{
|
||||||
SERIALIZE_ENUM(_status);
|
SERIALIZE_ENUM(_status);
|
||||||
SERIALIZE_SCALAR(inst);
|
SERIALIZE_SCALAR(inst);
|
||||||
|
nameOut(os, csprintf("%s.xc", name()));
|
||||||
xc->serialize(os);
|
xc->serialize(os);
|
||||||
nameOut(os, csprintf("%s.tickEvent", name()));
|
nameOut(os, csprintf("%s.tickEvent", name()));
|
||||||
tickEvent.serialize(os);
|
tickEvent.serialize(os);
|
||||||
|
@ -270,14 +271,14 @@ SimpleCPU::serialize(ostream &os)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SimpleCPU::unserialize(const IniFile *db, const string §ion)
|
SimpleCPU::unserialize(Checkpoint *cp, const string §ion)
|
||||||
{
|
{
|
||||||
UNSERIALIZE_ENUM(_status);
|
UNSERIALIZE_ENUM(_status);
|
||||||
UNSERIALIZE_SCALAR(inst);
|
UNSERIALIZE_SCALAR(inst);
|
||||||
xc->unserialize(db, section);
|
xc->unserialize(cp, csprintf("%s.xc", section));
|
||||||
tickEvent.unserialize(db, csprintf("%s.tickEvent", name()));
|
tickEvent.unserialize(cp, csprintf("%s.tickEvent", section));
|
||||||
cacheCompletionEvent
|
cacheCompletionEvent
|
||||||
.unserialize(db, csprintf("%s.cacheCompletionEvent", name()));
|
.unserialize(cp, csprintf("%s.cacheCompletionEvent", section));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -49,7 +49,7 @@ class GDBListener;
|
||||||
#endif // FULL_SYSTEM
|
#endif // FULL_SYSTEM
|
||||||
|
|
||||||
class MemInterface;
|
class MemInterface;
|
||||||
class IniFile;
|
class Checkpoint;
|
||||||
|
|
||||||
namespace Trace {
|
namespace Trace {
|
||||||
class InstRecord;
|
class InstRecord;
|
||||||
|
@ -259,7 +259,7 @@ class SimpleCPU : public BaseCPU
|
||||||
void processCacheCompletion();
|
void processCacheCompletion();
|
||||||
|
|
||||||
virtual void serialize(std::ostream &os);
|
virtual void serialize(std::ostream &os);
|
||||||
virtual void unserialize(const IniFile *db, const std::string §ion);
|
virtual void unserialize(Checkpoint *cp, const std::string §ion);
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
Fault read(Addr addr, T& data, unsigned flags);
|
Fault read(Addr addr, T& data, unsigned flags);
|
||||||
|
|
|
@ -44,7 +44,7 @@ typedef uint64_t UINT64;
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
class IniFile;
|
class Checkpoint;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ struct AlphaAccess
|
||||||
|
|
||||||
#ifndef CONSOLE
|
#ifndef CONSOLE
|
||||||
void serialize(std::ostream &os);
|
void serialize(std::ostream &os);
|
||||||
void unserialize(const IniFile *db, const std::string §ion);
|
void unserialize(Checkpoint *cp, const std::string §ion);
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,7 @@ AlphaAccess::serialize(ostream &os)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
AlphaAccess::unserialize(const IniFile *db, const std::string §ion)
|
AlphaAccess::unserialize(Checkpoint *cp, const std::string §ion)
|
||||||
{
|
{
|
||||||
UNSERIALIZE_SCALAR(last_offset);
|
UNSERIALIZE_SCALAR(last_offset);
|
||||||
UNSERIALIZE_SCALAR(version);
|
UNSERIALIZE_SCALAR(version);
|
||||||
|
@ -216,9 +216,9 @@ AlphaConsole::serialize(ostream &os)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
AlphaConsole::unserialize(const IniFile *db, const std::string §ion)
|
AlphaConsole::unserialize(Checkpoint *cp, const std::string §ion)
|
||||||
{
|
{
|
||||||
alphaAccess->unserialize(db, section);
|
alphaAccess->unserialize(cp, section);
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaConsole)
|
BEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaConsole)
|
||||||
|
|
|
@ -101,7 +101,7 @@ class AlphaConsole : public MmapDevice
|
||||||
* standard serialization routines for checkpointing
|
* standard serialization routines for checkpointing
|
||||||
*/
|
*/
|
||||||
virtual void serialize(std::ostream &os);
|
virtual void serialize(std::ostream &os);
|
||||||
virtual void unserialize(const IniFile *db, const std::string §ion);
|
virtual void unserialize(Checkpoint *cp, const std::string §ion);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __ALPHA_CONSOLE_HH__
|
#endif // __ALPHA_CONSOLE_HH__
|
||||||
|
|
|
@ -319,7 +319,7 @@ SimConsole::serialize(ostream &os)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SimConsole::unserialize(const IniFile *db, const std::string §ion)
|
SimConsole::unserialize(Checkpoint *cp, const std::string §ion)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ class SimConsole : public SimObject
|
||||||
void setInt(int bits);
|
void setInt(int bits);
|
||||||
|
|
||||||
virtual void serialize(std::ostream &os);
|
virtual void serialize(std::ostream &os);
|
||||||
virtual void unserialize(const IniFile *db, const std::string §ion);
|
virtual void unserialize(Checkpoint *cp, const std::string §ion);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConsoleListener : public SimObject
|
class ConsoleListener : public SimObject
|
||||||
|
|
|
@ -129,7 +129,7 @@ Event::serialize(std::ostream &os)
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Event::unserialize(const IniFile *db, const string §ion)
|
Event::unserialize(Checkpoint *cp, const string §ion)
|
||||||
{
|
{
|
||||||
if (scheduled())
|
if (scheduled())
|
||||||
deschedule();
|
deschedule();
|
||||||
|
@ -154,39 +154,51 @@ Event::unserialize(const IniFile *db, const string §ion)
|
||||||
void
|
void
|
||||||
EventQueue::nameChildren()
|
EventQueue::nameChildren()
|
||||||
{
|
{
|
||||||
#if 0
|
int numEvents = 0;
|
||||||
int j = 0;
|
|
||||||
|
|
||||||
Event *event = head;
|
Event *event = head;
|
||||||
while (event) {
|
while (event) {
|
||||||
stringstream stream;
|
if (event->getFlags(Event::AutoSerialize)) {
|
||||||
ccprintf(stream, "%s.event%d", name(), j++);
|
event->setName(csprintf("%s.event%d", name(), numEvents++));
|
||||||
event->setName(stream.str());
|
}
|
||||||
|
|
||||||
event = event->next;
|
event = event->next;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
numAutoSerializeEvents = numEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
EventQueue::serialize(ostream &os)
|
EventQueue::serialize(ostream &os)
|
||||||
{
|
{
|
||||||
#if 0
|
// should have been set by a preceding call to nameChildren()
|
||||||
string objects = "";
|
assert(numAutoSerializeEvents >= 0);
|
||||||
|
|
||||||
|
SERIALIZE_SCALAR(numAutoSerializeEvents);
|
||||||
|
|
||||||
|
int numEvents = 0;
|
||||||
Event *event = head;
|
Event *event = head;
|
||||||
while (event) {
|
while (event) {
|
||||||
objects += event->name();
|
if (event->getFlags(Event::AutoSerialize)) {
|
||||||
objects += " ";
|
event->nameOut(os);
|
||||||
event->serialize(os);
|
event->serialize(os);
|
||||||
|
numEvents++;
|
||||||
|
}
|
||||||
event = event->next;
|
event = event->next;
|
||||||
}
|
}
|
||||||
nameOut(os, "Serialized");
|
|
||||||
SERIALIZE_SCALAR(objects);
|
assert(numEvents == numAutoSerializeEvents);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
EventQueue::unserialize(Checkpoint *cp, const std::string §ion)
|
||||||
|
{
|
||||||
|
UNSERIALIZE_SCALAR(numAutoSerializeEvents);
|
||||||
|
for (int eventNum = 0; eventNum < numAutoSerializeEvents; ++eventNum) {
|
||||||
|
Serializeable::create(cp, csprintf("%s.event%d", section, eventNum));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
EventQueue::dump()
|
EventQueue::dump()
|
||||||
{
|
{
|
||||||
|
|
|
@ -73,7 +73,8 @@ class Event : public Serializeable, public FastAlloc
|
||||||
None = 0x0,
|
None = 0x0,
|
||||||
Squashed = 0x1,
|
Squashed = 0x1,
|
||||||
Scheduled = 0x2,
|
Scheduled = 0x2,
|
||||||
AutoDelete = 0x4
|
AutoDelete = 0x4,
|
||||||
|
AutoSerialize = 0x8
|
||||||
};
|
};
|
||||||
|
|
||||||
bool getFlags(Flags f) const { return (_flags & f) == f; }
|
bool getFlags(Flags f) const { return (_flags & f) == f; }
|
||||||
|
@ -190,7 +191,7 @@ class Event : public Serializeable, public FastAlloc
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void serialize(std::ostream &os);
|
virtual void serialize(std::ostream &os);
|
||||||
virtual void unserialize(const IniFile *db, const std::string §ion);
|
virtual void unserialize(Checkpoint *cp, const std::string §ion);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T, void (T::* F)()>
|
template <class T, void (T::* F)()>
|
||||||
|
@ -221,6 +222,9 @@ class EventQueue : public Serializeable
|
||||||
private:
|
private:
|
||||||
Event *head;
|
Event *head;
|
||||||
|
|
||||||
|
// only used to hold value between nameChildren() and serialize()
|
||||||
|
int numAutoSerializeEvents;
|
||||||
|
|
||||||
void insert(Event *event);
|
void insert(Event *event);
|
||||||
void remove(Event *event);
|
void remove(Event *event);
|
||||||
|
|
||||||
|
@ -228,7 +232,7 @@ class EventQueue : public Serializeable
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
EventQueue(const std::string &n)
|
EventQueue(const std::string &n)
|
||||||
: Serializeable(n), head(NULL)
|
: Serializeable(n), head(NULL), numAutoSerializeEvents(-1)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// schedule the given event on this queue
|
// schedule the given event on this queue
|
||||||
|
@ -264,6 +268,7 @@ class EventQueue : public Serializeable
|
||||||
|
|
||||||
virtual void nameChildren();
|
virtual void nameChildren();
|
||||||
virtual void serialize(std::ostream &os);
|
virtual void serialize(std::ostream &os);
|
||||||
|
virtual void unserialize(Checkpoint *cp, const std::string §ion);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ parseParam(const string &s, T &value)
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
showParam(ostream &os, const T &value)
|
showParam(ostream &os, T const &value)
|
||||||
{
|
{
|
||||||
os << value;
|
os << value;
|
||||||
}
|
}
|
||||||
|
@ -277,7 +277,7 @@ template VectorParam<type>;
|
||||||
// types that can use the above templates
|
// types that can use the above templates
|
||||||
#define INSTANTIATE_PARAM_TEMPLATES(type, typestr) \
|
#define INSTANTIATE_PARAM_TEMPLATES(type, typestr) \
|
||||||
template bool parseParam<type>(const string &s, type &value); \
|
template bool parseParam<type>(const string &s, type &value); \
|
||||||
template void showParam<type>(ostream &os, const type &value); \
|
template void showParam<type>(ostream &os, type const &value); \
|
||||||
template void Param<type>::parse(const string &); \
|
template void Param<type>::parse(const string &); \
|
||||||
template void VectorParam<type>::parse(const string &); \
|
template void VectorParam<type>::parse(const string &); \
|
||||||
template void Param<type>::showValue(ostream &) const; \
|
template void Param<type>::showValue(ostream &) const; \
|
||||||
|
|
112
sim/serialize.cc
112
sim/serialize.cc
|
@ -43,6 +43,7 @@
|
||||||
#include "sim/sim_events.hh"
|
#include "sim/sim_events.hh"
|
||||||
#include "sim/sim_object.hh"
|
#include "sim/sim_object.hh"
|
||||||
#include "base/trace.hh"
|
#include "base/trace.hh"
|
||||||
|
#include "sim/config_node.hh"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -88,11 +89,11 @@ paramOut(ostream &os, const std::string &name, const T& param)
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
paramIn(const IniFile *db, const std::string §ion,
|
paramIn(Checkpoint *cp, const std::string §ion,
|
||||||
const std::string &name, T& param)
|
const std::string &name, T& param)
|
||||||
{
|
{
|
||||||
std::string str;
|
std::string str;
|
||||||
if (!db->find(section, name, str) || !parseParam(str, param)) {
|
if (!cp->find(section, name, str) || !parseParam(str, param)) {
|
||||||
fatal("Can't unserialize '%s:%s'\n", section, name);
|
fatal("Can't unserialize '%s:%s'\n", section, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,11 +117,11 @@ arrayParamOut(ostream &os, const std::string &name,
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
arrayParamIn(const IniFile *db, const std::string §ion,
|
arrayParamIn(Checkpoint *cp, const std::string §ion,
|
||||||
const std::string &name, T *param, int size)
|
const std::string &name, T *param, int size)
|
||||||
{
|
{
|
||||||
std::string str;
|
std::string str;
|
||||||
if (!db->find(section, name, str)) {
|
if (!cp->find(section, name, str)) {
|
||||||
fatal("Can't unserialize '%s:%s'\n", section, name);
|
fatal("Can't unserialize '%s:%s'\n", section, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,17 +160,27 @@ arrayParamIn(const IniFile *db, const std::string §ion,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
objParamIn(Checkpoint *cp, const std::string §ion,
|
||||||
|
const std::string &name, Serializeable * ¶m)
|
||||||
|
{
|
||||||
|
if (!cp->findObj(section, name, param)) {
|
||||||
|
fatal("Can't unserialize '%s:%s'\n", section, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define INSTANTIATE_PARAM_TEMPLATES(type) \
|
#define INSTANTIATE_PARAM_TEMPLATES(type) \
|
||||||
template void \
|
template void \
|
||||||
paramOut(ostream &os, const std::string &name, const type ¶m); \
|
paramOut(ostream &os, const std::string &name, type const ¶m); \
|
||||||
template void \
|
template void \
|
||||||
paramIn(const IniFile *db, const std::string §ion, \
|
paramIn(Checkpoint *cp, const std::string §ion, \
|
||||||
const std::string &name, type & param); \
|
const std::string &name, type & param); \
|
||||||
template void \
|
template void \
|
||||||
arrayParamOut(ostream &os, const std::string &name, \
|
arrayParamOut(ostream &os, const std::string &name, \
|
||||||
const type *param, int size); \
|
type const *param, int size); \
|
||||||
template void \
|
template void \
|
||||||
arrayParamIn(const IniFile *db, const std::string §ion, \
|
arrayParamIn(Checkpoint *cp, const std::string §ion, \
|
||||||
const std::string &name, type *param, int size);
|
const std::string &name, type *param, int size);
|
||||||
|
|
||||||
|
|
||||||
|
@ -421,41 +432,74 @@ SerializeableClass::SerializeableClass(const string &className,
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
Serializeable *
|
Serializeable *
|
||||||
SerializeableClass::createObject(IniFile &configDB,
|
SerializeableClass::createObject(Checkpoint *cp,
|
||||||
const string &configClassName)
|
const std::string §ion)
|
||||||
{
|
{
|
||||||
// find simulation object class name from configuration class
|
string className;
|
||||||
// (specified by 'type=' parameter)
|
|
||||||
string simObjClassName;
|
|
||||||
|
|
||||||
if (!configDB.findDefault(configClassName, "type", simObjClassName)) {
|
if (!cp->find(section, "type", className)) {
|
||||||
cerr << "Configuration class '" << configClassName << "' not found."
|
fatal("Serializeable::create: no 'type' entry in section '%s'.\n",
|
||||||
<< endl;
|
section);
|
||||||
abort();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// look up className to get appropriate createFunc
|
CreateFunc createFunc = (*classMap)[className];
|
||||||
if (classMap->find(simObjClassName) == classMap->end()) {
|
|
||||||
cerr << "Simulator object class '" << simObjClassName << "' not found."
|
if (createFunc == NULL) {
|
||||||
<< endl;
|
fatal("Serializeable::create: no create function for class '%s'.\n",
|
||||||
abort();
|
className);
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateFunc createFunc = (*classMap)[simObjClassName];
|
Serializeable *object = createFunc(cp, section);
|
||||||
|
|
||||||
// builder instance
|
|
||||||
SerializeableBuilder *objectBuilder = (*createFunc)();
|
|
||||||
|
|
||||||
assert(objectBuilder != NULL);
|
|
||||||
|
|
||||||
// now create the actual simulation object
|
|
||||||
Serializeable *object = objectBuilder->create();
|
|
||||||
|
|
||||||
assert(object != NULL);
|
assert(object != NULL);
|
||||||
|
|
||||||
// done with the SerializeableBuilder now
|
|
||||||
delete objectBuilder;
|
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Serializeable *
|
||||||
|
Serializeable::create(Checkpoint *cp, const std::string §ion)
|
||||||
|
{
|
||||||
|
Serializeable *object = SerializeableClass::createObject(cp, section);
|
||||||
|
object->unserialize(cp, section);
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Checkpoint::Checkpoint(const std::string &filename, const std::string &path,
|
||||||
|
const ConfigNode *_configNode)
|
||||||
|
: db(new IniFile), basePath(path), configNode(_configNode)
|
||||||
|
{
|
||||||
|
if (!db->load(filename)) {
|
||||||
|
fatal("Can't load checkpoint file '%s'\n", filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
mainEventQueue.unserialize(this, "MainEventQueue");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Checkpoint::find(const std::string §ion, const std::string &entry,
|
||||||
|
std::string &value)
|
||||||
|
{
|
||||||
|
return db->find(section, entry, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Checkpoint::findObj(const std::string §ion, const std::string &entry,
|
||||||
|
Serializeable *&value)
|
||||||
|
{
|
||||||
|
string path;
|
||||||
|
|
||||||
|
if (!db->find(section, entry, path))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if ((value = configNode->resolveSimObject(path)) != NULL)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if ((value = objMap[path]) != NULL)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -41,13 +41,14 @@
|
||||||
#include "sim/host.hh"
|
#include "sim/host.hh"
|
||||||
#include "sim/configfile.hh"
|
#include "sim/configfile.hh"
|
||||||
|
|
||||||
class IniFile;
|
class Serializeable;
|
||||||
|
class Checkpoint;
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void paramOut(std::ostream &os, const std::string &name, const T& param);
|
void paramOut(std::ostream &os, const std::string &name, const T& param);
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void paramIn(const IniFile *db, const std::string §ion,
|
void paramIn(Checkpoint *cp, const std::string §ion,
|
||||||
const std::string &name, T& param);
|
const std::string &name, T& param);
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
|
@ -55,16 +56,21 @@ void arrayParamOut(std::ostream &os, const std::string &name,
|
||||||
const T *param, int size);
|
const T *param, int size);
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void arrayParamIn(const IniFile *db, const std::string §ion,
|
void arrayParamIn(Checkpoint *cp, const std::string §ion,
|
||||||
const std::string &name, T *param, int size);
|
const std::string &name, T *param, int size);
|
||||||
|
|
||||||
|
void
|
||||||
|
objParamIn(Checkpoint *cp, const std::string §ion,
|
||||||
|
const std::string &name, Serializeable * ¶m);
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// These macros are streamlined to use in serialize/unserialize
|
// These macros are streamlined to use in serialize/unserialize
|
||||||
// functions. It's assumed that serialize() has a parameter 'os' for
|
// functions. It's assumed that serialize() has a parameter 'os' for
|
||||||
// the ostream, and unserialize() has parameters 'db' and 'section'.
|
// the ostream, and unserialize() has parameters 'cp' and 'section'.
|
||||||
#define SERIALIZE_SCALAR(scalar) paramOut(os, #scalar, scalar)
|
#define SERIALIZE_SCALAR(scalar) paramOut(os, #scalar, scalar)
|
||||||
|
|
||||||
#define UNSERIALIZE_SCALAR(scalar) paramIn(db, section, #scalar, scalar)
|
#define UNSERIALIZE_SCALAR(scalar) paramIn(cp, section, #scalar, scalar)
|
||||||
|
|
||||||
// ENUMs are like SCALARs, but we cast them to ints on the way out
|
// ENUMs are like SCALARs, but we cast them to ints on the way out
|
||||||
#define SERIALIZE_ENUM(scalar) paramOut(os, #scalar, (int)scalar)
|
#define SERIALIZE_ENUM(scalar) paramOut(os, #scalar, (int)scalar)
|
||||||
|
@ -72,7 +78,7 @@ void arrayParamIn(const IniFile *db, const std::string §ion,
|
||||||
#define UNSERIALIZE_ENUM(scalar) \
|
#define UNSERIALIZE_ENUM(scalar) \
|
||||||
do { \
|
do { \
|
||||||
int tmp; \
|
int tmp; \
|
||||||
paramIn(db, section, #scalar, tmp); \
|
paramIn(cp, section, #scalar, tmp); \
|
||||||
scalar = (typeof(scalar))tmp; \
|
scalar = (typeof(scalar))tmp; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
@ -80,7 +86,16 @@ void arrayParamIn(const IniFile *db, const std::string §ion,
|
||||||
arrayParamOut(os, #member, member, size)
|
arrayParamOut(os, #member, member, size)
|
||||||
|
|
||||||
#define UNSERIALIZE_ARRAY(member, size) \
|
#define UNSERIALIZE_ARRAY(member, size) \
|
||||||
arrayParamIn(db, section, #member, member, size)
|
arrayParamIn(cp, section, #member, member, size)
|
||||||
|
|
||||||
|
#define SERIALIZE_OBJPTR(objptr) paramOut(os, #objptr, (objptr)->name())
|
||||||
|
|
||||||
|
#define UNSERIALIZE_OBJPTR(objptr) \
|
||||||
|
do { \
|
||||||
|
Serializeable *sptr; \
|
||||||
|
objParamIn(cp, section, #objptr, sptr); \
|
||||||
|
objptr = dynamic_cast<typeof(objptr)>(sptr); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Basic support for object serialization.
|
* Basic support for object serialization.
|
||||||
|
@ -113,7 +128,10 @@ class Serializeable
|
||||||
|
|
||||||
virtual void nameChildren() {}
|
virtual void nameChildren() {}
|
||||||
virtual void serialize(std::ostream& os) {}
|
virtual void serialize(std::ostream& os) {}
|
||||||
virtual void unserialize(const IniFile *db, const std::string §ion) {}
|
virtual void unserialize(Checkpoint *cp, const std::string §ion) {}
|
||||||
|
|
||||||
|
static Serializeable *create(Checkpoint *cp,
|
||||||
|
const std::string §ion);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Serializer
|
class Serializer
|
||||||
|
@ -187,7 +205,8 @@ class SerializeableClass
|
||||||
// for the object (specified by the second string argument), and
|
// for the object (specified by the second string argument), and
|
||||||
// an optional config hierarchy node (specified by the third
|
// an optional config hierarchy node (specified by the third
|
||||||
// argument). A pointer to the new SerializeableBuilder is returned.
|
// argument). A pointer to the new SerializeableBuilder is returned.
|
||||||
typedef SerializeableBuilder *(*CreateFunc)();
|
typedef Serializeable *(*CreateFunc)(Checkpoint *cp,
|
||||||
|
const std::string §ion);
|
||||||
|
|
||||||
static std::map<std::string,CreateFunc> *classMap;
|
static std::map<std::string,CreateFunc> *classMap;
|
||||||
|
|
||||||
|
@ -200,9 +219,8 @@ class SerializeableClass
|
||||||
|
|
||||||
// create Serializeable given name of class and pointer to
|
// create Serializeable given name of class and pointer to
|
||||||
// configuration hierarchy node
|
// configuration hierarchy node
|
||||||
static Serializeable *createObject(IniFile &configDB,
|
static Serializeable *createObject(Checkpoint *cp,
|
||||||
const std::string &configClassName);
|
const std::string §ion);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -210,29 +228,29 @@ class SerializeableClass
|
||||||
// SerializeableBuilder and SerializeableClass objects
|
// SerializeableBuilder and SerializeableClass objects
|
||||||
//
|
//
|
||||||
|
|
||||||
#define CREATE_SERIALIZEABLE(OBJ_CLASS) \
|
#define REGISTER_SERIALIZEABLE(CLASS_NAME, OBJ_CLASS) \
|
||||||
OBJ_CLASS *OBJ_CLASS##Builder::create()
|
SerializeableClass the##OBJ_CLASS##Class(CLASS_NAME, \
|
||||||
|
OBJ_CLASS::createForUnserialize);
|
||||||
|
|
||||||
#define REGISTER_SERIALIZEABLE(CLASS_NAME, OBJ_CLASS) \
|
class Checkpoint
|
||||||
class OBJ_CLASS##Builder : public SerializeableBuilder \
|
{
|
||||||
{ \
|
private:
|
||||||
public: \
|
|
||||||
\
|
IniFile *db;
|
||||||
OBJ_CLASS##Builder() {} \
|
const std::string basePath;
|
||||||
virtual ~OBJ_CLASS##Builder() {} \
|
const ConfigNode *configNode;
|
||||||
\
|
std::map<std::string, Serializeable*> objMap;
|
||||||
OBJ_CLASS *create(); \
|
|
||||||
}; \
|
public:
|
||||||
\
|
Checkpoint(const std::string &filename, const std::string &path,
|
||||||
\
|
const ConfigNode *_configNode);
|
||||||
SerializeableBuilder * \
|
|
||||||
new##OBJ_CLASS##Builder() \
|
bool find(const std::string §ion, const std::string &entry,
|
||||||
{ \
|
std::string &value);
|
||||||
return new OBJ_CLASS##Builder(); \
|
|
||||||
} \
|
bool findObj(const std::string §ion, const std::string &entry,
|
||||||
\
|
Serializeable *&value);
|
||||||
SerializeableClass the##OBJ_CLASS##Class(CLASS_NAME, \
|
};
|
||||||
new##OBJ_CLASS##Builder);
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue