2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "base/callback.hh"
32 #include "base/inifile.hh"
33 #include "base/match.hh"
34 #include "base/misc.hh"
35 #include "base/trace.hh"
36 #include "base/stats/events.hh"
37 #include "base/serializer.hh"
38 #include "sim/configfile.hh"
39 #include "sim/host.hh"
40 #include "sim/sim_object.hh"
41 #include "sim/stats.hh"
42 #include "sim/param.hh"
47 ////////////////////////////////////////////////////////////////////////
49 // SimObject member definitions
51 ////////////////////////////////////////////////////////////////////////
54 // static list of all SimObjects, used for initialization etc.
56 SimObject::SimObjectList
SimObject::simObjectList
;
59 extern ObjectMatch event_ignore
;
63 // SimObject constructor: used to maintain static simObjectList
65 SimObject::SimObject(Params
*p
)
72 doRecordEvent
= !Stats::event_ignore
.match(name());
73 simObjectList
.push_back(this);
77 // SimObject constructor: used to maintain static simObjectList
79 SimObject::SimObject(const string
&_name
)
82 _params
->name
= _name
;
87 doRecordEvent
= !Stats::event_ignore
.match(name());
88 simObjectList
.push_back(this);
102 // no default statistics, so nothing to do in base implementation
105 SimObject::regStats()
110 SimObject::regFormulas()
115 SimObject::resetStats()
121 // call regStats() on all SimObjects and then regFormulas() on all
124 struct SimObjectResetCB
: public Callback
126 virtual void process() { SimObject::resetAllStats(); }
130 static SimObjectResetCB StatResetCB
;
134 SimObject::regAllStats()
136 SimObjectList::iterator i
;
137 SimObjectList::iterator end
= simObjectList
.end();
140 * @todo change cprintfs to DPRINTFs
142 for (i
= simObjectList
.begin(); i
!= end
; ++i
) {
144 cprintf("registering stats for %s\n", (*i
)->name());
149 for (i
= simObjectList
.begin(); i
!= end
; ++i
) {
151 cprintf("registering formulas for %s\n", (*i
)->name());
156 Stats::registerResetCallback(&StatResetCB
);
160 // static function: call connect() on all SimObjects.
163 SimObject::connectAll()
165 SimObjectList::iterator i
= simObjectList
.begin();
166 SimObjectList::iterator end
= simObjectList
.end();
168 for (; i
!= end
; ++i
) {
175 // static function: call init() on all SimObjects.
180 SimObjectList::iterator i
= simObjectList
.begin();
181 SimObjectList::iterator end
= simObjectList
.end();
183 for (; i
!= end
; ++i
) {
190 // static function: call resetStats() on all SimObjects.
193 SimObject::resetAllStats()
195 SimObjectList::iterator i
= simObjectList
.begin();
196 SimObjectList::iterator end
= simObjectList
.end();
198 for (; i
!= end
; ++i
) {
205 // static function: serialize all SimObjects.
208 SimObject::serializeAll(ostream
&os
)
210 SimObjectList::reverse_iterator ri
= simObjectList
.rbegin();
211 SimObjectList::reverse_iterator rend
= simObjectList
.rend();
213 for (; ri
!= rend
; ++ri
) {
214 SimObject
*obj
= *ri
;
222 // static function: flag which objects should have the debugger break
225 SimObject::debugObjectBreak(const string
&objs
)
227 SimObjectList::const_iterator i
= simObjectList
.begin();
228 SimObjectList::const_iterator end
= simObjectList
.end();
230 ObjectMatch
match(objs
);
231 for (; i
!= end
; ++i
) {
233 obj
->doDebugBreak
= match
.match(obj
->name());
239 debugObjectBreak(const char *objs
)
241 SimObject::debugObjectBreak(string(objs
));
246 SimObject::recordEvent(const std::string
&stat
)
249 Stats::recordEvent(stat
);
253 SimObject::drain(Serializer
*serializer
)
255 serializer
->signalDrained();
258 DEFINE_SIM_OBJECT_CLASS_NAME("SimObject", SimObject
)