sim_object.hh revision 1762
113219Sodanrc@yahoo.com.br/* 213219Sodanrc@yahoo.com.br * Copyright (c) 2001-2005 The Regents of The University of Michigan 313219Sodanrc@yahoo.com.br * All rights reserved. 413219Sodanrc@yahoo.com.br * 513219Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without 613219Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are 713219Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright 813219Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer; 913219Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright 1013219Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the 1113219Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution; 1213219Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its 1313219Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from 1413219Sodanrc@yahoo.com.br * this software without specific prior written permission. 1513219Sodanrc@yahoo.com.br * 1613219Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1713219Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1813219Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1913219Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2013219Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2113219Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2213219Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2313219Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2413219Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2513219Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2613219Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2713219Sodanrc@yahoo.com.br */ 2813219Sodanrc@yahoo.com.br 2913219Sodanrc@yahoo.com.br/* @file 3013219Sodanrc@yahoo.com.br * User Console Definitions 3113219Sodanrc@yahoo.com.br */ 3213219Sodanrc@yahoo.com.br 3313219Sodanrc@yahoo.com.br#ifndef __SIM_OBJECT_HH__ 3413219Sodanrc@yahoo.com.br#define __SIM_OBJECT_HH__ 3513219Sodanrc@yahoo.com.br 3613219Sodanrc@yahoo.com.br#include <map> 3713219Sodanrc@yahoo.com.br#include <list> 3813219Sodanrc@yahoo.com.br#include <vector> 3913219Sodanrc@yahoo.com.br#include <iostream> 4013219Sodanrc@yahoo.com.br 4113219Sodanrc@yahoo.com.br#include "sim/serialize.hh" 4213219Sodanrc@yahoo.com.br#include "sim/startup.hh" 4313219Sodanrc@yahoo.com.br 4413219Sodanrc@yahoo.com.br/* 4513219Sodanrc@yahoo.com.br * Abstract superclass for simulation objects. Represents things that 4613219Sodanrc@yahoo.com.br * correspond to physical components and can be specified via the 4713219Sodanrc@yahoo.com.br * config file (CPUs, caches, etc.). 4813219Sodanrc@yahoo.com.br */ 4913219Sodanrc@yahoo.com.brclass SimObject : public Serializable, protected StartupCallback 5013219Sodanrc@yahoo.com.br{ 5113219Sodanrc@yahoo.com.br public: 5213219Sodanrc@yahoo.com.br struct Params { 5313219Sodanrc@yahoo.com.br std::string name; 5413219Sodanrc@yahoo.com.br }; 5513219Sodanrc@yahoo.com.br 5613219Sodanrc@yahoo.com.br protected: 5713219Sodanrc@yahoo.com.br Params *_params; 5813219Sodanrc@yahoo.com.br 5913219Sodanrc@yahoo.com.br public: 6013219Sodanrc@yahoo.com.br const Params *params() const { return _params; } 6113219Sodanrc@yahoo.com.br 6213219Sodanrc@yahoo.com.br private: 6313219Sodanrc@yahoo.com.br friend class Serializer; 6413219Sodanrc@yahoo.com.br 6513219Sodanrc@yahoo.com.br typedef std::vector<SimObject *> SimObjectList; 6613219Sodanrc@yahoo.com.br 6713219Sodanrc@yahoo.com.br // list of all instantiated simulation objects 6813219Sodanrc@yahoo.com.br static SimObjectList simObjectList; 6913219Sodanrc@yahoo.com.br 7013219Sodanrc@yahoo.com.br public: 7113219Sodanrc@yahoo.com.br SimObject(Params *_params); 7213219Sodanrc@yahoo.com.br SimObject(const std::string &_name); 7313219Sodanrc@yahoo.com.br 7413219Sodanrc@yahoo.com.br virtual ~SimObject() {} 7513219Sodanrc@yahoo.com.br 7613219Sodanrc@yahoo.com.br virtual const std::string name() const { return params()->name; } 7713219Sodanrc@yahoo.com.br 7813219Sodanrc@yahoo.com.br // initialization pass of all objects. 7913219Sodanrc@yahoo.com.br // Gets invoked after construction, before unserialize. 8013219Sodanrc@yahoo.com.br virtual void init(); 8113219Sodanrc@yahoo.com.br static void initAll(); 8213219Sodanrc@yahoo.com.br 83 // register statistics for this object 84 virtual void regStats(); 85 virtual void regFormulas(); 86 virtual void resetStats(); 87 88 // static: call reg_stats on all SimObjects 89 static void regAllStats(); 90 91 // static: call resetStats on all SimObjects 92 static void resetAllStats(); 93 94 // static: call nameOut() & serialize() on all SimObjects 95 static void serializeAll(std::ostream &); 96 97#ifdef DEBUG 98 public: 99 bool doDebugBreak; 100 static void debugObjectBreak(const std::string &objs); 101#endif 102 103 public: 104 bool doRecordEvent; 105 void recordEvent(const std::string &stat); 106}; 107 108#endif // __SIM_OBJECT_HH__ 109