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,
457 if (!master_mem_object) {
459 "Object isn't a mem object and so can have master port:"
460 " %s[%d]", master_port_name, master_port_index));
463 if (!slave_mem_object) {
465 "Object isn't a mem object and so can have slave port:"
466 " %s[%d]", slave_port_name, slave_port_index));
475 master_port_name, master_port_index);
477 slave_port_name, slave_port_index);
481 "Master port: %s[%d] is already connected\n", master_port_name,
487 "Slave port: %s[%d] is already connected\n", slave_port_name,
491 DPRINTF(CxxConfig,
"Binding port %s.%s[%d]"
493 master_object->
name(), master_port_name, master_port_index,
494 slave_object->
name(), slave_port_name, slave_port_index);
496 master_port.
bind(slave_port);
504 unsigned int master_port_index = 0;
506 for (
auto peer_i = peers.begin(); peer_i != peers.end();
509 const std::string &peer = *peer_i;
510 std::string slave_object_name;
511 std::string slave_port_name;
512 unsigned int slave_port_index;
514 parsePort(peer, slave_object_name, slave_port_name,
517 std::string slave_instance_name =
rename(slave_object_name);
521 "Can't find slave port object: %s", slave_instance_name));
527 slave_object, slave_port_name, slave_port_index);
538 const std::string &instance_name =
object->name();
540 std::string object_name =
unRename(instance_name);
542 std::string object_type;
546 DPRINTF(CxxConfig,
"Binding ports of object: %s (%s)\n",
547 instance_name, object_type);
549 for (
auto i = entry.
ports.begin();
i != entry.
ports.end(); ++
i) {
552 DPRINTF(CxxConfig,
"Binding port: %s.%s\n", instance_name,
561 if (!port->
isVector && peers.size() > 1) {
563 "Too many connections to non-vector port %s (%d)\n",
564 port->
name, peers.size()));
574 std::string &path, std::string &port,
unsigned int &
index)
576 std::size_t dot_i = inp.rfind(
'.');
577 std::size_t open_square_i = inp.rfind(
'[');
579 if (dot_i == std::string::npos) {
580 DPRINTF(CxxConfig,
"Bad port string: %s\n", inp);
585 path = std::string(inp, 0, dot_i);
587 if (open_square_i == std::string::npos) {
589 port = std::string(inp, dot_i + 1, inp.length() - dot_i);
593 port = std::string(inp, dot_i + 1, (open_square_i - 1) - dot_i);
594 index = std::atoi(inp.c_str() + open_square_i + 1);
614 DPRINTF(CxxConfig,
"Initialising all objects\n");
617 DPRINTF(CxxConfig,
"Registering stats\n");
620 DPRINTF(CxxConfig,
"Registering probe points\n");
623 DPRINTF(CxxConfig,
"Connecting probe listeners\n");
630 DPRINTF(CxxConfig,
"Calling initState on all objects\n");
637 DPRINTF(CxxConfig,
"Starting up all objects\n");
658 os <<
'[' << (*i)->name() <<
"]\n";
667 (*i)->loadState(checkpoint);
674 DPRINTF(CxxConfig,
"Freeing sim object: %s\n", (*i)->name());
683 DPRINTF(CxxConfig,
"Freeing sim object params: %s\n",
694 const std::string ¶m_name,
const std::string ¶m_value)
700 " .%s=X=\"%s\"", param_name, param_value));
702 std::string instance_name =
rename(object_name);
704 DPRINTF(CxxConfig,
"Setting parameter %s.%s=%s\n",
705 instance_name, param_name, param_value);
711 const std::string ¶m_name,
720 std::string instance_name =
rename(object_name);
722 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.
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.
virtual bool setSimObjectVector(const std::string &name, const std::vector< SimObject * > &simObjects)
As setSimObjectVector but set a whole vector of references.
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...
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.
virtual BaseSlavePort & getSlavePort(const std::string &if_name, PortID idx=InvalidPortID)
Get a slave port with a given name and index.
virtual void regStats()
Register statistics for this object.
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.
A BaseSlavePort is a protocol-agnostic slave port, responsible only for the structural connection to ...
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.
virtual CxxConfigParams * makeParamsObject() const
Make a ...Param structure for the SimObject class of this entry.
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.
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.
virtual const std::string name() const
virtual void bind(BaseSlavePort &slave_port)=0
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.
The MemObject class extends the ClockedObject with accessor functions to get its master and slave por...
A BaseMasterPort is a protocol-agnostic master port, responsible only for the structural connection t...
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.
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.
virtual BaseMasterPort & getMasterPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a master port with a given name and index.
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.