Go to the documentation of this file.
45 #include "debug/CxxConfig.hh"
50 configFile(configFile_), flags(configFile_.getFlags()),
51 simObjectResolver(*this)
57 std::string &object_type)
60 throw Exception(object_name,
"Can't find sim object");
63 throw Exception(object_name,
"Sim object has no 'type' field");
69 "No sim object type %s is available", object_type));
83 if (from_name.find(renaming.
fromPrefix) == 0) {
85 from_name.substr(renaming.
fromPrefix.length());
98 if (to_name.find(renaming.
toPrefix) == 0) {
100 to_name.substr(renaming.
toPrefix.length());
110 std::ostringstream params;
112 auto i = param_values.begin();
113 auto end_i = param_values.end();
132 std::string instance_name =
rename(object_name);
134 if (object_name ==
"Null")
142 throw Exception(instance_name,
"Cycle in configuration");
144 std::string object_type;
153 DPRINTF(CxxConfig,
"Configuring sim object references for: %s"
154 " (%s from object %s)\n", instance_name, object_type,
175 "Element not found: %s", param->
name));
180 for (
auto n = sub_object_names.begin();
181 n != sub_object_names.end(); ++
n)
187 sub_objects.push_back(sub_object);
194 "Can't assign sim object element %s from \"%s\"",
198 DPRINTF(CxxConfig,
"Setting sim object(s): %s.%s=%s\n",
199 object_name, param->
name,
202 std::string sub_object_name;
208 "Element not found: %s", param->
name));
219 "Can't assign sim object element %s from"
220 " \"%s\"", param->
name, sub_object_name));
224 DPRINTF(CxxConfig,
"Setting sim object(s):"
225 " %s.%s=%s\n", object_name, param->
name,
231 DPRINTF(CxxConfig,
"Creating SimObject: %s\n", instance_name);
236 " type: %s", object_type));
242 if (visit_children) {
247 for (
auto i = children.begin();
i != children.end(); ++
i)
251 delete object_params;
265 std::string instance_name =
rename(object_name);
271 std::string object_type;
275 DPRINTF(CxxConfig,
"Configuring parameters of object: %s (%s)\n",
276 instance_name, object_type);
283 object_params->
setName(instance_name);
301 "Element not found for parameter: %s",
306 param_values,
flags))
309 "Bad parameter value: .%s=X=\"%s\"",
313 DPRINTF(CxxConfig,
"Setting parameter"
314 " %s.%s=%s\n", instance_name, param->
name,
317 std::string param_value;
323 "Element not found for parameter: %s",
331 "Bad parameter value: .%s=X=\"%s\"",
332 param->
name, param_value));
335 DPRINTF(CxxConfig,
"Setting parameter %s.%s=%s\n",
336 instance_name, param->
name, param_value);
343 for (
auto i = entry.
ports.begin();
i != entry.
ports.end(); ++
i) {
348 DPRINTF(CxxConfig,
"Port not found: %s.%s,"
349 " assuming there are no connections\n",
350 instance_name, port->
name);
353 unsigned int peer_count = peers.size();
364 "Unconnected port: %s", port->
name));
367 DPRINTF(CxxConfig,
"Setting port connection count"
368 " for: %s.%s to %d\n",
369 instance_name, port->
name, peer_count);
381 DPRINTF(CxxConfig,
"Nulling sim object reference: %s.%s\n",
382 instance_name, param->
name);
395 "Error nulling sim object reference(s): %s",
401 delete object_params;
407 return object_params;
433 for (
auto i = children.begin();
i != children.end(); ++
i)
447 SimObject *requestor_object,
const std::string &request_port_name,
448 PortID request_port_index,
449 SimObject *responder_object,
const std::string &response_port_name,
450 PortID response_port_index)
458 request_port_name, request_port_index);
460 response_port_name, response_port_index);
464 "Request port: %s[%d] is already connected\n", request_port_name,
465 request_port_index));
470 "Response port: %s[%d] is already connected\n", response_port_name,
471 response_port_index));
474 DPRINTF(CxxConfig,
"Binding port %s.%s[%d]"
476 requestor_object->
name(), request_port_name, request_port_index,
477 responder_object->
name(), response_port_name, response_port_index);
479 request_port.
bind(response_port);
487 unsigned int request_port_index = 0;
489 for (
auto peer_i = peers.begin(); peer_i != peers.end();
492 const std::string &peer = *peer_i;
493 std::string response_object_name;
494 std::string response_port_name;
495 unsigned int response_port_index;
497 parsePort(peer, response_object_name, response_port_name,
498 response_port_index);
500 std::string response_instance_name =
rename(response_object_name);
505 "Can't find response port object: %s",
506 response_instance_name));
512 responder_object, response_port_name, response_port_index);
514 request_port_index++;
523 const std::string &instance_name =
object->name();
525 std::string object_name =
unRename(instance_name);
527 std::string object_type;
531 DPRINTF(CxxConfig,
"Binding ports of object: %s (%s)\n",
532 instance_name, object_type);
534 for (
auto i = entry.
ports.begin();
i != entry.
ports.end(); ++
i) {
537 DPRINTF(CxxConfig,
"Binding port: %s.%s\n", instance_name,
546 if (!port->
isVector && peers.size() > 1) {
548 "Too many connections to non-vector port %s (%d)\n",
549 port->
name, peers.size()));
559 std::string &path, std::string &port,
unsigned int &
index)
561 std::size_t dot_i = inp.rfind(
'.');
562 std::size_t open_square_i = inp.rfind(
'[');
564 if (dot_i == std::string::npos) {
565 DPRINTF(CxxConfig,
"Bad port string: %s\n", inp);
570 path = std::string(inp, 0, dot_i);
572 if (open_square_i == std::string::npos) {
574 port = std::string(inp, dot_i + 1, inp.length() - dot_i);
578 port = std::string(inp, dot_i + 1, (open_square_i - 1) - dot_i);
579 index = std::atoi(inp.c_str() + open_square_i + 1);
599 DPRINTF(CxxConfig,
"Initialising all objects\n");
602 DPRINTF(CxxConfig,
"Registering stats\n");
605 DPRINTF(CxxConfig,
"Registering probe points\n");
608 DPRINTF(CxxConfig,
"Connecting probe listeners\n");
615 DPRINTF(CxxConfig,
"Calling initState on all objects\n");
622 DPRINTF(CxxConfig,
"Starting up all objects\n");
643 os <<
'[' << (*i)->name() <<
"]\n";
652 (*i)->loadState(checkpoint);
659 DPRINTF(CxxConfig,
"Freeing sim object: %s\n", (*i)->name());
668 DPRINTF(CxxConfig,
"Freeing sim object params: %s\n",
679 const std::string ¶m_name,
const std::string ¶m_value)
685 " .%s=X=\"%s\"", param_name, param_value));
687 std::string instance_name =
rename(object_name);
689 DPRINTF(CxxConfig,
"Setting parameter %s.%s=%s\n",
690 instance_name, param_name, param_value);
696 const std::string ¶m_name,
705 std::string instance_name =
rename(object_name);
707 DPRINTF(CxxConfig,
"Setting parameter %s.%s=\"%s\"\n",
virtual void regProbeListeners()
Register probe listeners for this object.
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...
void addRenaming(const Renaming &renaming)
Add a name prefix renaming to those currently applied.
virtual bool setParam(const std::string &name, const std::string &value, const Flags flags)
Set a parameter with a value parsed from the given string.
virtual void regStats()
Callback to set stat parameters.
virtual bool setPortConnectionCount(const std::string &name, unsigned int count)
Set the number of connections expected for the named port.
virtual void initState()
initState() is called on each SimObject when not restoring from a checkpoint.
bool tryDrain()
Try to drain the system.
virtual bool getPortPeers(const std::string &object_name, const std::string &port_name, std::vector< std::string > &peers) const =0
Get the peer (connected) ports of the named ports.
CxxConfigManager(CxxConfigFileBase &configFile_)
void deleteObjects()
Delete all objects and clear objectsByName and objectsByOrder.
const bool isSimObject
Is this a SimObject, and so is to be set with setSimObject...
std::string unRename(const std::string &to_name)
Apply the first matching renaming in reverse (toPrefix -> fromPrefix for the given name.
CxxConfigFileBase & configFile
Configuration file being read.
Name substitution when instantiating any object whose name starts with fromPrefix.
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
void findAllObjects()
Find all objects by iterating over the object names in the config file with findObject.
void instantiate(bool build_all=true)
Build all objects (if build_all is true, otherwise objects must have been individually findObject-ed ...
virtual void getObjectChildren(const std::string &object_name, std::vector< std::string > &children, bool return_paths=false) const =0
Get the names or paths of all the children SimObjects of this SimObject.
virtual SimObject * simObjectCreate()
Create the associated SimObject.
virtual bool getParamVector(const std::string &object_name, const std::string ¶m_name, std::vector< std::string > &values) const =0
Get a list/vector parameter.
virtual CxxConfigParams * makeParamsObject() const
Make a ...Param structure for the SimObject class of this entry.
virtual bool setSimObject(const std::string &name, SimObject *simObject)
Set a SimObject valued parameter with a reference to the given SimObject.
const bool isRequestor
Is this a request or response port.
Similar to ParamDesc to describe ports.
void serialize(std::ostream &os)
Serialize (checkpoint) all objects to the given stream.
void resume()
Resume normal simulation in a Drained system.
void findTraversalOrder(const std::string &object_name)
Populate objectsInOrder with a preorder, depth first traversal from the given object name down throug...
static std::string formatParamList(const std::vector< std::string > ¶m_values)
virtual void startup()
startup() is the final initialization call before simulation.
std::map< std::string, PortDesc * > ports
Ports.
Base for peer classes of SimObjectParams derived classes with parameter modifying member functions.
virtual const std::string & getName()
Get full path name string.
std::map< std::string, ParamDesc * > parameters
All parameters (including SimObjects) in order.
virtual bool setParamVector(const std::string &name, const std::vector< std::string > &values, const Flags flags)
As setParamVector but for parameters given as vectors pre-separated into elements.
void bindObjectPorts(SimObject *object)
Bind the ports of a single SimObject.
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
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 setParamVector(const std::string &object_name, const std::string ¶m_name, const std::vector< std::string > ¶m_values)
Config details entry for a SimObject.
Ports are used to interface objects to each other.
void initState()
Call initState on all objects.
Exception for instantiate/post-instantiate errors.
virtual void setName(const std::string &name_)
Example flag.
std::map< std::string, SimObject * > objectsByName
SimObject indexed by name.
std::string rename(const std::string &from_name)
Apply the first matching renaming in renamings to the given name.
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...
virtual bool getParam(const std::string &object_name, const std::string ¶m_name, std::string &value) const =0
Get a single parameter value as a string returned in value.
CxxConfigParams * findObjectParams(const std::string &object_name)
Find the parameters for the named object.
void startup()
Call startup on all objects.
virtual const std::string name() const
static DrainManager & instance()
Get the singleton DrainManager instance.
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...
virtual void regProbePoints()
Register probe points for this object.
std::set< std::string > inVisit
While configuring, inVisit contains names of SimObjects visited in this recursive configuration walk.
void setParam(const std::string &object_name, const std::string ¶m_name, const std::string ¶m_value)
Convenience functions for calling set...
virtual bool objectExists(const std::string &object_name) const =0
Does an object with this path exist?
void loadState(CheckpointIn &checkpoint)
Load all objects' state from the given Checkpoint.
virtual void getAllObjectNames(std::vector< std::string > &list) const =0
Get all SimObjects in the config.
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.
Config file wrapper providing a common interface to CxxConfigManager.
bool isConnected() const
Is this port currently connected to a peer?
std::map< std::string, CxxConfigParams * > objectParamsByName
...Params objects created by this manager
virtual void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
std::list< Renaming > renamings
All the renamings applicable when instantiating objects.
std::map< std::string, CxxConfigDirectoryEntry * > cxx_config_directory
Directory of all SimObject classes config details.
virtual bool setSimObjectVector(const std::string &name, const std::vector< SimObject * > &simObjects)
As setSimObjectVector but set a whole vector of references.
void bindAllPorts()
Bind the ports of all the objects in objectInOrder order.
void forEachObject(void(SimObject::*mem_func)())
Perform mem_func on each SimObject.
std::string csprintf(const char *format, const Args &...args)
virtual void bind(Port &peer)
Attach to a peer port.
void drainResume()
Resume from drain.
CxxConfigParams::Flags flags
Flags to pass to affect param setting.
unsigned int drain()
Drain all objects.
std::list< SimObject * > objectsInOrder
SimObjects in order.
Abstract superclass for simulation objects.
Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17