gem5  v22.1.0.0
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 
62 namespace gem5
63 {
64 
65 class 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:
175  CxxConfigManager(CxxConfigFileBase &configFile_);
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.
Definition: cxx_config.hh:204
Exception for instantiate/post-instantiate errors.
Definition: cxx_manager.hh:81
Exception(const std::string &name_, const std::string &message_)
Definition: cxx_manager.hh:87
Class for resolving SimObject names to SimObjects usable by the checkpoint restore mechanism.
Definition: cxx_manager.hh:158
SimObjectResolver(CxxConfigManager &configManager_)
Definition: cxx_manager.hh:163
SimObject * resolveSimObject(const std::string &name)
Find a SimObject given a full path name.
Definition: cxx_manager.hh:167
This class allows a config file to be read into gem5 (generating the appropriate SimObjects) from C++...
Definition: cxx_manager.hh:70
std::set< std::string > inVisit
While configuring, inVisit contains names of SimObjects visited in this recursive configuration walk.
Definition: cxx_manager.hh:126
std::list< SimObject * > objectsInOrder
SimObjects in order.
Definition: cxx_manager.hh:121
void drainResume()
Resume from drain.
Definition: cxx_manager.cc:636
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.
Definition: cxx_manager.cc:561
void startup()
Call startup on all objects.
Definition: cxx_manager.cc:623
void deleteObjects()
Delete all objects and clear objectsByName and objectsByOrder.
Definition: cxx_manager.cc:659
CxxConfigManager(CxxConfigFileBase &configFile_)
Definition: cxx_manager.cc:52
void serialize(std::ostream &os)
Serialize (checkpoint) all objects to the given stream.
Definition: cxx_manager.cc:642
std::string rename(const std::string &from_name)
Apply the first matching renaming in renamings to the given name.
Definition: cxx_manager.cc:81
std::string unRename(const std::string &to_name)
Apply the first matching renaming in reverse (toPrefix -> fromPrefix for the given name.
Definition: cxx_manager.cc:96
CxxConfigParams::Flags flags
Flags to pass to affect param setting.
Definition: cxx_manager.hh:76
void setParamVector(const std::string &object_name, const std::string &param_name, const std::vector< std::string > &param_values)
Definition: cxx_manager.cc:698
CxxConfigFileBase & configFile
Configuration file being read.
Definition: cxx_manager.hh:73
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.
Definition: cxx_manager.cc:449
void addRenaming(const Renaming &renaming)
Add a name prefix renaming to those currently applied.
Definition: cxx_manager.cc:715
unsigned int drain()
Drain all objects.
Definition: cxx_manager.cc:630
void initState()
Call initState on all objects.
Definition: cxx_manager.cc:616
std::list< Renaming > renamings
All the renamings applicable when instantiating objects.
Definition: cxx_manager.hh:129
void findTraversalOrder(const std::string &object_name)
Populate objectsInOrder with a preorder, depth first traversal from the given object name down throug...
Definition: cxx_manager.cc:425
SimObjectType & getObject(const std::string &object_name)
Find an object from objectsByName with a type-checking cast.
Definition: cxx_manager.hh:240
std::map< std::string, SimObject * > objectsByName
SimObject indexed by name.
Definition: cxx_manager.hh:115
void setParam(const std::string &object_name, const std::string &param_name, const std::string &param_value)
Convenience functions for calling set...
Definition: cxx_manager.cc:681
void forEachObject(void(SimObject::*mem_func)())
Perform mem_func on each SimObject.
Definition: cxx_manager.cc:588
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...
Definition: cxx_manager.cc:486
CxxConfigParams * findObjectParams(const std::string &object_name)
Find the parameters for the named object.
Definition: cxx_manager.cc:266
void bindObjectPorts(SimObject *object)
Bind the ports of a single SimObject.
Definition: cxx_manager.cc:522
std::map< std::string, CxxConfigParams * > objectParamsByName
...Params objects created by this manager
Definition: cxx_manager.hh:118
SimObjectResolver & getSimObjectResolver()
Get the resolver used to map SimObject names to SimObjects for checkpoint restore.
Definition: cxx_manager.hh:303
void loadState(CheckpointIn &checkpoint)
Load all objects' state from the given Checkpoint.
Definition: cxx_manager.cc:652
void findAllObjects()
Find all objects by iterating over the object names in the config file with findObject.
Definition: cxx_manager.cc:414
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...
Definition: cxx_manager.cc:132
SimObjectResolver simObjectResolver
Singleton instance of SimObjectResolver.
Definition: cxx_manager.hh:172
void bindAllPorts()
Bind the ports of all the objects in objectInOrder order.
Definition: cxx_manager.cc:442
void instantiate(bool build_all=true)
Build all objects (if build_all is true, otherwise objects must have been individually findObject-ed ...
Definition: cxx_manager.cc:595
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...
Definition: cxx_manager.cc:59
Base for peer classes of SimObjectParams derived classes with parameter modifying member functions.
Definition: cxx_config.hh:130
Base class to wrap object resolving functionality.
Definition: sim_object.hh:386
Abstract superclass for simulation objects.
Definition: sim_object.hh:148
STL list class.
Definition: stl.hh:51
C++-only configuration and instantiation support.
Bitfield< 30, 0 > index
Bitfield< 17 > os
Definition: misc.hh:810
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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.
Definition: cxx_manager.hh:102
Renaming(const std::string &from_prefix, const std::string &to_prefix)
Definition: cxx_manager.hh:106
const std::string & name()
Definition: trace.cc:49

Generated on Wed Dec 21 2022 10:22:39 for gem5 by doxygen 1.9.1