diff --git a/libs/libclkarchopenfpga/src/base/clock_network.cpp b/libs/libclkarchopenfpga/src/base/clock_network.cpp index 3bfc16f40..808286911 100644 --- a/libs/libclkarchopenfpga/src/base/clock_network.cpp +++ b/libs/libclkarchopenfpga/src/base/clock_network.cpp @@ -199,6 +199,27 @@ void ClockNetwork::add_spine_switch_point(const ClockSpineId& spine_id, const Cl spine_parent_[drive_spine_id] = spine_id; } +bool ClockNetwork::link() { + for (ClockTreeId& tree_id : trees()) { + if (!link_tree(tree_id)) { + return false; + } + } + return true; +} + +bool ClockNetwork::link_tree(const ClockTreeId& tree_id) { + tree_top_spines_[tree_id].clear(); + /* Sort the spines under a tree; assign levels and identify top-level spines */ + for (ClockSpineId spine_id : spines(tree_id)) { + /* Spines that have no parent are the top-level spines*/ + if (!spine_parent_[spine_id]) { + tree_top_spines_[tree_id].push_back(spine_id); + } + } + return true; +} + /************************************************************************ * Internal invalidators/validators ***********************************************************************/ diff --git a/libs/libclkarchopenfpga/src/base/clock_network.h b/libs/libclkarchopenfpga/src/base/clock_network.h index c22a7bb93..c566f045f 100644 --- a/libs/libclkarchopenfpga/src/base/clock_network.h +++ b/libs/libclkarchopenfpga/src/base/clock_network.h @@ -81,6 +81,8 @@ class ClockNetwork { void set_spine_start_point(const ClockSpineId& spine_id, const vtr::Point& coord); void set_spine_end_point(const ClockSpineId& spine_id, const vtr::Point& coord); void add_spine_switch_point(const ClockSpineId& spine_id, const ClockSpineId& drive_spine_id, const vtr::Point& coord); + /* Build internal links between clock tree, spines etc. This is also an validator to verify the correctness of the clock network. Must run before using the data! */ + bool link(); public: /* Public invalidators/validators */ /* Show if the tree id is a valid for data queries */ @@ -89,6 +91,10 @@ class ClockNetwork { bool valid_spine_id(const ClockSpineId& spine_id) const; bool valid_spine_switch_point_id(const ClockSpineId& spine_id, const ClockSwitchPointId& switch_point_id) const; + private: /* Private mutators */ + /* Build internal links between spines under a given tree */ + bool link_tree(const ClockTreeId& tree_id); + private: /* Internal data */ /* Basic information of each tree */ vtr::vector tree_ids_;