gem5 v24.0.0.0
Loading...
Searching...
No Matches
cxx_manager.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
50#ifndef __SIM_CXX_MANAGER_HH__
51#define __SIM_CXX_MANAGER_HH__
52
53#include <list>
54#include <map>
55#include <set>
56#include <string>
57#include <vector>
58
59#include "base/cprintf.hh"
60#include "sim/cxx_config.hh"
61
62namespace gem5
63{
64
65class CheckpointIn;
66
70{
71 protected:
74
77
78 public:
80 class Exception : public std::exception
81 {
82 public:
83 std::string name;
84 std::string message;
85
86 public:
87 Exception(const std::string &name_, const std::string &message_) :
88 name(name_), message(message_)
89 { }
90
91 const char *what() const throw() { return message.c_str(); }
92
93 ~Exception() throw() { }
94 };
95
101 struct Renaming
102 {
103 std::string fromPrefix;
104 std::string toPrefix;
105
106 Renaming(const std::string &from_prefix,
107 const std::string &to_prefix) :
108 fromPrefix(from_prefix),
109 toPrefix(to_prefix)
110 { }
111 };
112
113 public:
115 std::map<std::string, SimObject *> objectsByName;
116
118 std::map<std::string, CxxConfigParams *> objectParamsByName;
119
122
123 protected:
126 std::set<std::string> inVisit;
127
130
132 void bindPort(SimObject *requestorObject, const std::string &requestPort,
133 PortID requestPortIndex, SimObject *responderObject,
134 const std::string &responsePort, PortID responsePortIndex);
135
139 void bindRequestPort(SimObject *object,
141 const std::vector<std::string> &peers);
142
144 std::string rename(const std::string &from_name);
145
148 std::string unRename(const std::string &to_name);
149
150 protected:
153 void bindAllPorts();
154
158 {
159 protected:
161
162 public:
164 configManager(configManager_)
165 { }
166
167 SimObject *resolveSimObject(const std::string &name)
168 { return &(configManager.getObject<SimObject>(name)); }
169 };
170
173
174 public:
176
181 const std::string &object_name, std::string &object_type);
182
187 void addRenaming(const Renaming &renaming);
188
189 public:
191 void bindObjectPorts(SimObject *object);
192
210 SimObject *findObject(const std::string &object_name,
211 bool visit_children = false);
212
229 CxxConfigParams *findObjectParams(const std::string &object_name);
230
233 void findTraversalOrder(const std::string &object_name);
234
238 template<typename SimObjectType>
239 SimObjectType &
240 getObject(const std::string &object_name)
241 {
242 if (objectsByName.find(object_name) == objectsByName.end()) {
243 throw Exception("", csprintf("No sim object named: %s",
244 object_name));
245 }
246
247 SimObjectType *object = dynamic_cast<SimObjectType *>(
248 objectsByName[object_name]);
249
250 if (!object) {
251 throw Exception("", csprintf("Sim object: %s has the wrong"
252 " type", object_name));
253 }
254
255 return *object;
256 }
257
259 void forEachObject(void (SimObject::*mem_func)());
260
263 void findAllObjects();
264
267 static void parsePort(const std::string &inp,
268 std::string &path, std::string &port, unsigned int &index);
269
278 void instantiate(bool build_all = true);
279
281 void initState();
282
284 void startup();
285
287 unsigned int drain();
288
290 void drainResume();
291
293 void serialize(std::ostream &os);
294
296 void loadState(CheckpointIn &checkpoint);
297
299 void deleteObjects();
300
304
308 void setParam(const std::string &object_name,
309 const std::string &param_name, const std::string &param_value);
310 void setParamVector(const std::string &object_name,
311 const std::string &param_name,
312 const std::vector<std::string> &param_values);
313};
314
315} // namespace gem5
316
317#endif // __SIM_CXX_MANAGER_HH__
Similar to ParamDesc to describe ports.
Definition cxx_config.hh:94
Config details entry for a SimObject.
Definition cxx_config.hh:70
Config file wrapper providing a common interface to CxxConfigManager.
Exception for instantiate/post-instantiate errors.
Exception(const std::string &name_, const std::string &message_)
Class for resolving SimObject names to SimObjects usable by the checkpoint restore mechanism.
SimObject * resolveSimObject(const std::string &name)
Find a SimObject given a full path name.
SimObjectResolver(CxxConfigManager &configManager_)
This class allows a config file to be read into gem5 (generating the appropriate SimObjects) from C++...
std::set< std::string > inVisit
While configuring, inVisit contains names of SimObjects visited in this recursive configuration walk.
std::list< SimObject * > objectsInOrder
SimObjects in order.
void drainResume()
Resume from drain.
static void parsePort(const std::string &inp, std::string &path, std::string &port, unsigned int &index)
Parse a port string of the form 'path(.path)*.port[index]' into path, port and index.
void startup()
Call startup on all objects.
void deleteObjects()
Delete all objects and clear objectsByName and objectsByOrder.
CxxConfigManager(CxxConfigFileBase &configFile_)
void serialize(std::ostream &os)
Serialize (checkpoint) all objects to the given stream.
std::string rename(const std::string &from_name)
Apply the first matching renaming in renamings to the given name.
std::string unRename(const std::string &to_name)
Apply the first matching renaming in reverse (toPrefix -> fromPrefix for the given name.
CxxConfigParams::Flags flags
Flags to pass to affect param setting.
void setParamVector(const std::string &object_name, const std::string &param_name, const std::vector< std::string > &param_values)
CxxConfigFileBase & configFile
Configuration file being read.
SimObjectResolver & getSimObjectResolver()
Get the resolver used to map SimObject names to SimObjects for checkpoint restore.
void bindPort(SimObject *requestorObject, const std::string &requestPort, PortID requestPortIndex, SimObject *responderObject, const std::string &responsePort, PortID responsePortIndex)
Bind a single connection between two objects' ports.
SimObjectType & getObject(const std::string &object_name)
Find an object from objectsByName with a type-checking cast.
void addRenaming(const Renaming &renaming)
Add a name prefix renaming to those currently applied.
unsigned int drain()
Drain all objects.
void initState()
Call initState on all objects.
std::list< Renaming > renamings
All the renamings applicable when instantiating objects.
void findTraversalOrder(const std::string &object_name)
Populate objectsInOrder with a preorder, depth first traversal from the given object name down throug...
std::map< std::string, SimObject * > objectsByName
SimObject indexed by name.
void setParam(const std::string &object_name, const std::string &param_name, const std::string &param_value)
Convenience functions for calling set... member functions on a CxxConfigParams for an object.
void forEachObject(void(SimObject::*mem_func)())
Perform mem_func on each SimObject.
void bindRequestPort(SimObject *object, const CxxConfigDirectoryEntry::PortDesc &port, const std::vector< std::string > &peers)
Bind a single (possibly vectored) request port to peers from the unparsed list peers with elements in...
CxxConfigParams * findObjectParams(const std::string &object_name)
Find the parameters for the named object.
void bindObjectPorts(SimObject *object)
Bind the ports of a single SimObject.
std::map< std::string, CxxConfigParams * > objectParamsByName
...Params objects created by this manager
void loadState(CheckpointIn &checkpoint)
Load all objects' state from the given Checkpoint.
void findAllObjects()
Find all objects by iterating over the object names in the config file with findObject.
SimObject * findObject(const std::string &object_name, bool visit_children=false)
Walk the configuration starting with object object_name and fill in all the elements of this object o...
SimObjectResolver simObjectResolver
Singleton instance of SimObjectResolver.
void bindAllPorts()
Bind the ports of all the objects in objectInOrder order.
void instantiate(bool build_all=true)
Build all objects (if build_all is true, otherwise objects must have been individually findObject-ed ...
const CxxConfigDirectoryEntry & findObjectType(const std::string &object_name, std::string &object_type)
Find the type field for a named object and return both the name of the type to object_type and the ob...
Base for peer classes of SimObjectParams derived classes with parameter modifying member functions.
Base class to wrap object resolving functionality.
Abstract superclass for simulation objects.
STL list class.
Definition stl.hh:51
STL vector class.
Definition stl.hh:37
C++-only configuration and instantiation support.
Bitfield< 30, 0 > index
Bitfield< 17 > os
Definition misc.hh:838
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition types.hh:245
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161
Name substitution when instantiating any object whose name starts with fromPrefix.
Renaming(const std::string &from_prefix, const std::string &to_prefix)
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0