base: Tag API methods in amo.hh
[gem5.git] / src / sim / sim_object.cc
1 /*
2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
3 * Copyright (c) 2010 Advanced Micro Devices, Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include "sim/sim_object.hh"
31
32 #include "base/logging.hh"
33 #include "base/match.hh"
34 #include "base/trace.hh"
35 #include "debug/Checkpoint.hh"
36 #include "sim/probe/probe.hh"
37
38 using namespace std;
39
40
41 ////////////////////////////////////////////////////////////////////////
42 //
43 // SimObject member definitions
44 //
45 ////////////////////////////////////////////////////////////////////////
46
47 //
48 // static list of all SimObjects, used for initialization etc.
49 //
50 SimObject::SimObjectList SimObject::simObjectList;
51
52 //
53 // SimObject constructor: used to maintain static simObjectList
54 //
55 SimObject::SimObject(const Params *p)
56 : EventManager(getEventQueue(p->eventq_index)),
57 Stats::Group(nullptr),
58 _params(p)
59 {
60 #ifdef DEBUG
61 doDebugBreak = false;
62 #endif
63 simObjectList.push_back(this);
64 probeManager = new ProbeManager(this);
65 }
66
67 SimObject::~SimObject()
68 {
69 delete probeManager;
70 }
71
72 void
73 SimObject::init()
74 {
75 }
76
77 void
78 SimObject::loadState(CheckpointIn &cp)
79 {
80 if (cp.sectionExists(name())) {
81 DPRINTF(Checkpoint, "unserializing\n");
82 // This works despite name() returning a fully qualified name
83 // since we are at the top level.
84 unserializeSection(cp, name());
85 } else {
86 DPRINTF(Checkpoint, "no checkpoint section found\n");
87 }
88 }
89
90 void
91 SimObject::initState()
92 {
93 }
94
95 void
96 SimObject::startup()
97 {
98 }
99
100 /**
101 * No probe points by default, so do nothing in base.
102 */
103 void
104 SimObject::regProbePoints()
105 {
106 }
107
108 /**
109 * No probe listeners by default, so do nothing in base.
110 */
111 void
112 SimObject::regProbeListeners()
113 {
114 }
115
116 ProbeManager *
117 SimObject::getProbeManager()
118 {
119 return probeManager;
120 }
121
122 Port &
123 SimObject::getPort(const std::string &if_name, PortID idx)
124 {
125 fatal("%s does not have any port named %s\n", name(), if_name);
126 }
127
128 //
129 // static function: serialize all SimObjects.
130 //
131 void
132 SimObject::serializeAll(CheckpointOut &cp)
133 {
134 SimObjectList::reverse_iterator ri = simObjectList.rbegin();
135 SimObjectList::reverse_iterator rend = simObjectList.rend();
136
137 for (; ri != rend; ++ri) {
138 SimObject *obj = *ri;
139 // This works despite name() returning a fully qualified name
140 // since we are at the top level.
141 obj->serializeSection(cp, obj->name());
142 }
143 }
144
145
146 #ifdef DEBUG
147 //
148 // static function: flag which objects should have the debugger break
149 //
150 void
151 SimObject::debugObjectBreak(const string &objs)
152 {
153 SimObjectList::const_iterator i = simObjectList.begin();
154 SimObjectList::const_iterator end = simObjectList.end();
155
156 ObjectMatch match(objs);
157 for (; i != end; ++i) {
158 SimObject *obj = *i;
159 obj->doDebugBreak = match.match(obj->name());
160 }
161 }
162
163 void
164 debugObjectBreak(const char *objs)
165 {
166 SimObject::debugObjectBreak(string(objs));
167 }
168 #endif
169
170 SimObject *
171 SimObject::find(const char *name)
172 {
173 SimObjectList::const_iterator i = simObjectList.begin();
174 SimObjectList::const_iterator end = simObjectList.end();
175
176 for (; i != end; ++i) {
177 SimObject *obj = *i;
178 if (obj->name() == name)
179 return obj;
180 }
181
182 return NULL;
183 }