Changed the naming of Serializeable derived objects. Serializeable no longer has

objName as a member, instead it has the pure virtual function name().  SimObject
now has a objName member, and all classes derived directly from Serializeable
have to implement a name() function (which now makes them unique by pointer value)

cpu/simple_cpu/simple_cpu.cc:
    Change initialization of Event to get rid of Serializeable naming
dev/etherlink.cc:
dev/etherlink.hh:
    Seralizeable derived naming changes
sim/eventq.cc:
    Serializeable derived naming changes, also changed serialization process so it
    doesn't need to use nameChildren
sim/eventq.hh:
    Serializeable derived naming changes, remove constructor for specifying event name
sim/serialize.cc:
    Serializeable derived naming changes, remove setName function and the child naming
    pass for serialization
sim/serialize.hh:
    Serializeable derived naming changes, removed nameChildren, setName
sim/sim_object.cc:
sim/sim_object.hh:
    Serializeable derived naming changes

--HG--
extra : convert_revision : 67bcc275b6c210f7049f98a1ad0d22e8f5596a63
This commit is contained in:
Andrew Schultz 2003-10-31 17:32:04 -05:00
parent b5fc3af142
commit 2ab51fbcdb
9 changed files with 55 additions and 88 deletions

View file

@ -76,7 +76,7 @@
using namespace std; using namespace std;
SimpleCPU::TickEvent::TickEvent(SimpleCPU *c) SimpleCPU::TickEvent::TickEvent(SimpleCPU *c)
: Event(&mainEventQueue, "SimpleCPU::TickEvent", 100), cpu(c) : Event(&mainEventQueue, 100), cpu(c)
{ {
} }
@ -94,7 +94,7 @@ SimpleCPU::TickEvent::description()
SimpleCPU::CacheCompletionEvent::CacheCompletionEvent(SimpleCPU *_cpu) SimpleCPU::CacheCompletionEvent::CacheCompletionEvent(SimpleCPU *_cpu)
: Event(&mainEventQueue, "SimpleCPU::CacheCompletionEvent"), : Event(&mainEventQueue),
cpu(_cpu) cpu(_cpu)
{ {
} }

View file

@ -80,7 +80,7 @@ EtherLink::Interface::Interface(const std::string &name, Link *tx, Link *rx)
} }
EtherLink::Link::Link(const std::string &name, double rate, EtherDump *d) EtherLink::Link::Link(const std::string &name, double rate, EtherDump *d)
: Serializeable(name), txint(NULL), rxint(NULL), ticks_per_byte(rate), : objName(name), txint(NULL), rxint(NULL), ticks_per_byte(rate),
dump(d), event(&mainEventQueue, this) dump(d), event(&mainEventQueue, this)
{} {}

View file

