gem5  v20.1.0.0
sim_object.cc
Go to the documentation of this file.
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 
42 //
43 // SimObject member definitions
44 //
46 
47 //
48 // static list of all SimObjects, used for initialization etc.
49 //
51 
52 //
53 // SimObject constructor: used to maintain static simObjectList
54 //
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 
68 {
69  delete probeManager;
70 }
71 
72 void
74 {
75 }
76 
77 void
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.
85  } else {
86  DPRINTF(Checkpoint, "no checkpoint section found\n");
87  }
88 }
89 
90 void
92 {
93 }
94 
95 void
97 {
98 }
99 
103 void
105 {
106 }
107 
111 void
113 {
114 }
115 
116 ProbeManager *
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
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 }
SimObject::regProbeListeners
virtual void regProbeListeners()
Register probe listeners for this object.
Definition: sim_object.cc:112
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
Serializable::unserializeSection
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
Definition: serialize.cc:178
SimObject::Params
SimObjectParams Params
Definition: sim_object.hh:113
getEventQueue
EventQueue * getEventQueue(uint32_t index)
Function for returning eventq queue for the provided index.
Definition: eventq.cc:61
SimObject::~SimObject
virtual ~SimObject()
Definition: sim_object.cc:67
SimObject::initState
virtual void initState()
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: sim_object.cc:91
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
SimObject::serializeAll
static void serializeAll(CheckpointOut &cp)
Serialize all SimObjects in the system.
Definition: sim_object.cc:132
SimObject::simObjectList
static SimObjectList simObjectList
List of all instantiated simulation objects.
Definition: sim_object.hh:99
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
std::vector
STL vector class.
Definition: stl.hh:37
Serializable::serializeSection
void serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
Definition: serialize.cc:171
SimObject::startup
virtual void startup()
startup() is the final initialization call before simulation.
Definition: sim_object.cc:96
cp
Definition: cprintf.cc:40
match.hh
sim_object.hh
SimObject::getPort
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Definition: sim_object.cc:123
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
name
const std::string & name()
Definition: trace.cc:50
SimObject::getProbeManager
ProbeManager * getProbeManager()
Get the probe manager for this object.
Definition: sim_object.cc:117
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
SimObject::regProbePoints
virtual void regProbePoints()
Register probe points for this object.
Definition: sim_object.cc:104
SimObject::loadState
virtual void loadState(CheckpointIn &cp)
loadState() is called on each SimObject when restoring from a checkpoint.
Definition: sim_object.cc:78
ProbeManager
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition: probe.hh:150
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
SimObject::SimObject
SimObject(const Params *_params)
Definition: sim_object.cc:55
SimObject::init
virtual void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: sim_object.cc:73
logging.hh
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
Stats
Definition: statistics.cc:61
EventManager
Definition: eventq.hh:973
trace.hh
SimObject::probeManager
ProbeManager * probeManager
Manager coordinates hooking up probe points with listeners.
Definition: sim_object.hh:102
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
probe.hh
CheckpointIn
Definition: serialize.hh:67
ObjectMatch
ObjectMatch contains a vector of expressions.
Definition: match.hh:53
SimObject::find
static SimObject * find(const char *name)
Find the SimObject with the given name and return a pointer to it.
Definition: sim_object.cc:171
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17