17#include "sparta/log/NotificationSource.hpp"
18#include "sparta/simulation/TreeNodePrivateAttorney.hpp"
33 class PythonInterpreter;
76 const std::string & desc,
82 "descendant_attached",
83 "Notification immediately after a node becomes a descendant of this "
84 "root at any distance. This new node may have children already attached "
85 "which will not receive their own descendant_attached notification",
86 "descendant_attached")
88 if(search_scope !=
nullptr){
89 search_node_ = search_scope;
92 alloc_search_node_.reset(search_node_);
106 const std::string & desc,
117 RootTreeNode(name,
"Top of device tree", nullptr, nullptr)
126 const std::string & desc,
138 const std::string & desc) :
157 RootTreeNode(
"top",
"Top of device tree", nullptr, search_scope)
166 RootTreeNode(
"top",
"Top of device tree", sim, search_scope)
175 RootTreeNode(
"top",
"Top of device tree", nullptr, nullptr)
245 <<
getLocation()<<
"\" not currently in the TREE_BUILDING phase, so it cannot "
246 "enter TREE_CONFIGURING";
288 <<
"\" not in the TREE_FINALIZED phase, so it cannot be bound (bindTreeEarly)";
308 <<
"\" not in the TREE_FINALIZED phase, so it cannot be bound (bindTreeLate)";
339 <<
"\" not in the TREE_FINALIZED phase, so it cannot be pre-run validated";
389 virtual std::string
stringize(
bool pretty=
false)
const override {
391 std::stringstream ss;
412 return new_node_noti_;
435 std::vector<const ArchData*>& ad_no_assoc,
436 std::vector<const ArchData*>& ad_not_attached,
437 std::vector<const ArchData*>& ad_other_tree)
const noexcept;
474 virtual void createResource_()
override {};
485 virtual void onSettingParent_(
const TreeNode* parent)
const override final {
486 if(parent != search_node_){
488 <<
"\" cannot be a child of any other node except its constructed "
501 virtual void setParent_(
TreeNode* parent,
bool)
override final {
502 if(parent != search_node_){
503 throw SpartaCriticalError(
"This RootTreeNode \"")
504 <<
"\" cannot be a child of any other node except its constructed "
511 virtual void onDescendentSubtreeAdded_(
TreeNode* des)
noexcept override final {
518 onDescendentSubtreeAdded_(child);
520 }
catch(SpartaException& ex){
521 std::stringstream msg;
523 "\nThis exception within onDescendentSubtreeAdded_, which is not exception-"
524 "safe. The integrity of this sparta tree (" <<
getRoot() <<
") is compromised. "
534 std::unique_ptr<GlobalTreeNode> alloc_search_node_;
540 GlobalTreeNode* search_node_;
545 app::Simulation* sim_;
TreeNode refinement representing the global namespace (above "top") of a device tree.
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.
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.
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.
RootTreeNode(const std::string &name, const std::string &desc, app::Simulation *sim)
Consturctor with name, desc, and simulator.
virtual ~RootTreeNode()
Destructor.
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 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.
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...
RootTreeNode(const std::string &name, const std::string &desc)
Constructor with name and desc.
NotificationSource< TreeNode > NewDescendantNotiSrc
Type for notification source in this node which is posted when a new descendent is attached.
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.
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
virtual TreeNode * getRoot()
Gets farthest ancestor of this node.
void validateTree_()
Iterates the finalized tree and validates each node (e.g. ensures statistics can be evaluated)
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.
friend class TreeNodePrivateAttorney
Friend an attorney pattern that can expose access to getAllChildren_ or other methods that bypass pri...
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...
Simulator which builds a sparta DeviceTree.
Macros for handling exponential backoff.