gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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__
gem5::PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:245
gem5::CxxConfigManager::Renaming::fromPrefix
std::string fromPrefix
Definition: cxx_manager.hh:103
gem5::CxxConfigManager::Exception::message
std::string message
Definition: cxx_manager.hh:84
gem5::CxxConfigManager::renamings
std::list< Renaming > renamings
All the renamings applicable when instantiating objects.
Definition: cxx_manager.hh:129
gem5::CxxConfigManager::Renaming::Renaming
Renaming(const std::string &from_prefix, const std::string &to_prefix)
Definition: cxx_manager.hh:106
gem5::CxxConfigManager::objectsByName
std::map< std::string, SimObject * > objectsByName
SimObject indexed by name.
Definition: cxx_manager.hh:115
gem5::MipsISA::index
Bitfield< 30, 0 > index
Definition: pra_constants.hh:47
gem5::CxxConfigManager::deleteObjects
void deleteObjects()
Delete all objects and clear objectsByName and objectsByOrder.
Definition: cxx_manager.cc:659
gem5::CxxConfigManager::bindObjectPorts
void bindObjectPorts(SimObject *object)
Bind the ports of a single SimObject.
Definition: cxx_manager.cc:522
gem5::CxxConfigManager
This class allows a config file to be read into gem5 (generating the appropriate SimObjects) from C++...
Definition: cxx_manager.hh:69
gem5::CxxConfigManager::unRename
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
gem5::CxxConfigManager::Exception::Exception
Exception(const std::string &name_, const std::string &message_)
Definition: cxx_manager.hh:87
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::CxxConfigManager::Exception::name
std::string name
Definition: cxx_manager.hh:83
gem5::CxxConfigManager::SimObjectResolver::configManager
CxxConfigManager & configManager
Definition: cxx_manager.hh:160
gem5::CxxConfigManager::simObjectResolver
SimObjectResolver simObjectResolver
Singleton instance of SimObjectResolver.
Definition: cxx_manager.hh:172
gem5::CxxConfigManager::flags
CxxConfigParams::Flags flags
Flags to pass to affect param setting.
Definition: cxx_manager.hh:76
gem5::CxxConfigManager::bindPort
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
gem5::CxxConfigManager::parsePort
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
gem5::CxxConfigManager::bindRequestPort
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
gem5::CxxConfigParams
Base for peer classes of SimObjectParams derived classes with parameter modifying member functions.
Definition: cxx_config.hh:129
gem5::CxxConfigManager::findAllObjects
void findAllObjects()
Find all objects by iterating over the object names in the config file with findObject.
Definition: cxx_manager.cc:414
gem5::CxxConfigManager::addRenaming
void addRenaming(const Renaming &renaming)
Add a name prefix renaming to those currently applied.
Definition: cxx_manager.cc:715
cxx_config.hh
gem5::CxxConfigManager::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...
Definition: cxx_manager.cc:132
std::vector< std::string >
gem5::csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
gem5::CxxConfigManager::Renaming::toPrefix
std::string toPrefix
Definition: cxx_manager.hh:104
gem5::CxxConfigManager::Exception::what
const char * what() const
Definition: cxx_manager.hh:91
gem5::CxxConfigManager::forEachObject
void forEachObject(void(SimObject::*mem_func)())
Perform mem_func on each SimObject.
Definition: cxx_manager.cc:588
gem5::CxxConfigManager::objectParamsByName
std::map< std::string, CxxConfigParams * > objectParamsByName
...Params objects created by this manager
Definition: cxx_manager.hh:118
gem5::CxxConfigManager::findObjectParams
CxxConfigParams * findObjectParams(const std::string &object_name)
Find the parameters for the named object.
Definition: cxx_manager.cc:266
gem5::CxxConfigManager::serialize
void serialize(std::ostream &os)
Serialize (checkpoint) all objects to the given stream.
Definition: cxx_manager.cc:642
gem5::Flags< FlagsType >
gem5::CxxConfigManager::objectsInOrder
std::list< SimObject * > objectsInOrder
SimObjects in order.
Definition: cxx_manager.hh:121
gem5::CxxConfigManager::setParamVector
void setParamVector(const std::string &object_name, const std::string &param_name, const std::vector< std::string > &param_values)
Definition: cxx_manager.cc:698
gem5::CxxConfigManager::inVisit
std::set< std::string > inVisit
While configuring, inVisit contains names of SimObjects visited in this recursive configuration walk.
Definition: cxx_manager.hh:126
gem5::CxxConfigManager::startup
void startup()
Call startup on all objects.
Definition: cxx_manager.cc:623
gem5::CxxConfigManager::CxxConfigManager
CxxConfigManager(CxxConfigFileBase &configFile_)
Definition: cxx_manager.cc:52
gem5::CxxConfigManager::Exception
Exception for instantiate/post-instantiate errors.
Definition: cxx_manager.hh:80
gem5::CxxConfigManager::findTraversalOrder
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
gem5::CxxConfigManager::getSimObjectResolver
SimObjectResolver & getSimObjectResolver()
Get the resolver used to map SimObject names to SimObjects for checkpoint restore.
Definition: cxx_manager.hh:303
cprintf.hh
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::CxxConfigDirectoryEntry::PortDesc
Similar to ParamDesc to describe ports.
Definition: cxx_config.hh:93
gem5::CxxConfigManager::drainResume
void drainResume()
Resume from drain.
Definition: cxx_manager.cc:636
name
const std::string & name()
Definition: trace.cc:48
gem5::CxxConfigManager::Renaming
Name substitution when instantiating any object whose name starts with fromPrefix.
Definition: cxx_manager.hh:101
gem5::CxxConfigManager::drain
unsigned int drain()
Drain all objects.
Definition: cxx_manager.cc:630
gem5::CxxConfigManager::loadState
void loadState(CheckpointIn &checkpoint)
Load all objects' state from the given Checkpoint.
Definition: cxx_manager.cc:652
gem5::CxxConfigFileBase
Config file wrapper providing a common interface to CxxConfigManager.
Definition: cxx_config.hh:203
gem5::CxxConfigManager::initState
void initState()
Call initState on all objects.
Definition: cxx_manager.cc:616
gem5::CxxConfigManager::bindAllPorts
void bindAllPorts()
Bind the ports of all the objects in objectInOrder order.
Definition: cxx_manager.cc:442
gem5::CxxConfigManager::Exception::~Exception
~Exception()
Definition: cxx_manager.hh:93
gem5::CxxConfigManager::configFile
CxxConfigFileBase & configFile
Configuration file being read.
Definition: cxx_manager.hh:73
gem5::X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:810
gem5::CxxConfigManager::rename
std::string rename(const std::string &from_name)
Apply the first matching renaming in renamings to the given name.
Definition: cxx_manager.cc:81
gem5::SimObjectResolver
Base class to wrap object resolving functionality.
Definition: sim_object.hh:379
gem5::CxxConfigDirectoryEntry
Config details entry for a SimObject.
Definition: cxx_config.hh:69
gem5::CxxConfigManager::instantiate
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
gem5::CxxConfigManager::SimObjectResolver::resolveSimObject
SimObject * resolveSimObject(const std::string &name)
Find a SimObject given a full path name.
Definition: cxx_manager.hh:167
gem5::CxxConfigManager::findObjectType
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
std::list
STL list class.
Definition: stl.hh:51
gem5::CxxConfigManager::SimObjectResolver
Class for resolving SimObject names to SimObjects usable by the checkpoint restore mechanism.
Definition: cxx_manager.hh:157
gem5::CxxConfigManager::SimObjectResolver::SimObjectResolver
SimObjectResolver(CxxConfigManager &configManager_)
Definition: cxx_manager.hh:163
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::CxxConfigManager::setParam
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
gem5::CxxConfigManager::getObject
SimObjectType & getObject(const std::string &object_name)
Find an object from objectsByName with a type-checking cast.
Definition: cxx_manager.hh:240

Generated on Sun Jul 30 2023 01:56:59 for gem5 by doxygen 1.8.17