16#include "sparta/simulation/TreeNodeExtensions.hpp"
19#include "sparta/log/NotificationSource.hpp"
20#include "sparta/simulation/TreeNodePrivateAttorney.hpp"
21#include "sparta/simulation/ParameterTree.hpp"
37 class PythonInterpreter;
80 const std::string & desc,
86 "descendant_attached",
87 "Notification immediately after a node becomes a descendant of this "
88 "root at any distance. This new node may have children already attached "
89 "which will not receive their own descendant_attached notification",
90 "descendant_attached")
92 if(search_scope !=
nullptr){
93 search_node_ = search_scope;
96 alloc_search_node_.reset(search_node_);
110 const std::string & desc,
121 RootTreeNode(name,
"Top of device tree", nullptr, nullptr)
130 const std::string & desc,
142 const std::string & desc) :
161 RootTreeNode(
"top",
"Top of device tree", nullptr, search_scope)
170 RootTreeNode(
"top",
"Top of device tree", sim, search_scope)
179 RootTreeNode(
"top",
"Top of device tree", nullptr, nullptr)
249 <<
getLocation()<<
"\" not currently in the TREE_BUILDING phase, so it cannot "
250 "enter TREE_CONFIGURING";
292 <<
"\" not in the TREE_FINALIZED phase, so it cannot be bound (bindTreeEarly)";
312 <<
"\" not in the TREE_FINALIZED phase, so it cannot be bound (bindTreeLate)";
343 <<
"\" not in the TREE_FINALIZED phase, so it cannot be pre-run validated";
393 virtual std::string
stringize(
bool pretty=
false)
const override {
395 std::stringstream ss;
416 return new_node_noti_;
439 std::vector<const ArchData*>& ad_no_assoc,
440 std::vector<const ArchData*>& ad_not_attached,
441 std::vector<const ArchData*>& ad_other_tree)
const noexcept;
475 template <
typename ExtensionT>
477 static_assert(std::is_base_of<ExtensionsBase, ExtensionT>::value);
478 extensionFactories_()[ExtensionT::NAME] = []() {
return new ExtensionT; };
485 std::function<ExtensionsBase*()> factory)
487 extensionFactories_()[extension_name] = factory;
496 auto it = extensionFactories_().find(extension_name);
497 if (it != extensionFactories_().end()) {
501 static std::function<ExtensionsBase*()> none;
510 return extensions_ptree_;
519 return extensions_ptree_;
529 const std::vector<std::string> & config_search_paths = {},
530 const bool verbose_cfg =
false)
535 applicator.applyUnbound(ptree, verbose_cfg);
538 extensions_ptree_.
merge(ptree);
540 std::cout <<
"After merging extension file '" << yaml_file <<
"', parameter tree contains:\n";
541 constexpr bool print_user_data =
false;
542 extensions_ptree_.
recursePrint(std::cout, print_user_data);
555 static std::map<std::string, std::function<ExtensionsBase*()>> & extensionFactories_() {
556 static std::map<std::string, std::function<ExtensionsBase*()>> factories;
561 ParameterTree extensions_ptree_;
564 virtual void createResource_()
override {};
575 virtual void onSettingParent_(
const TreeNode* parent)
const override final {
576 if(parent != search_node_){
577 throw SpartaException(
"This RootTreeNode \"")
578 <<
"\" cannot be a child of any other node except its constructed "
591 virtual void setParent_(
TreeNode* parent,
bool)
override final {
592 if(parent != search_node_){
593 throw SpartaCriticalError(
"This RootTreeNode \"")
594 <<
"\" cannot be a child of any other node except its constructed "
601 virtual void onDescendentSubtreeAdded_(
TreeNode* des)
noexcept override final {
608 onDescendentSubtreeAdded_(child);
610 }
catch(SpartaException& ex){
611 std::stringstream msg;
613 "\nThis exception within onDescendentSubtreeAdded_, which is not exception-"
614 "safe. The integrity of this sparta tree (" <<
getRoot() <<
") is compromised. "
624 std::unique_ptr<GlobalTreeNode> alloc_search_node_;
630 GlobalTreeNode* search_node_;
635 app::Simulation* sim_;
644 template <
typename ExtensionT>
656#define SPARTA_CONCATENATE_DETAIL(x, y) x##y
657#define SPARTA_CONCATENATE(x, y) SPARTA_CONCATENATE_DETAIL(x, y)
659#define REGISTER_TREE_NODE_EXTENSION(ExtensionClass) \
660 sparta::ExtensionRegistration<ExtensionClass> SPARTA_CONCATENATE(__extension_registration_, __COUNTER__)
Configuration Applicators.
TreeNode refinement representing the global namespace (above "top") of a device tree.
A set of sparta::Parameters per sparta::ResourceTreeNode.
Basic Node framework in sparta device tree composite pattern.
Set of macros for Sparta assertions. Caught by the framework.
#define sparta_abort(...)
Simple variatic assertion that will print a message to std::cerr and call std::terminate()
#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.
A representation of simulated time.
TreeNode which represents some "global" namespace of the device tree, containing only RootTreeNodes,...
A TreeNode that generates a specific type of notification which propagates up a tree of TreeNodes (us...
void postNotification(const NotificationDataT &data) const
Post with reference to data with parent as message origin.
Virtual Parameter Tree. This represents a tree of parameters read from some source but does not neces...
void recursePrint(std::ostream &o, bool print_user_data=true) const
Recursively print.
void merge(const ParameterTree &rhp)
Merge this tree with another by applying all of its parameters to this tree. Parameters in the right ...
TreePhase getPhase() const
Gets the trees current phase.
@ TREE_BUILDING
Setting up tree hierarchy only (initial state)
@ TREE_FINALIZED
Tree and all resources have been instantiated. No more configuration/connection allowed.
TreeNode which represents the root ("top") of a device tree.
RootTreeNode(app::Simulation *sim, GlobalTreeNode *search_scope)
Constructor with only a simulator and search scope.
app::Simulation * getSimulator() const
Gets the simulator (if any) associated with this Root node.
void simulationTerminating()
Called after simulation has stopped, but before statistic/report generation.
static std::function< ExtensionsBase *()> & getExtensionFactory(const std::string &extension_name)
Get a tree node extension factory, if available. Check "operator bool()" before using.
RootTreeNode(const std::string &name)
Constructor with name only.
void dumpArchDataAssociations(std::ostream &o) const noexcept
Debugging tool which checks all ArchDatas in existence to see if they are associated with this tree....
RootTreeNode(GlobalTreeNode *search_scope)
Constructor with only a search scope.
static void registerExtensionFactory(const std::string &extension_name, std::function< ExtensionsBase *()> factory)
Register a tree node extension factory.
RootTreeNode(const std::string &name, const std::string &desc, app::Simulation *sim)
Consturctor with name, desc, and simulator.
static void registerExtensionClass()
Register a tree node extension factory.
virtual ~RootTreeNode()
Destructor.
NotificationSource< TreeNode > NewDescendantNotiSrc
Type for notification source in this node which is posted when a new descendent is attached.
RootTreeNode()
Default constuctor.
RootTreeNode(app::Simulation *sim)
Constructor with only a simulator.
void bindTreeEarly()
Public method for recursively giving all resources and nodes a chance to bind ports locally....
virtual std::string stringize(bool pretty=false) const override
Render description of this RootTreeNode as a string.
GlobalTreeNode * getSearchScope()
Gets the search node "parent" of this root node which is suitable for performing searches that includ...
void addExtensions(const std::string &yaml_file, const std::vector< std::string > &config_search_paths={}, const bool verbose_cfg=false)
Add tree node extension(s) from the given YAML file. This method simply adds the extension informatio...
void dumpTypeMix(std::ostream &o) const
Dumps the mix of tree node concrete types to the ostream.
void enterConfiguring()
Public method to crystalize the tree structure and begin configuring.
const ParameterTree & getExtensionsUnboundParameterTree() const
Returns a ParameterTree (const version) containing an unbound set of named tree node extensions and t...
void bindTreeLate()
Public method for recursively giving all resources and nodes a chance to bind ports locally....
void validatePreRun()
Validate the entire tree immediately prior to running. All ports should be bound ,...
void enterTeardown()
Places this tree into TREE_TEARDOWN phase so that nodes may be deleted without errors.
void dumpDebugContent(std::ostream &out) noexcept
Dump all debug content from each resource in the tree to an ostream.
void validatePostRun()
Validate all resources in the simulator, throwing exceptions if invalid state is detected....
virtual bool isAttached() const override final
Is this node part of a device tree with a proper RootTreeNode at the root.
void enterFinalized(sparta::python::PythonInterpreter *pyshell=nullptr)
Public method for recursive tree finalization. Places tree temporarily into TREE_FINALIZING phase bef...
RootTreeNode(const std::string &name, const std::string &desc, GlobalTreeNode *search_scope)
Constructor with name, desc, and search scope.
void validateArchDataAssociations() const
Gets the results.
void getArchDataAssociations(std::vector< const ArchData * > &ad_this_tree, std::vector< const ArchData * > &ad_no_assoc, std::vector< const ArchData * > &ad_not_attached, std::vector< const ArchData * > &ad_other_tree) const noexcept
Gets vectors of all the ArchData instances in existance now categorized into several groups....
RootTreeNode(const std::string &name, const std::string &desc, app::Simulation *sim, GlobalTreeNode *search_scope)
Constructor.
virtual TreeNode * getParent() override final
Gets immediate parent of this node if one exists.
NewDescendantNotiSrc & getNodeAttachedNotification()
Returns the post-write notification-source node for this register which can be used to observe writes...
ParameterTree & getExtensionsUnboundParameterTree()
Returns a ParameterTree containing an unbound set of named tree node extensions and their parameter v...
RootTreeNode(const std::string &name, const std::string &desc)
Constructor with name and desc.
virtual void setClock(const Clock *clk) override final
Assigns a clock to this node. This clock will then be accessed by any descendant which has no assigne...
Used to construct and throw a standard C++ exception. Inherits from std::exception.
static const TreeNode::ChildrenVector & getAllChildren(const TreeNode &node)
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
void validateTree_()
Iterates the finalized tree and validates each node (e.g. ensures statistics can be evaluated)
virtual TreeNode * getRoot()
Gets farthest ancestor of this node.
static constexpr char GROUP_NAME_NONE[]
Group name indicating that a node belongs to no group.
void simulationTerminating_()
Hook to allow simulation resources to clean-up before simulation is ended.
void enterTeardown_() noexcept
Recursively enter TREE_TEARDOWN phase while alerting nodes through onEnteringTeardown_ and alterting ...
TreeNode()=delete
Not default-constructable.
void addChild(TreeNode *child, bool inherit_phase=true)
Adds a TreeNode to this node as a child.
virtual void setClock(const Clock *clk)
Assigns a clock to this node. This clock will then be accessed by any descendant which has no assigne...
void dumpDebugContent_(std::ostream &out) const noexcept
Allows resources to write out detailed textual debugging information about the node....
void enterConfig_() noexcept
Recursively enter TREE_CONFIGURING phase.
void bindTreeLate_()
Recursively invoke TreeNode::onBindTreeEarly_ and Resource::onBindTreeLate_ (in that order for each n...
void bindTreeEarly_()
Recursively invoke TreeNode::onBindTreeEarly_ and Resource::onBindTreeEarly_ (in that order for each ...
void removeFromParentForTeardown_(TreeNode *parent)
Protected Wrapper for getParent()->removeChildForTeardown_ which allows subclases of TreeNode to indi...
Applies a configuration file to a node pattern.
Simulator which builds a sparta DeviceTree.
Macros for handling exponential backoff.