8#include "sparta/functional/ArchData.hpp"
10#include "sparta/log/MessageSource.hpp"
14#include "sparta/simulation/ResourceFactory.hpp"
64 const std::string & name,
65 const std::string & group,
67 const std::string & desc,
69 TreeNode(name, group, group_idx, desc),
70 created_resource_(false),
77 if(
nullptr == res_fact_){
82 if(parent !=
nullptr){
91 const std::string & group,
93 const std::string & desc,
102 const std::string & name,
103 const std::string & desc,
117 const std::string & desc,
130 if(res_fact_ !=
nullptr){
131 if(params_ !=
nullptr){
186 virtual std::string
stringize(
bool pretty=
false)
const override {
188 std::stringstream ss;
201 <<
getLocation() <<
" because it already has a resource. ";
208 Resource* getResourceNow() noexcept {
236 <<
getLocation() <<
" but tree was not in TREE_FINALIZING phase";
242 "Resource was set in ResourceTreeNode " <<
getLocation()
243 <<
" but not by the ResourceTreeNode itself");
255 <<
getName() <<
"\"@" << (
void*)
this <<
" because it is not attached to a tree with a RootTreeNode";
266 <<
getLocation() <<
" and no ancestor has an associated clock. All ResourceTreeNodes "
267 <<
"must have at least one clock associated with a node in their ancestry";
271 if(!params_->validateIndependently(errs)){
276 if(!params_->validateDependencies(
this, errs)){
277 throw SpartaException(
"Parameter validation callbacks indicated invalid parameters: ")
290 <<
" but that resource did not register itself with this node. Ensure that "
291 "this resource class uses the proper sparta::Resource base-class constructor "
292 "which takes a ResourceContainer";
297 <<
" but that resource was different than the resource registered with this "
303 created_resource_ =
true;
317 void onSettingParent_(
const TreeNode* parent)
const override {
321 <<
getName() <<
"\" as child of device tree node \""
322 <<
getLocation() <<
"\". This tree has exited the TREE_BUILDING "
323 <<
"phase and ResourceTreeNodes can no longer be added.";
330 void onConfiguring_()
override {
338 void onBindTreeEarly_()
override {
354 void onBindTreeLate_()
override {
359 void validateNode_()
const override {
371 void initConfigurables_() {
382 throw SpartaException(
"resource type for ResourceFactory associated with ")
387 bool created_resource_;
388 ResourceFactoryBase*
const res_fact_;
389 ParameterSet* params_;
A set of sparta::Parameters per sparta::ResourceTreeNode.
Set of macros for Sparta assertions. Caught by the framework.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
Exception class for all of Sparta.
Basic Node framework in sparta device tree composite pattern.
void layout()
Organizes the Segments into overlapping regions as needed, eventually calling ArchDataSegment::place ...
Generic container of Parameters.
void verifyAllRead() const
Checks the read-count on all Parameters. If any have no been read at least once since last write (sin...
void resetReadCounts()
Reset the read-count on all Parameters in this set.
virtual bool isBuilt() const
Is this node (and thus the entire tree above it) "built". Checks that getPhase has passed TREE_BUILDI...
TreePhase getPhase() const
Gets the trees current phase.
@ TREE_FINALIZING
Tree is being finalized, but has not completed (maybe errors?)
void lockResource_()
Allows subclasses to assign the resource associated with this node.
Resource * getResource_() noexcept
Returns the currently held resource of this node (if any). This method can be called at any time.
Factory which can create Resources as well as the Parameter sets that can be modified before actually...
virtual void deleteSubtree(sparta::ResourceTreeNode *n)=0
Optionally deletes the TreeNodes created by createSubtee (if any).
virtual void deleteResource(Resource *res)=0
Deletes a resource created by the createResource method of this ResourceFactory.
virtual std::string getResourceType() const =0
Returns the resource type-name for this resource, demangled.
virtual void onBuilding(sparta::ResourceTreeNode *n)=0
Hook for additional building on ResourceTreeNode constructing.
virtual void deleteParameters(ParameterSet *params)=0
Deletes a ParameterSet created by the createParameters method of this ResourceFactory.
virtual Resource * createResource(TreeNode *node, const ParameterSet *params)=0
Instanitates a new Resource of the type described by this factory.
virtual void bindLate(TreeNode *node)=0
Allows contents to be bound together if desired.
virtual void onConfiguring(sparta::ResourceTreeNode *n)=0
Hook for additional configuring on resource node configure.
virtual std::string getResourceTypeRaw() const =0
Returns the resource type-name for this resource as in the typeid.
virtual ParameterSet * createParameters(TreeNode *node)=0
Creates a new set of parameters associated with the resource that can be created by this factory.
TreeNode subclass representing a node in the device tree which contains a single ResourceFactory and ...
virtual ~ResourceTreeNode()
Virtual Destructor.
virtual void createResource_() override
After setting parameters, create a resource.
void finalize()
Finalize this node and construct its resource.
ResourceTreeNode(const std::string &name, const std::string &group, group_idx_type group_idx, const std::string &desc, ResourceFactoryBase *res_fact)
Alternate Constructor.
virtual std::string getResourceTypeRaw() const override
Gets the typename of the resource that this node will contain once finalized.
virtual std::string getResourceType() const override
Gets the typename of the resource that this node will contain once finalized, demangled.
const ParameterSet * getParameterSet() const
Gets the Parameter set assoiciated with this node.
static const ArchData::offset_type ARCH_DATA_LINE_SIZE
Size of an ArchData line for ResourceTreeNode (bytes) ArchData for ResourceTreeNode is a catch-all sp...
ResourceTreeNode(TreeNode *parent, const std::string &name, const std::string &group, group_idx_type group_idx, const std::string &desc, ResourceFactoryBase *res_fact)
Construct a new TreeNode attached to a parent.
ParameterSet * getParameterSet()
Gets the ParameterSet associated with this ResourceTreeNode.
ResourceTreeNode(TreeNode *parent, const std::string &name, const std::string &desc, ResourceFactoryBase *res_fact)
Alternate Constructor.
virtual std::string stringize(bool pretty=false) const override
Render description of this ResourceTreeNode as a string.
ResourceTreeNode(const std::string &name, const std::string &desc, ResourceFactoryBase *res_fact)
Alternate Constructor.
The is the base class for all types of resources used by the SPARTA framework.
Used to construct and throw a standard C++ exception. Inherits from std::exception.
Node in a composite tree representing a sparta Tree item.
static const group_idx_type GROUP_IDX_NONE
GroupIndex indicating that a node has no group index because it belongs to no group.
std::string getLocation() const override final
static constexpr char GROUP_NAME_NONE[]
Group name indicating that a node belongs to no group.
virtual bool isAttached() const
Is this node part of a device tree with a proper RootTreeNode at the root.
void addChild(TreeNode *child, bool inherit_phase=true)
Adds a TreeNode to this node as a child.
uint32_t group_idx_type
Index within a group.
const Clock * getClock() override
Walks up parents (starting with self) until a parent with an associated local clock is found,...
const std::string & getName() const override
Gets the name of this node.
void setExpectedParent_(const TreeNode *parent)
Tracks a node as an expected parent without actually adding this node as a child. This is used almost...
Macros for handling exponential backoff.