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;
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)
: Event(&mainEventQueue, "SimpleCPU::CacheCompletionEvent"),
: Event(&mainEventQueue),
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)
: 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)
{}

View file

@ -54,6 +54,8 @@ class EtherLink : public SimObject
*/
class Link : public Serializeable {
protected:
std::string objName;
Interface *txint;
Interface *rxint;
@ -87,6 +89,8 @@ class EtherLink : public SimObject
Link(const std::string &name, double rate, EtherDump *dump);
~Link() {}
virtual std::string name() const { return objName; }
bool busy() const { return (bool)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
EventQueue::serialize(ostream &os)
{
// should have been set by a preceding call to nameChildren()
assert(numAutoSerializeEvents >= 0);
SERIALIZE_SCALAR(numAutoSerializeEvents);
std::list<Event *> eventPtrs;
int numEvents = 0;
Event *event = head;
while (event) {
if (event->getFlags(Event::AutoSerialize)) {
event->nameOut(os);
event->serialize(os);
eventPtrs.push_back(event);
numEvents++;
}
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
EventQueue::unserialize(Checkpoint *cp, const std::string &section)
{
UNSERIALIZE_SCALAR(numAutoSerializeEvents);
for (int eventNum = 0; eventNum < numAutoSerializeEvents; ++eventNum) {
Serializeable::create(cp, csprintf("%s.event%d", section, eventNum));
int numEvents;
uintptr_t ptr;
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
EventQueue::dump()
{

View file

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

View file

@ -49,8 +49,8 @@ using namespace std;
Serializer *Serializeable::serializer = NULL;
Serializeable::Serializeable(const string &n)
: objName(n), serialized(false)
Serializeable::Serializeable()
: serialized(false)
{ }
Serializeable::~Serializeable()
@ -209,16 +209,6 @@ Serializeable::childOut(const string &name, Serializeable *child)
}
#endif
void
Serializeable::setName(const string &name)
{
if (objName != "") {
cprintf("Renaming object '%s' to '%s'.\n", objName, name);
}
objName = name;
}
Serializer::Serializer()
{ }
@ -270,20 +260,6 @@ Serializer::serialize(const string &f)
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();
while (!objects.empty()) {
Serializeable *obj = objects.front();

View file

@ -107,9 +107,6 @@ class Serializeable
friend class Serializer;
protected:
// object name: should be unique
std::string objName;
bool serialized;
static Serializer *serializer;
@ -118,15 +115,12 @@ class Serializeable
void nameOut(std::ostream& os, const std::string &_name);
public:
Serializeable(const std::string &n);
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 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::SimObject(const string &_name)
: Serializeable(_name)
: objName(_name)
{
simObjectList.push_back(this);
}

View file

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