47 #include "debug/CxxConfig.hh" 52 configFile(configFile_), flags(configFile_.getFlags()),
53 simObjectResolver(*this)
59 std::string &object_type)
62 throw Exception(object_name,
"Can't find sim object");
65 throw Exception(object_name,
"Sim object has no 'type' field");
71 "No sim object type %s is available", object_type));
85 if (from_name.find(renaming.
fromPrefix) == 0) {
87 from_name.substr(renaming.
fromPrefix.length());
100 if (to_name.find(renaming.
toPrefix) == 0) {
102 to_name.substr(renaming.
toPrefix.length());
112 std::ostringstream params;
114 auto i = param_values.begin();
115 auto end_i = param_values.end();
134 std::string instance_name =
rename(object_name);
136 if (object_name ==
"Null")
144 throw Exception(instance_name,
"Cycle in configuration");
146 std::string object_type;
155 DPRINTF(CxxConfig,
"Configuring sim object references for: %s" 156 " (%s from object %s)\n", instance_name, object_type,
177 "Element not found: %s", param->
name));
182 for (
auto n = sub_object_names.begin();
183 n != sub_object_names.end(); ++
n)
189 sub_objects.push_back(sub_object);
196 "Can't assign sim object element %s from \"%s\"",
200 DPRINTF(CxxConfig,
"Setting sim object(s): %s.%s=%s\n",
201 object_name, param->
name,
204 std::string sub_object_name;
210 "Element not found: %s", param->
name));
221 "Can't assign sim object element %s from" 222 " \"%s\"", param->
name, sub_object_name));
226 DPRINTF(CxxConfig,
"Setting sim object(s):" 227 " %s.%s=%s\n", object_name, param->
name,
233 DPRINTF(CxxConfig,
"Creating SimObject: %s\n", instance_name);
238 " type: %s", object_type));
244 if (visit_children) {
249 for (
auto i = children.begin();
i != children.end(); ++
i)
253 delete object_params;
267 std::string instance_name =
rename(object_name);
273 std::string object_type;
277 DPRINTF(CxxConfig,
"Configuring parameters of object: %s (%s)\n",
278 instance_name, object_type);
285 object_params->
setName(instance_name);
303 "Element not found for parameter: %s",
308 param_values,
flags))
311 "Bad parameter value: .%s=X=\"%s\"",
315 DPRINTF(CxxConfig,
"Setting parameter" 316 " %s.%s=%s\n", instance_name, param->
name,
319 std::string param_value;
325 "Element not found for parameter: %s",
333 "Bad parameter value: .%s=X=\"%s\"",
334 param->
name, param_value));
337 DPRINTF(CxxConfig,
"Setting parameter %s.%s=%s\n",
338 instance_name, param->
name, param_value);
345 for (
auto i = entry.
ports.begin();
i != entry.
ports.end(); ++
i) {
350 DPRINTF(CxxConfig,
"Port not found: %s.%s," 351 " assuming there are no connections\n",
352 instance_name, port->
name);
355 unsigned int peer_count = peers.size();
366 "Unconnected port: %s", port->
name));
369 DPRINTF(CxxConfig,
"Setting port connection count" 370 " for: %s.%s to %d\n",
371 instance_name, port->
name, peer_count);
383 DPRINTF(CxxConfig,
"Nulling sim object reference: %s.%s\n",
384 instance_name, param->
name);
397 "Error nulling sim object reference(s): %s",
403 delete object_params;
409 return object_params;
435 for (
auto i = children.begin();
i != children.end(); ++
i)
449 SimObject *master_object,
const std::string &master_port_name,
451 SimObject *slave_object,
const std::string &slave_port_name,
460 master_port_name, master_port_index);
462 slave_port_name, slave_port_index);
466 "Master port: %s[%d] is already connected\n", master_port_name,
472 "Slave port: %s[%d] is already connected\n", slave_port_name,
476 DPRINTF(CxxConfig,
"Binding port %s.%s[%d]" 478 master_object->
name(), master_port_name, master_port_index,
479 slave_object->
name(), slave_port_name, slave_port_index);
481 master_port.
bind(slave_port);
489 unsigned int master_port_index = 0;
491 for (
auto peer_i = peers.begin(); peer_i != peers.end();
494 const std::string &peer = *peer_i;
495 std::string slave_object_name;
496 std::string slave_port_name;
497 unsigned int slave_port_index;
499 parsePort(peer, slave_object_name, slave_port_name,
502 std::string slave_instance_name =
rename(slave_object_name);
506 "Can't find slave port object: %s", slave_instance_name));
512 slave_object, slave_port_name, slave_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",
void setParamVector(const std::string &object_name, const std::string ¶m_name, const std::vector< std::string > ¶m_values)
virtual const std::string & getName()
Get full path name string.
Ports are used to interface objects to each other.
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
void startup()
Call startup on all objects.
void initState()
Call initState on all objects.
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.
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.
void loadState(CheckpointIn &checkpoint)
Load all objects' state from the given Checkpoint.
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...
std::list< Renaming > renamings
All the renamings applicable when instantiating objects.
std::map< std::string, SimObject * > objectsByName
SimObject indexed by name.
void setParam(const std::string &object_name, const std::string ¶m_name, const std::string ¶m_value)
Convenience functions for calling set...
void bindAllPorts()
Bind the ports of all the objects in objectInOrder order.
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 CxxConfigParams * makeParamsObject() const
Make a ...Param structure for the SimObject class of this entry.
virtual void regStats()
Callback to set stat parameters.
Base for peer classes of SimObjectParams derived classes with parameter modifying member functions...
const bool isSimObject
Is this a SimObject, and so is to be set with setSimObject...
CxxConfigParams * findObjectParams(const std::string &object_name)
Find the parameters for the named object.
bool isConnected() const
Is this port currently connected to a peer?
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.
void forEachObject(void(SimObject::*mem_func)())
Perform mem_func on each SimObject.
std::map< std::string, PortDesc * > ports
Ports.
Similar to ParamDesc to describe ports.
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.
std::set< std::string > inVisit
While configuring, inVisit contains names of SimObjects visited in this recursive configuration walk...
void addRenaming(const Renaming &renaming)
Add a name prefix renaming to those currently applied.
virtual void setName(const std::string &name_)
Example flag.
virtual void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
CxxConfigParams::Flags flags
Flags to pass to affect param setting.
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.
static std::string formatParamList(const std::vector< std::string > ¶m_values)
std::string csprintf(const char *format, const Args &...args)
Exception for instantiate/post-instantiate errors.
std::map< std::string, CxxConfigParams * > objectParamsByName
...Params objects created by this manager
std::list< SimObject * > objectsInOrder
SimObjects in order.
std::map< std::string, CxxConfigDirectoryEntry * > cxx_config_directory
Directory of all SimObject classes config details.
Config file wrapper providing a common interface to CxxConfigManager.
CxxConfigManager(CxxConfigFileBase &configFile_)
void drainResume()
Resume from drain.
unsigned int drain()
Drain all objects.
void deleteObjects()
Delete all objects and clear objectsByName and objectsByOrder.
virtual void regProbePoints()
Register probe points for this object.
std::map< std::string, ParamDesc * > parameters
All parameters (including SimObjects) in order.
virtual void regProbeListeners()
Register probe listeners for this object.
virtual const std::string name() const
const bool isMaster
Is this a master or slave port.
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.
bool tryDrain()
Try to drain the system.
virtual bool objectExists(const std::string &object_name) const =0
Does an object with this path exist?
virtual SimObject * simObjectCreate()
Create the associated SimObject.
virtual bool setPortConnectionCount(const std::string &name, unsigned int count)
Set the number of connections expected for the named port.
CxxConfigFileBase & configFile
Configuration file being read.
std::string unRename(const std::string &to_name)
Apply the first matching renaming in reverse (toPrefix -> fromPrefix for the given name...
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 ...
static DrainManager & instance()
Get the singleton DrainManager instance.
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.
virtual void bind(Port &peer)
Attach to a peer port.
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...
Config details entry for a SimObject.
virtual void getAllObjectNames(std::vector< std::string > &list) const =0
Get all SimObjects in the config.
virtual void initState()
initState() is called on each SimObject when not restoring from a checkpoint.
void serialize(std::ostream &os)
Serialize (checkpoint) all objects to the given stream.
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
virtual bool setSimObjectVector(const std::string &name, const std::vector< SimObject *> &simObjects)
As setSimObjectVector but set a whole vector of references.
void findAllObjects()
Find all objects by iterating over the object names in the config file with findObject.
C++-only configuration and instantiation support.
void instantiate(bool build_all=true)
Build all objects (if build_all is true, otherwise objects must have been individually findObject-ed ...
virtual bool setSimObject(const std::string &name, SimObject *simObject)
Set a SimObject valued parameter with a reference to the given SimObject.
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.
Abstract superclass for simulation objects.
void bindObjectPorts(SimObject *object)
Bind the ports of a single SimObject.
virtual void startup()
startup() is the final initialization call before simulation.
Name substitution when instantiating any object whose name starts with fromPrefix.