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
using namespace std;
SimpleCPU::TickEvent::TickEvent(SimpleCPU *c)
- : Event(&mainEventQueue, "SimpleCPU::TickEvent", 100), cpu(c)
+ : Event(&mainEventQueue, 100), cpu(c)
{
}
SimpleCPU::CacheCompletionEvent::CacheCompletionEvent(SimpleCPU *_cpu)
- : Event(&mainEventQueue, "SimpleCPU::CacheCompletionEvent"),
+ : Event(&mainEventQueue),
cpu(_cpu)
{
}
}
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)
{}
*/
class Link : public Serializeable {
protected:
+ std::string objName;
+
Interface *txint;
Interface *rxint;
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);
}
}
-
-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 §ion)
{
- 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()
{
* @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
~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); }
*/
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);
// 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);
Tick nextEventTime() { return empty() ? curTick : head->when(); }
- virtual void nameChildren();
virtual void serialize(std::ostream &os);
virtual void unserialize(Checkpoint *cp, const std::string §ion);
};
Serializer *Serializeable::serializer = NULL;
-Serializeable::Serializeable(const string &n)
- : objName(n), serialized(false)
+Serializeable::Serializeable()
+ : serialized(false)
{ }
Serializeable::~Serializeable()
}
#endif
-void
-Serializeable::setName(const string &name)
-{
- if (objName != "") {
- cprintf("Renaming object '%s' to '%s'.\n", objName, name);
- }
-
- objName = name;
-}
-
Serializer::Serializer()
{ }
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();
friend class Serializer;
protected:
- // object name: should be unique
- std::string objName;
-
bool serialized;
static Serializer *serializer;
void nameOut(std::ostream& os, const std::string &_name);
public:
- Serializeable(const std::string &n);
+ Serializeable();
virtual ~Serializeable();
- void setName(const std::string &name);
-
- // return name
- const std::string &name() const { return objName; }
+ // manditory virtual function, so objects must provide names
+ virtual std::string name() const = 0;
- virtual void nameChildren() {}
virtual void serialize(std::ostream& os) {}
virtual void unserialize(Checkpoint *cp, const std::string §ion) {}
// SimObject constructor: used to maintain static simObjectList
//
SimObject::SimObject(const string &_name)
- : Serializeable(_name)
+ : objName(_name)
{
simObjectList.push_back(this);
}
*/
class SimObject : public Serializeable
{
+ protected:
+ std::string objName;
+
private:
friend class Serializer;
virtual ~SimObject() {}
+ virtual std::string name() const { return objName; }
+
// register statistics for this object
virtual void regStats();
virtual void regFormulas();