@ -54,6 +54,8 @@ class EtherLink : public SimObject
*/ */
class Link : public Serializeable { class Link : public Serializeable {
protected: protected:
std::string objName;
Interface *txint; Interface *txint;
Interface *rxint; Interface *rxint;
@ -87,6 +89,8 @@ class EtherLink : public SimObject
Link(const std::string &name, double rate, EtherDump *dump); Link(const std::string &name, double rate, EtherDump *dump);
~Link() {} ~Link() {}
virtual std::string name() const { return objName; }
bool busy() const { return (bool)packet; } bool busy() const { return (bool)packet; }
bool transmit(PacketPtr packet); bool transmit(PacketPtr packet);

View file

@ -150,55 +150,53 @@ Event::unserialize(Checkpoint *cp, const string &section)
} }
} }
void
EventQueue::nameChildren()
{
int numEvents = 0;
Event *event = head;
while (event) {
if (event->getFlags(Event::AutoSerialize)) {
event->setName(csprintf("%s.event%d", name(), numEvents++));
}
event = event->next;
}
numAutoSerializeEvents = numEvents;
}
void void
EventQueue::serialize(ostream &os) EventQueue::serialize(ostream &os)
{ {
// should have been set by a preceding call to nameChildren() std::list<Event *> eventPtrs;
assert(numAutoSerializeEvents >= 0);
SERIALIZE_SCALAR(numAutoSerializeEvents);
int numEvents = 0; int numEvents = 0;
Event *event = head; Event *event = head;
while (event) { while (event) {
if (event->getFlags(Event::AutoSerialize)) { if (event->getFlags(Event::AutoSerialize)) {
event->nameOut(os); eventPtrs.push_back(event);
event->serialize(os);
numEvents++; numEvents++;
} }
event = event->next; event = event->next;
} }
assert(numEvents == numAutoSerializeEvents); SERIALIZE_SCALAR(numEvents);
}
int i = 0;
for (std::list<Event *>::iterator it=eventPtrs.begin();
it != eventPtrs.end(); ++it) {
paramOut(os, csprintf("%s.eventPtr%d", name(), i++), (uintptr_t)*it);
}
for (std::list<Event *>::iterator it=eventPtrs.begin();
it != eventPtrs.end(); ++it) {
(*it)->nameOut(os);
(*it)->serialize(os);
}
}
void void
EventQueue::unserialize(Checkpoint *cp, const std::string &section) EventQueue::unserialize(Checkpoint *cp, const std::string &section)
{ {
UNSERIALIZE_SCALAR(numAutoSerializeEvents); int numEvents;
for (int eventNum = 0; eventNum < numAutoSerializeEvents; ++eventNum) { uintptr_t ptr;
Serializeable::create(cp, csprintf("%s.event%d", section, eventNum));
UNSERIALIZE_SCALAR(numEvents);
for (int i = 0; i < numEvents; i++) {
// get the pointer value associated with the event
paramIn(cp, section, csprintf("%s.eventPtr%d", name(), i), ptr);
// create the event based on its pointer value
Serializeable::create(cp, csprintf("%s_%x", Event::defaultName, ptr));
} }
} }
void void
EventQueue::dump() EventQueue::dump()
{ {

View file

@ -104,22 +104,7 @@ class Event : public Serializeable, public FastAlloc
* @param queue that the event gets scheduled on * @param queue that the event gets scheduled on
*/ */
Event(EventQueue *q, int p = 0) Event(EventQueue *q, int p = 0)
: Serializeable(defaultName), queue(q), next(NULL), : queue(q), next(NULL), _priority(p), _flags(None),
_priority(p), _flags(None),
#if TRACING_ON
when_created(curTick), when_scheduled(0),
#endif
annotated_value(0)
{
}
/*
* Event constructor
* @param queue that the event gets scheduled on
*/
Event(EventQueue *q, std::string _name, int p = 0)
: Serializeable(_name), queue(q), next(NULL),
_priority(p), _flags(None),
#if TRACING_ON #if TRACING_ON
when_created(curTick), when_scheduled(0), when_created(curTick), when_scheduled(0),
#endif #endif
@ -129,6 +114,10 @@ class Event : public Serializeable, public FastAlloc
~Event() {} ~Event() {}
virtual std::string name() const {
return csprintf("%s_%x", defaultName, (uintptr_t)this);
}
/// Determine if the current event is scheduled /// Determine if the current event is scheduled
bool scheduled() const { return getFlags(Scheduled); } bool scheduled() const { return getFlags(Scheduled); }
@ -219,12 +208,12 @@ DelayFunction(Tick when, T *object)
*/ */
class EventQueue : public Serializeable class EventQueue : public Serializeable
{ {
protected:
std::string objName;
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);
@ -232,9 +221,11 @@ class EventQueue : public Serializeable
// constructor // constructor
EventQueue(const std::string &n) EventQueue(const std::string &n)
: Serializeable(n), head(NULL), numAutoSerializeEvents(-1) : objName(n), head(NULL)
{} {}
virtual std::string name() const { return objName; }
// schedule the given event on this queue // schedule the given event on this queue
void schedule(Event *ev); void schedule(Event *ev);
void deschedule(Event *ev); void deschedule(Event *ev);
@ -266,7 +257,6 @@ class EventQueue : public Serializeable
Tick nextEventTime() { return empty() ? curTick : head->when(); } Tick nextEventTime() { return empty() ? curTick : head->when(); }
virtual void nameChildren();
virtual void serialize(std::ostream &os); virtual void serialize(std::ostream &os);
virtual void unserialize(Checkpoint *cp, const std::string &section); virtual void unserialize(Checkpoint *cp, const std::string &section);
}; };

View file

@ -49,8 +49,8 @@ using namespace std;
Serializer *Serializeable::serializer = NULL; Serializer *Serializeable::serializer = NULL;
Serializeable::Serializeable(const string &n) Serializeable::Serializeable()
: objName(n), serialized(false) : serialized(false)
{ } { }
Serializeable::~Serializeable() Serializeable::~Serializeable()
@ -209,16 +209,6 @@ Serializeable::childOut(const string &name, Serializeable *child)
} }
#endif #endif
void
Serializeable::setName(const string &name)
{
if (objName != "") {
cprintf("Renaming object '%s' to '%s'.\n", objName, name);
}
objName = name;
}
Serializer::Serializer() Serializer::Serializer()
{ } { }
@ -270,20 +260,6 @@ Serializer::serialize(const string &f)
serlist_t list; serlist_t list;
add_objects();
while (!objects.empty()) {
Serializeable *serial = objects.front();
DPRINTF(Serialize, "Naming children of %s\n", serial->name());
serial->nameChildren();
objects.pop_front();
list.push_back(serial);
}
while (!list.empty()) {
list.front()->serialized = false;
list.pop_front();
}
add_objects(); add_objects();
while (!objects.empty()) { while (!objects.empty()) {
Serializeable *obj = objects.front(); Serializeable *obj = objects.front();

View file

@ -107,9 +107,6 @@ class Serializeable
friend class Serializer; friend class Serializer;
protected: protected:
// object name: should be unique
std::string objName;
bool serialized; bool serialized;
static Serializer *serializer; static Serializer *serializer;
@ -118,15 +115,12 @@ class Serializeable
void nameOut(std::ostream& os, const std::string &_name); void nameOut(std::ostream& os, const std::string &_name);
public: public:
Serializeable(const std::string &n); Serializeable();
virtual ~Serializeable(); virtual ~Serializeable();
void setName(const std::string &name); // manditory virtual function, so objects must provide names
virtual std::string name() const = 0;
// return name
const std::string &name() const { return objName; }
virtual void nameChildren() {}
virtual void serialize(std::ostream& os) {} virtual void serialize(std::ostream& os) {}
virtual void unserialize(Checkpoint *cp, const std::string &section) {} virtual void unserialize(Checkpoint *cp, const std::string &section) {}

View file

@ -54,7 +54,7 @@ SimObject::SimObjectList SimObject::simObjectList;
// SimObject constructor: used to maintain static simObjectList // SimObject constructor: used to maintain static simObjectList
// //
SimObject::SimObject(const string &_name) SimObject::SimObject(const string &_name)
: Serializeable(_name) : objName(_name)
{ {
simObjectList.push_back(this); simObjectList.push_back(this);
} }

View file

@ -47,6 +47,9 @@
*/ */
class SimObject : public Serializeable class SimObject : public Serializeable
{ {
protected:
std::string objName;
private: private:
friend class Serializer; friend class Serializer;
@ -60,6 +63,8 @@ class SimObject : public Serializeable
virtual ~SimObject() {} virtual ~SimObject() {}
virtual std::string name() const { return objName; }
// register statistics for this object // register statistics for this object
virtual void regStats(); virtual void regStats();
virtual void regFormulas(); virtual void regFormulas();