gem5  v20.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 class CheckpointIn;
63 
67 {
68  protected:
71 
74 
75  public:
77  class Exception : public std::exception
78  {
79  public:
80  std::string name;
81  std::string message;
82 
83  public:
84  Exception(const std::string &name_, const std::string &message_) :
85  name(name_), message(message_)
86  { }
87 
88  const char *what() const throw() { return message.c_str(); }
89 
90  ~Exception() throw() { }
91  };
92 
98  struct Renaming
99  {
100  std::string fromPrefix;
101  std::string toPrefix;
102 
103  Renaming(const std::string &from_prefix,
104  const std::string &to_prefix) :
105  fromPrefix(from_prefix),
106  toPrefix(to_prefix)
107  { }
108  };
109 
110  public:
112  std::map<std::string, SimObject *> objectsByName;
113 
115  std::map<std::string, CxxConfigParams *> objectParamsByName;
116 
119 
120  protected:
123  std::set<std::string> inVisit;
124 
127 
129  void bindPort(SimObject *requestorObject, const std::string &requestPort,
130  PortID requestPortIndex, SimObject *responderObject,
131  const std::string &responsePort, PortID responsePortIndex);
132 
136  void bindRequestPort(SimObject *object,
138  const std::vector<std::string> &peers);
139 
141  std::string rename(const std::string &from_name);
142 
145  std::string unRename(const std::string &to_name);
146 
147  protected:
150  void bindAllPorts();
151 
155  {
156  protected:
158 
159  public:
161  configManager(configManager_)
162  { }
163 
164  SimObject *resolveSimObject(const std::string &name)
165  { return &(configManager.getObject<SimObject>(name)); }
166  };
167 
170 
171  public:
172  CxxConfigManager(CxxConfigFileBase &configFile_);
173 
178  const std::string &object_name, std::string &object_type);
179 
184  void addRenaming(const Renaming &renaming);
185 
186  public:
188  void bindObjectPorts(SimObject *object);
189 
207  SimObject *findObject(const std::string &object_name,
208  bool visit_children = false);
209 
226  CxxConfigParams *findObjectParams(const std::string &object_name);
227 
230  void findTraversalOrder(const std::string &object_name);
231 
235  template<typename SimObjectType>
236  SimObjectType &
237  getObject(const std::string &object_name)
238  {
239  if (objectsByName.find(object_name) == objectsByName.end()) {
240  throw Exception("", csprintf("No sim object named: %s",
241  object_name));
242  }
243 
244  SimObjectType *object = dynamic_cast<SimObjectType *>(
245  objectsByName[object_name]);
246 
247  if (!object) {
248  throw Exception("", csprintf("Sim object: %s has the wrong"
249  " type", object_name));
250  }
251 
252  return *object;
253  }
254 
256  void forEachObject(void (SimObject::*mem_func)());
257 
260  void findAllObjects();
261 
264  static void parsePort(const std::string &inp,
265  std::string &path, std::string &port, unsigned int &index);
266 
275  void instantiate(bool build_all = true);
276 
278  void initState();
279 
281  void startup();
282 
284  unsigned int drain();
285 
287  void drainResume();
288 
290  void serialize(std::ostream &os);
291 
293  void loadState(CheckpointIn &checkpoint);
294 
296  void deleteObjects();
297 
301 
305  void setParam(const std::string &object_name,
306  const std::string &param_name, const std::string &param_value);
307  void setParamVector(const std::string &object_name,
308  const std::string &param_name,
309  const std::vector<std::string> &param_values);
310 };
311 
312 #endif // __SIM_CXX_MANAGER_HH__
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:483
CxxConfigManager::addRenaming
void addRenaming(const Renaming &renaming)
Add a name prefix renaming to those currently applied.
Definition: cxx_manager.cc:712
X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:803
CxxConfigManager::getSimObjectResolver
SimObjectResolver & getSimObjectResolver()
Get the resolver used to map SimObject names to SimObjects for checkpoint restore.
Definition: cxx_manager.hh:300
MipsISA::index
Bitfield< 30, 0 > index
Definition: pra_constants.hh:44
Flags< FlagsType >
CxxConfigManager::CxxConfigManager
CxxConfigManager(CxxConfigFileBase &configFile_)
Definition: cxx_manager.cc:49
CxxConfigManager::deleteObjects
void deleteObjects()
Delete all objects and clear objectsByName and objectsByOrder.
Definition: cxx_manager.cc:656
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:93
CxxConfigManager::configFile
CxxConfigFileBase & configFile
Configuration file being read.
Definition: cxx_manager.hh:70
CxxConfigManager::Renaming
Name substitution when instantiating any object whose name starts with fromPrefix.
Definition: cxx_manager.hh:98
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
CxxConfigManager::findAllObjects
void findAllObjects()
Find all objects by iterating over the object names in the config file with findObject.
Definition: cxx_manager.cc:411
cxx_config.hh
CxxConfigManager::Renaming::Renaming
Renaming(const std::string &from_prefix, const std::string &to_prefix)
Definition: cxx_manager.hh:103
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:592
std::vector< std::string >
CxxConfigManager::Exception::name
std::string name
Definition: cxx_manager.hh:80
CxxConfigDirectoryEntry::PortDesc
Similar to ParamDesc to describe ports.
Definition: cxx_config.hh:90
CxxConfigManager::serialize
void serialize(std::ostream &os)
Serialize (checkpoint) all objects to the given stream.
Definition: cxx_manager.cc:639
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:422
CxxConfigParams
Base for peer classes of SimObjectParams derived classes with parameter modifying member functions.
Definition: cxx_config.hh:123
CxxConfigManager::getObject
SimObjectType & getObject(const std::string &object_name)
Find an object from objectsByName with a type-checking cast.
Definition: cxx_manager.hh:237
CxxConfigManager::SimObjectResolver::configManager
CxxConfigManager & configManager
Definition: cxx_manager.hh:157
CxxConfigManager::bindObjectPorts
void bindObjectPorts(SimObject *object)
Bind the ports of a single SimObject.
Definition: cxx_manager.cc:519
CxxConfigManager::Exception::Exception
Exception(const std::string &name_, const std::string &message_)
Definition: cxx_manager.hh:84
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:558
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:695
CxxConfigManager::Renaming::fromPrefix
std::string fromPrefix
Definition: cxx_manager.hh:100
CxxConfigDirectoryEntry
Config details entry for a SimObject.
Definition: cxx_config.hh:66
CxxConfigManager::initState
void initState()
Call initState on all objects.
Definition: cxx_manager.cc:613
CxxConfigManager::Exception
Exception for instantiate/post-instantiate errors.
Definition: cxx_manager.hh:77
CxxConfigManager::objectsByName
std::map< std::string, SimObject * > objectsByName
SimObject indexed by name.
Definition: cxx_manager.hh:112
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:78
CxxConfigManager::Exception::message
std::string message
Definition: cxx_manager.hh:81
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:56
cprintf.hh
CxxConfigManager::findObjectParams
CxxConfigParams * findObjectParams(const std::string &object_name)
Find the parameters for the named object.
Definition: cxx_manager.cc:263
CxxConfigManager::startup
void startup()
Call startup on all objects.
Definition: cxx_manager.cc:620
name
const std::string & name()
Definition: trace.cc:50
CxxConfigManager::Renaming::toPrefix
std::string toPrefix
Definition: cxx_manager.hh:101
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:129
CxxConfigManager::inVisit
std::set< std::string > inVisit
While configuring, inVisit contains names of SimObjects visited in this recursive configuration walk.
Definition: cxx_manager.hh:123
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:678
CxxConfigManager::SimObjectResolver::SimObjectResolver
SimObjectResolver(CxxConfigManager &configManager_)
Definition: cxx_manager.hh:160
CxxConfigManager::SimObjectResolver
Class for resolving SimObject names to SimObjects usable by the checkpoint restore mechanism.
Definition: cxx_manager.hh:154
CxxConfigManager::Exception::what
const char * what() const
Definition: cxx_manager.hh:88
CxxConfigManager::loadState
void loadState(CheckpointIn &checkpoint)
Load all objects' state from the given Checkpoint.
Definition: cxx_manager.cc:649
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:446
CxxConfigFileBase
Config file wrapper providing a common interface to CxxConfigManager.
Definition: cxx_config.hh:185
CxxConfigManager::objectParamsByName
std::map< std::string, CxxConfigParams * > objectParamsByName
...Params objects created by this manager
Definition: cxx_manager.hh:115
CxxConfigManager::renamings
std::list< Renaming > renamings
All the renamings applicable when instantiating objects.
Definition: cxx_manager.hh:126
CxxConfigManager::bindAllPorts
void bindAllPorts()
Bind the ports of all the objects in objectInOrder order.
Definition: cxx_manager.cc:439
CxxConfigManager::simObjectResolver
SimObjectResolver simObjectResolver
Singleton instance of SimObjectResolver.
Definition: cxx_manager.hh:169
CxxConfigManager::forEachObject
void forEachObject(void(SimObject::*mem_func)())
Perform mem_func on each SimObject.
Definition: cxx_manager.cc:585
std::list< SimObject * >
CheckpointIn
Definition: serialize.hh:67
CxxConfigManager::SimObjectResolver::resolveSimObject
SimObject * resolveSimObject(const std::string &name)
Find a SimObject given a full path name.
Definition: cxx_manager.hh:164
csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:158
CxxConfigManager::drainResume
void drainResume()
Resume from drain.
Definition: cxx_manager.cc:633
CxxConfigManager
This class allows a config file to be read into gem5 (generating the appropriate SimObjects) from C++...
Definition: cxx_manager.hh:66
CxxConfigManager::flags
CxxConfigParams::Flags flags
Flags to pass to affect param setting.
Definition: cxx_manager.hh:73
CxxConfigManager::Exception::~Exception
~Exception()
Definition: cxx_manager.hh:90
CxxConfigManager::drain
unsigned int drain()
Drain all objects.
Definition: cxx_manager.cc:627
CxxConfigManager::objectsInOrder
std::list< SimObject * > objectsInOrder
SimObjects in order.
Definition: cxx_manager.hh:118
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