gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  * Authors: Andrew Bardsley
38  */
39 
52 #ifndef __SIM_CXX_MANAGER_HH__
53 #define __SIM_CXX_MANAGER_HH__
54 
55 #include <list>
56 #include <map>
57 #include <set>
58 #include <string>
59 #include <vector>
60 
61 #include "base/cprintf.hh"
62 #include "sim/cxx_config.hh"
63 
64 class CheckpointIn;
65 
69 {
70  protected:
73 
76 
77  public:
79  class Exception : public std::exception
80  {
81  public:
82  std::string name;
83  std::string message;
84 
85  public:
86  Exception(const std::string &name_, const std::string &message_) :
87  name(name_), message(message_)
88  { }
89 
90  const char *what() const throw() { return message.c_str(); }
91 
92  ~Exception() throw() { }
93  };
94 
100  struct Renaming
101  {
102  std::string fromPrefix;
103  std::string toPrefix;
104 
105  Renaming(const std::string &from_prefix,
106  const std::string &to_prefix) :
107  fromPrefix(from_prefix),
108  toPrefix(to_prefix)
109  { }
110  };
111 
112  public:
114  std::map<std::string, SimObject *> objectsByName;
115 
117  std::map<std::string, CxxConfigParams *> objectParamsByName;
118 
121 
122  protected:
125  std::set<std::string> inVisit;
126 
129 
131  void bindPort(SimObject *masterObject, const std::string &masterPort,
132  PortID masterPortIndex, SimObject *slaveObject,
133  const std::string &slavePort, PortID slavePortIndex);
134 
138  void bindMasterPort(SimObject *object,
140  const std::vector<std::string> &peers);
141 
143  std::string rename(const std::string &from_name);
144 
147  std::string unRename(const std::string &to_name);
148 
149  protected:
152  void bindAllPorts();
153 
157  {
158  protected:
160 
161  public:
163  configManager(configManager_)
164  { }
165 
166  SimObject *resolveSimObject(const std::string &name)
167  { return &(configManager.getObject<SimObject>(name)); }
168  };
169 
172 
173  public:
174  CxxConfigManager(CxxConfigFileBase &configFile_);
175 
180  const std::string &object_name, std::string &object_type);
181 
186  void addRenaming(const Renaming &renaming);
187 
188  public:
190  void bindObjectPorts(SimObject *object);
191 
209  SimObject *findObject(const std::string &object_name,
210  bool visit_children = false);
211 
228  CxxConfigParams *findObjectParams(const std::string &object_name);
229 
232  void findTraversalOrder(const std::string &object_name);
233 
237  template<typename SimObjectType>
238  SimObjectType &
239  getObject(const std::string &object_name)
240  {
241  if (objectsByName.find(object_name) == objectsByName.end()) {
242  throw Exception("", csprintf("No sim object named: %s",
243  object_name));
244  }
245 
246  SimObjectType *object = dynamic_cast<SimObjectType *>(
247  objectsByName[object_name]);
248 
249  if (!object) {
250  throw Exception("", csprintf("Sim object: %s has the wrong"
251  " type", object_name));
252  }
253 
254  return *object;
255  }
256 
258  void forEachObject(void (SimObject::*mem_func)());
259 
262  void findAllObjects();
263 
266  static void parsePort(const std::string &inp,
267  std::string &path, std::string &port, unsigned int &index);
268 
277  void instantiate(bool build_all = true);
278 
280  void initState();
281 
283  void startup();
284 
286  unsigned int drain();
287 
289  void drainResume();
290 
292  void serialize(std::ostream &os);
293 
295  void loadState(CheckpointIn &checkpoint);
296 
298  void deleteObjects();
299 
303 
307  void setParam(const std::string &object_name,
308  const std::string &param_name, const std::string &param_value);
309  void setParamVector(const std::string &object_name,
310  const std::string &param_name,
311  const std::vector<std::string> &param_values);
312 };
313 
314 #endif // __SIM_CXX_MANAGER_HH__
void setParamVector(const std::string &object_name, const std::string &param_name, const std::vector< std::string > &param_values)
Definition: cxx_manager.cc:710
Bitfield< 30, 0 > index
void startup()
Call startup on all objects.
Definition: cxx_manager.cc:635
void initState()
Call initState on all objects.
Definition: cxx_manager.cc:628
const std::string & name()
Definition: trace.cc:49
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:573
void loadState(CheckpointIn &checkpoint)
Load all objects' state from the given Checkpoint.
Definition: cxx_manager.cc:664
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:131
std::list< Renaming > renamings
All the renamings applicable when instantiating objects.
Definition: cxx_manager.hh:128
std::map< std::string, SimObject * > objectsByName
SimObject indexed by name.
Definition: cxx_manager.hh:114
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:693
void bindAllPorts()
Bind the ports of all the objects in objectInOrder order.
Definition: cxx_manager.cc:441
std::string rename(const std::string &from_name)
Apply the first matching renaming in renamings to the given name.
Definition: cxx_manager.cc:80
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:58
SimObject * resolveSimObject(const std::string &name)
Definition: cxx_manager.hh:166
Base for peer classes of SimObjectParams derived classes with parameter modifying member functions...
Definition: cxx_config.hh:125
const char * what() const
Definition: cxx_manager.hh:90
CxxConfigParams * findObjectParams(const std::string &object_name)
Find the parameters for the named object.
Definition: cxx_manager.cc:265
void forEachObject(void(SimObject::*mem_func)())
Perform mem_func on each SimObject.
Definition: cxx_manager.cc:600
Bitfield< 17 > os
Definition: misc.hh:804
Similar to ParamDesc to describe ports.
Definition: cxx_config.hh:92
std::set< std::string > inVisit
While configuring, inVisit contains names of SimObjects visited in this recursive configuration walk...
Definition: cxx_manager.hh:125
void addRenaming(const Renaming &renaming)
Add a name prefix renaming to those currently applied.
Definition: cxx_manager.cc:727
SimObjectResolver simObjectResolver
Singleton instance of SimObjectResolver.
Definition: cxx_manager.hh:171
CxxConfigParams::Flags flags
Flags to pass to affect param setting.
Definition: cxx_manager.hh:75
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
Exception for instantiate/post-instantiate errors.
Definition: cxx_manager.hh:79
std::map< std::string, CxxConfigParams * > objectParamsByName
...Params objects created by this manager
Definition: cxx_manager.hh:117
C++-only configuration and instantiation support.
std::list< SimObject * > objectsInOrder
SimObjects in order.
Definition: cxx_manager.hh:120
SimObjectResolver & getSimObjectResolver()
Get the resolver used to map SimObject names to SimObjects for checkpoint restore.
Definition: cxx_manager.hh:302
Config file wrapper providing a common interface to CxxConfigManager.
Definition: cxx_config.hh:187
CxxConfigManager(CxxConfigFileBase &configFile_)
Definition: cxx_manager.cc:51
void drainResume()
Resume from drain.
Definition: cxx_manager.cc:648
unsigned int drain()
Drain all objects.
Definition: cxx_manager.cc:642
void deleteObjects()
Delete all objects and clear objectsByName and objectsByOrder.
Definition: cxx_manager.cc:671
This class allows a config file to be read into gem5 (generating the appropriate SimObjects) from C++...
Definition: cxx_manager.hh:68
SimObjectResolver(CxxConfigManager &configManager_)
Definition: cxx_manager.hh:162
Class for resolving SimObject names to SimObjects usable by the checkpoint restore mechanism...
Definition: cxx_manager.hh:156
Renaming(const std::string &from_prefix, const std::string &to_prefix)
Definition: cxx_manager.hh:105
Exception(const std::string &name_, const std::string &message_)
Definition: cxx_manager.hh:86
CxxConfigFileBase & configFile
Configuration file being read.
Definition: cxx_manager.hh:72
SimObjectType & getObject(const std::string &object_name)
Find an object from objectsByName with a type-checking cast.
Definition: cxx_manager.hh:239
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:95
void bindMasterPort(SimObject *object, const CxxConfigDirectoryEntry::PortDesc &port, const std::vector< std::string > &peers)
Bind a single (possibly vectored) master port to peers from the unparsed list peers with elements in ...
Definition: cxx_manager.cc:500
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:424
Config details entry for a SimObject.
Definition: cxx_config.hh:68
void serialize(std::ostream &os)
Serialize (checkpoint) all objects to the given stream.
Definition: cxx_manager.cc:654
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:181
void findAllObjects()
Find all objects by iterating over the object names in the config file with findObject.
Definition: cxx_manager.cc:413
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:607
void bindPort(SimObject *masterObject, const std::string &masterPort, PortID masterPortIndex, SimObject *slaveObject, const std::string &slavePort, PortID slavePortIndex)
Bind a single connection between two objects' ports.
Definition: cxx_manager.cc:448
Abstract superclass for simulation objects.
Definition: sim_object.hh:94
void bindObjectPorts(SimObject *object)
Bind the ports of a single SimObject.
Definition: cxx_manager.cc:534
Name substitution when instantiating any object whose name starts with fromPrefix.
Definition: cxx_manager.hh:100

Generated on Fri Jun 9 2017 13:03:51 for gem5 by doxygen 1.8.6