gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
CxxConfigManager Class Reference

This class allows a config file to be read into gem5 (generating the appropriate SimObjects) from C++. More...

#include <cxx_manager.hh>

Classes

class  Exception
 Exception for instantiate/post-instantiate errors. More...
 
struct  Renaming
 Name substitution when instantiating any object whose name starts with fromPrefix. More...
 
class  SimObjectResolver
 Class for resolving SimObject names to SimObjects usable by the checkpoint restore mechanism. More...
 

Public Member Functions

 CxxConfigManager (CxxConfigFileBase &configFile_)
 
const CxxConfigDirectoryEntryfindObjectType (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 object's directory entry as the return value. More...
 
void addRenaming (const Renaming &renaming)
 Add a name prefix renaming to those currently applied. More...
 
void bindObjectPorts (SimObject *object)
 Bind the ports of a single SimObject. More...
 
SimObjectfindObject (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 on the way. More...
 
CxxConfigParamsfindObjectParams (const std::string &object_name)
 Find the parameters for the named object. More...
 
void findTraversalOrder (const std::string &object_name)
 Populate objectsInOrder with a preorder, depth first traversal from the given object name down through all its children. More...
 
template<typename SimObjectType >
SimObjectType & getObject (const std::string &object_name)
 Find an object from objectsByName with a type-checking cast. More...
 
void forEachObject (void(SimObject::*mem_func)())
 Perform mem_func on each SimObject. More...
 
void findAllObjects ()
 Find all objects by iterating over the object names in the config file with findObject. More...
 
void instantiate (bool build_all=true)
 Build all objects (if build_all is true, otherwise objects must have been individually findObject-ed and added to the traversal order) and perform all the configuration specific actions up to, but not including initState. More...
 
void initState ()
 Call initState on all objects. More...
 
void startup ()
 Call startup on all objects. More...
 
unsigned int drain ()
 Drain all objects. More...
 
void drainResume ()
 Resume from drain. More...
 
void serialize (std::ostream &os)
 Serialize (checkpoint) all objects to the given stream. More...
 
void loadState (CheckpointIn &checkpoint)
 Load all objects' state from the given Checkpoint. More...
 
void deleteObjects ()
 Delete all objects and clear objectsByName and objectsByOrder. More...
 
SimObjectResolvergetSimObjectResolver ()
 Get the resolver used to map SimObject names to SimObjects for checkpoint restore. More...
 
void setParam (const std::string &object_name, const std::string &param_name, const std::string &param_value)
 Convenience functions for calling set... More...
 
void setParamVector (const std::string &object_name, const std::string &param_name, const std::vector< std::string > &param_values)
 

Static Public Member Functions

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. More...
 

Public Attributes

std::map< std::string,
SimObject * > 
objectsByName
 SimObject indexed by name. More...
 
std::map< std::string,
CxxConfigParams * > 
objectParamsByName
 ...Params objects created by this manager More...
 
std::list< SimObject * > objectsInOrder
 SimObjects in order. More...
 

Protected Member Functions

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. More...
 
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 the .ini connection format: path(.path)*.port[index]. More...
 
std::string rename (const std::string &from_name)
 Apply the first matching renaming in renamings to the given name. More...
 
std::string unRename (const std::string &to_name)
 Apply the first matching renaming in reverse (toPrefix -> fromPrefix for the given name. More...
 
void bindAllPorts ()
 Bind the ports of all the objects in objectInOrder order. More...
 

Protected Attributes

CxxConfigFileBaseconfigFile
 Configuration file being read. More...
 
CxxConfigParams::Flags flags
 Flags to pass to affect param setting. More...
 
std::set< std::string > inVisit
 While configuring, inVisit contains names of SimObjects visited in this recursive configuration walk. More...
 
std::list< Renamingrenamings
 All the renamings applicable when instantiating objects. More...
 
SimObjectResolver simObjectResolver
 Singleton instance of SimObjectResolver. More...
 

Detailed Description

This class allows a config file to be read into gem5 (generating the appropriate SimObjects) from C++.

Definition at line 68 of file cxx_manager.hh.

Constructor & Destructor Documentation

CxxConfigManager::CxxConfigManager ( CxxConfigFileBase configFile_)

Definition at line 51 of file cxx_manager.cc.

Member Function Documentation

void CxxConfigManager::addRenaming ( const Renaming renaming)

Add a name prefix renaming to those currently applied.

Call this before trying to instantiate any object as the name mappings are not applied to the config tree read from the config file but are applied while processing instantiations

Definition at line 727 of file cxx_manager.cc.

References renamings.

void CxxConfigManager::bindAllPorts ( )
protected

Bind the ports of all the objects in objectInOrder order.

Also

Definition at line 441 of file cxx_manager.cc.

References bindObjectPorts(), ArmISA::i, and objectsInOrder.

Referenced by instantiate().

void CxxConfigManager::bindMasterPort ( SimObject object,
const CxxConfigDirectoryEntry::PortDesc port,
const std::vector< std::string > &  peers 
)
protected

Bind a single (possibly vectored) master port to peers from the unparsed list peers with elements in the .ini connection format: path(.path)*.port[index].

Definition at line 500 of file cxx_manager.cc.

References bindPort(), csprintf(), CxxConfigDirectoryEntry::PortDesc::name, SimObject::name(), objectsByName, parsePort(), and rename().

Referenced by bindObjectPorts().

void CxxConfigManager::bindObjectPorts ( SimObject object)
void CxxConfigManager::bindPort ( SimObject masterObject,
const std::string &  masterPort,
PortID  masterPortIndex,
SimObject slaveObject,
const std::string &  slavePort,
PortID  slavePortIndex 
)
protected
void CxxConfigManager::deleteObjects ( )

Delete all objects and clear objectsByName and objectsByOrder.

Definition at line 671 of file cxx_manager.cc.

References DPRINTF, CxxConfigParams::getName(), ArmISA::i, objectParamsByName, objectsByName, and objectsInOrder.

unsigned int CxxConfigManager::drain ( )

Drain all objects.

Definition at line 642 of file cxx_manager.cc.

References DrainManager::instance(), and DrainManager::tryDrain().

void CxxConfigManager::drainResume ( )

Resume from drain.

Definition at line 648 of file cxx_manager.cc.

References DrainManager::instance(), and DrainManager::resume().

void CxxConfigManager::findAllObjects ( )

Find all objects by iterating over the object names in the config file with findObject.

Also populate the traversal order

Definition at line 413 of file cxx_manager.cc.

References configFile, findTraversalOrder(), CxxConfigFileBase::getAllObjectNames(), and objectsInOrder.

Referenced by instantiate().

SimObject * CxxConfigManager::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 on the way.

This involves:

  • Calling findObjectParams to make the ...Params object If findObjectParams has already been called for this object, the ...Params object generated by that called (stored in (objectParamsByName[object_name] will be used)
  • Populating the ...Params object references to other SimObjects by recursively descending into the trees formed by SimObject references
  • Building the final SimObject and adding it to objectsByName
  • If visit_children is true, recursively visit all this object's children and build/find them too

After the first call, this function will return objectsByName[object_name]

Definition at line 131 of file cxx_manager.cc.

References configFile, csprintf(), DPRINTF, findObjectParams(), findObjectType(), formatParamList(), CxxConfigFileBase::getObjectChildren(), CxxConfigFileBase::getParam(), CxxConfigFileBase::getParamVector(), ArmISA::i, inVisit, CxxConfigDirectoryEntry::ParamDesc::isSimObject, CxxConfigDirectoryEntry::ParamDesc::isVector, ArmISA::n, CxxConfigDirectoryEntry::ParamDesc::name, objectParamsByName, objectsByName, CxxConfigDirectoryEntry::parameters, rename(), CxxConfigParams::setSimObject(), CxxConfigParams::setSimObjectVector(), and CxxConfigParams::simObjectCreate().

Referenced by findTraversalOrder().

CxxConfigParams * CxxConfigManager::findObjectParams ( const std::string &  object_name)

Find the parameters for the named object.

Returns NULL if the object isn't in the configuration. For the first call with a particular object name, a new CxxConfigParams descended object is made with the configuration file contents for this object. This involves populating that ...Params object with:

  • parameter values from the configuration file
  • port connection connection counts from the connection counts indicated by the number of peer ports in the configuration file
  • nulled (or vector<>::clear'ed) SimObject references for SimObject-values parameters

The ...Params object is then added to objectParamsByName After the first call, this function will return objectParamsByName[object_name]

Definition at line 265 of file cxx_manager.cc.

References configFile, csprintf(), DPRINTF, findObjectType(), flags, formatParamList(), CxxConfigFileBase::getParam(), CxxConfigFileBase::getParamVector(), CxxConfigFileBase::getPortPeers(), ArmISA::i, CxxConfigDirectoryEntry::ParamDesc::isSimObject, CxxConfigDirectoryEntry::ParamDesc::isVector, CxxConfigDirectoryEntry::makeParamsObject(), CxxConfigDirectoryEntry::ParamDesc::name, CxxConfigDirectoryEntry::PortDesc::name, objectParamsByName, CxxConfigDirectoryEntry::parameters, CxxConfigDirectoryEntry::ports, rename(), CxxConfigParams::setName(), CxxConfigParams::setParam(), CxxConfigParams::setParamVector(), CxxConfigParams::setPortConnectionCount(), CxxConfigParams::setSimObject(), and CxxConfigParams::setSimObjectVector().

Referenced by findObject(), setParam(), and setParamVector().

const CxxConfigDirectoryEntry & CxxConfigManager::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 object's directory entry as the return value.

Definition at line 58 of file cxx_manager.cc.

References configFile, csprintf(), cxx_config_directory, CxxConfigFileBase::getParam(), and CxxConfigFileBase::objectExists().

Referenced by bindObjectPorts(), findObject(), and findObjectParams().

void CxxConfigManager::findTraversalOrder ( const std::string &  object_name)

Populate objectsInOrder with a preorder, depth first traversal from the given object name down through all its children.

Definition at line 424 of file cxx_manager.cc.

References configFile, findObject(), CxxConfigFileBase::getObjectChildren(), ArmISA::i, and objectsInOrder.

Referenced by findAllObjects().

void CxxConfigManager::forEachObject ( void(SimObject::*)()  mem_func)

Perform mem_func on each SimObject.

Definition at line 600 of file cxx_manager.cc.

References ArmISA::i, and objectsInOrder.

Referenced by initState(), instantiate(), and startup().

template<typename SimObjectType >
SimObjectType& CxxConfigManager::getObject ( const std::string &  object_name)
inline

Find an object from objectsByName with a type-checking cast.

This function is provided for manipulating objects after instantiate as it assumes the named object exists.

Definition at line 239 of file cxx_manager.hh.

References csprintf(), and objectsByName.

Referenced by CxxConfigManager::SimObjectResolver::resolveSimObject().

SimObjectResolver& CxxConfigManager::getSimObjectResolver ( )
inline

Get the resolver used to map SimObject names to SimObjects for checkpoint restore.

Definition at line 302 of file cxx_manager.hh.

References simObjectResolver.

void CxxConfigManager::initState ( )

Call initState on all objects.

Definition at line 628 of file cxx_manager.cc.

References DPRINTF, forEachObject(), and SimObject::initState().

void CxxConfigManager::instantiate ( bool  build_all = true)

Build all objects (if build_all is true, otherwise objects must have been individually findObject-ed and added to the traversal order) and perform all the configuration specific actions up to, but not including initState.

If you want to set some parameters before completing instantiation, call findObjectParams on the objects you want to modify, then call instantiate

Definition at line 607 of file cxx_manager.cc.

References bindAllPorts(), DPRINTF, findAllObjects(), forEachObject(), SimObject::init(), SimObject::regProbeListeners(), SimObject::regProbePoints(), and SimObject::regStats().

void CxxConfigManager::loadState ( CheckpointIn checkpoint)

Load all objects' state from the given Checkpoint.

Definition at line 664 of file cxx_manager.cc.

References ArmISA::i, and objectsInOrder.

void CxxConfigManager::parsePort ( const std::string &  inp,
std::string &  path,
std::string &  port,
unsigned int &  index 
)
static

Parse a port string of the form 'path(.path)*.port[index]' into path, port and index.

Definition at line 573 of file cxx_manager.cc.

References DPRINTF.

Referenced by bindMasterPort().

std::string CxxConfigManager::rename ( const std::string &  from_name)
protected

Apply the first matching renaming in renamings to the given name.

Definition at line 80 of file cxx_manager.cc.

References CxxConfigManager::Renaming::fromPrefix, ArmISA::i, renamings, and CxxConfigManager::Renaming::toPrefix.

Referenced by bindMasterPort(), findObject(), findObjectParams(), setParam(), and setParamVector().

void CxxConfigManager::serialize ( std::ostream &  os)

Serialize (checkpoint) all objects to the given stream.

Definition at line 654 of file cxx_manager.cc.

References ArmISA::i, and objectsInOrder.

void CxxConfigManager::setParam ( const std::string &  object_name,
const std::string &  param_name,
const std::string &  param_value 
)

Convenience functions for calling set...

member functions on a CxxConfigParams for an object. These functions throw Exception rather than return a bool on failure

Definition at line 693 of file cxx_manager.cc.

References csprintf(), DPRINTF, findObjectParams(), flags, rename(), and CxxConfigParams::setParam().

void CxxConfigManager::setParamVector ( const std::string &  object_name,
const std::string &  param_name,
const std::vector< std::string > &  param_values 
)
void CxxConfigManager::startup ( )

Call startup on all objects.

Definition at line 635 of file cxx_manager.cc.

References DPRINTF, forEachObject(), and SimObject::startup().

std::string CxxConfigManager::unRename ( const std::string &  to_name)
protected

Apply the first matching renaming in reverse (toPrefix -> fromPrefix for the given name.

Definition at line 95 of file cxx_manager.cc.

References CxxConfigManager::Renaming::fromPrefix, ArmISA::i, renamings, and CxxConfigManager::Renaming::toPrefix.

Referenced by bindObjectPorts().

Member Data Documentation

CxxConfigFileBase& CxxConfigManager::configFile
protected

Configuration file being read.

Definition at line 72 of file cxx_manager.hh.

Referenced by bindObjectPorts(), findAllObjects(), findObject(), findObjectParams(), findObjectType(), and findTraversalOrder().

CxxConfigParams::Flags CxxConfigManager::flags
protected

Flags to pass to affect param setting.

Definition at line 75 of file cxx_manager.hh.

Referenced by findObjectParams(), setParam(), and setParamVector().

std::set<std::string> CxxConfigManager::inVisit
protected

While configuring, inVisit contains names of SimObjects visited in this recursive configuration walk.

Definition at line 125 of file cxx_manager.hh.

Referenced by findObject().

std::map<std::string, CxxConfigParams *> CxxConfigManager::objectParamsByName

...Params objects created by this manager

Definition at line 117 of file cxx_manager.hh.

Referenced by deleteObjects(), findObject(), and findObjectParams().

std::map<std::string, SimObject *> CxxConfigManager::objectsByName

SimObject indexed by name.

Definition at line 114 of file cxx_manager.hh.

Referenced by bindMasterPort(), deleteObjects(), findObject(), and getObject().

std::list<SimObject *> CxxConfigManager::objectsInOrder

SimObjects in order.

This is populated by findAllObjects

Definition at line 120 of file cxx_manager.hh.

Referenced by bindAllPorts(), deleteObjects(), findAllObjects(), findTraversalOrder(), forEachObject(), loadState(), and serialize().

std::list<Renaming> CxxConfigManager::renamings
protected

All the renamings applicable when instantiating objects.

Definition at line 128 of file cxx_manager.hh.

Referenced by addRenaming(), rename(), and unRename().

SimObjectResolver CxxConfigManager::simObjectResolver
protected

Singleton instance of SimObjectResolver.

Definition at line 171 of file cxx_manager.hh.

Referenced by getSimObjectResolver().


The documentation for this class was generated from the following files:

Generated on Fri Jun 9 2017 13:04:06 for gem5 by doxygen 1.8.6