[lib] code format

This commit is contained in:
tangxifan 2023-02-22 21:03:04 -08:00
parent aafd1e6fb3
commit d1133000ba
5 changed files with 143 additions and 88 deletions

View File

@ -14,9 +14,7 @@ namespace openfpga { // Begin namespace openfpga
/************************************************************************ /************************************************************************
* Constructors * Constructors
***********************************************************************/ ***********************************************************************/
ClockNetwork::ClockNetwork() { ClockNetwork::ClockNetwork() { is_dirty_ = true; }
is_dirty_ = true;
}
/************************************************************************ /************************************************************************
* Public Accessors : aggregates * Public Accessors : aggregates
@ -47,8 +45,9 @@ size_t ClockNetwork::tree_depth(const ClockTreeId& tree_id) const {
return tree_depths_[tree_id]; return tree_depths_[tree_id];
} }
std::vector<ClockSpineId> ClockNetwork::spines(const ClockTreeId& tree_id) const { std::vector<ClockSpineId> ClockNetwork::spines(
std::vector<ClockSpineId> ret; const ClockTreeId& tree_id) const {
std::vector<ClockSpineId> ret;
for (ClockSpineId spine_id : spine_ids_) { for (ClockSpineId spine_id : spine_ids_) {
if (spine_parent_trees_[spine_id] == tree_id) { if (spine_parent_trees_[spine_id] == tree_id) {
ret.push_back(spine_id); ret.push_back(spine_id);
@ -62,17 +61,20 @@ std::string ClockNetwork::spine_name(const ClockSpineId& spine_id) const {
return spine_names_[spine_id]; return spine_names_[spine_id];
} }
vtr::Point<int> ClockNetwork::spine_start_point(const ClockSpineId& spine_id) const { vtr::Point<int> ClockNetwork::spine_start_point(
const ClockSpineId& spine_id) const {
VTR_ASSERT(valid_spine_id(spine_id)); VTR_ASSERT(valid_spine_id(spine_id));
return spine_start_points_[spine_id]; return spine_start_points_[spine_id];
} }
vtr::Point<int> ClockNetwork::spine_end_point(const ClockSpineId& spine_id) const { vtr::Point<int> ClockNetwork::spine_end_point(
const ClockSpineId& spine_id) const {
VTR_ASSERT(valid_spine_id(spine_id)); VTR_ASSERT(valid_spine_id(spine_id));
return spine_end_points_[spine_id]; return spine_end_points_[spine_id];
} }
std::vector<ClockSwitchPointId> ClockNetwork::spine_switch_points(const ClockSpineId& spine_id) const { std::vector<ClockSwitchPointId> ClockNetwork::spine_switch_points(
const ClockSpineId& spine_id) const {
VTR_ASSERT(valid_spine_id(spine_id)); VTR_ASSERT(valid_spine_id(spine_id));
std::vector<ClockSwitchPointId> ret; std::vector<ClockSwitchPointId> ret;
ret.reserve(spine_switch_points_[spine_id].size()); ret.reserve(spine_switch_points_[spine_id].size());
@ -83,12 +85,16 @@ std::vector<ClockSwitchPointId> ClockNetwork::spine_switch_points(const ClockSpi
return ret; return ret;
} }
ClockSpineId ClockNetwork::spine_switch_point_tap(const ClockSpineId& spine_id, const ClockSwitchPointId& switch_point_id) const { ClockSpineId ClockNetwork::spine_switch_point_tap(
const ClockSpineId& spine_id,
const ClockSwitchPointId& switch_point_id) const {
VTR_ASSERT(valid_spine_switch_point_id(spine_id, switch_point_id)); VTR_ASSERT(valid_spine_switch_point_id(spine_id, switch_point_id));
return spine_switch_points_[spine_id][size_t(switch_point_id)]; return spine_switch_points_[spine_id][size_t(switch_point_id)];
} }
vtr::Point<int> ClockNetwork::spine_switch_point(const ClockSpineId& spine_id, const ClockSwitchPointId& switch_point_id) const { vtr::Point<int> ClockNetwork::spine_switch_point(
const ClockSpineId& spine_id,
const ClockSwitchPointId& switch_point_id) const {
VTR_ASSERT(valid_spine_switch_point_id(spine_id, switch_point_id)); VTR_ASSERT(valid_spine_switch_point_id(spine_id, switch_point_id));
return spine_switch_coords_[spine_id][size_t(switch_point_id)]; return spine_switch_coords_[spine_id][size_t(switch_point_id)];
} }
@ -155,8 +161,10 @@ ClockSpineId ClockNetwork::create_spine(const std::string& name) {
/* Check if the name is already used or not */ /* Check if the name is already used or not */
auto result = spine_name2id_map_.find(name); auto result = spine_name2id_map_.find(name);
if (result != spine_name2id_map_.end()) { if (result != spine_name2id_map_.end()) {
VTR_LOG_WARN("Unable to create a spine with duplicated name '%s' in clock network\nPlease use the existing spine or rename\n", VTR_LOG_WARN(
name.c_str()); "Unable to create a spine with duplicated name '%s' in clock "
"network\nPlease use the existing spine or rename\n",
name.c_str());
return ClockSpineId::INVALID(); return ClockSpineId::INVALID();
} }
@ -189,34 +197,40 @@ ClockSpineId ClockNetwork::try_create_spine(const std::string& name) {
return spine_id; return spine_id;
} }
void ClockNetwork::set_spine_parent_tree(const ClockSpineId& spine_id, const ClockTreeId& tree_id) { void ClockNetwork::set_spine_parent_tree(const ClockSpineId& spine_id,
const ClockTreeId& tree_id) {
VTR_ASSERT(valid_spine_id(spine_id)); VTR_ASSERT(valid_spine_id(spine_id));
VTR_ASSERT(valid_tree_id(tree_id)); VTR_ASSERT(valid_tree_id(tree_id));
spine_parent_trees_[spine_id] = tree_id; spine_parent_trees_[spine_id] = tree_id;
} }
void ClockNetwork::set_spine_start_point(const ClockSpineId& spine_id, const vtr::Point<int>& coord) { void ClockNetwork::set_spine_start_point(const ClockSpineId& spine_id,
const vtr::Point<int>& coord) {
VTR_ASSERT(valid_spine_id(spine_id)); VTR_ASSERT(valid_spine_id(spine_id));
spine_start_points_[spine_id] = coord; spine_start_points_[spine_id] = coord;
} }
void ClockNetwork::set_spine_end_point(const ClockSpineId& spine_id, const vtr::Point<int>& coord) { void ClockNetwork::set_spine_end_point(const ClockSpineId& spine_id,
const vtr::Point<int>& coord) {
VTR_ASSERT(valid_spine_id(spine_id)); VTR_ASSERT(valid_spine_id(spine_id));
spine_end_points_[spine_id] = coord; spine_end_points_[spine_id] = coord;
} }
void ClockNetwork::add_spine_switch_point(const ClockSpineId& spine_id, const ClockSpineId& drive_spine_id, const vtr::Point<int>& coord) { void ClockNetwork::add_spine_switch_point(const ClockSpineId& spine_id,
const ClockSpineId& drive_spine_id,
const vtr::Point<int>& coord) {
VTR_ASSERT(valid_spine_id(spine_id)); VTR_ASSERT(valid_spine_id(spine_id));
VTR_ASSERT(valid_spine_id(drive_spine_id)); VTR_ASSERT(valid_spine_id(drive_spine_id));
spine_switch_points_[spine_id].push_back(drive_spine_id); spine_switch_points_[spine_id].push_back(drive_spine_id);
spine_switch_coords_[spine_id].push_back(coord); spine_switch_coords_[spine_id].push_back(coord);
/* Do not allow any spine has different parents */ /* Do not allow any spine has different parents */
if (spine_parents_[drive_spine_id]) { if (spine_parents_[drive_spine_id]) {
VTR_LOG_ERROR("Detect a spine %s' has two parents '%s' and '%s'. Not allowed in a clock tree!\n", VTR_LOG_ERROR(
spine_name(drive_spine_id).c_str(), "Detect a spine %s' has two parents '%s' and '%s'. Not allowed in a "
spine_name(spine_parents_[drive_spine_id]).c_str(), "clock tree!\n",
spine_name(spine_id).c_str() spine_name(drive_spine_id).c_str(),
); spine_name(spine_parents_[drive_spine_id]).c_str(),
spine_name(spine_id).c_str());
exit(1); exit(1);
} }
spine_parents_[drive_spine_id] = spine_id; spine_parents_[drive_spine_id] = spine_id;
@ -249,7 +263,8 @@ bool ClockNetwork::link_tree(const ClockTreeId& tree_id) {
bool ClockNetwork::link_tree_top_spines(const ClockTreeId& tree_id) { bool ClockNetwork::link_tree_top_spines(const ClockTreeId& tree_id) {
tree_top_spines_[tree_id].clear(); tree_top_spines_[tree_id].clear();
/* Sort the spines under a tree; assign levels and identify top-level spines */ /* Sort the spines under a tree; assign levels and identify top-level spines
*/
for (ClockSpineId spine_id : spines(tree_id)) { for (ClockSpineId spine_id : spines(tree_id)) {
/* Spines that have no parent are the top-level spines*/ /* Spines that have no parent are the top-level spines*/
if (!spine_parents_[spine_id]) { if (!spine_parents_[spine_id]) {
@ -288,14 +303,18 @@ bool ClockNetwork::update_tree_depth(const ClockTreeId& tree_id) {
* Internal invalidators/validators * Internal invalidators/validators
***********************************************************************/ ***********************************************************************/
bool ClockNetwork::valid_tree_id(const ClockTreeId& tree_id) const { bool ClockNetwork::valid_tree_id(const ClockTreeId& tree_id) const {
return (size_t(tree_id) < tree_ids_.size()) && (tree_id == tree_ids_[tree_id]); return (size_t(tree_id) < tree_ids_.size()) &&
(tree_id == tree_ids_[tree_id]);
} }
bool ClockNetwork::valid_spine_id(const ClockSpineId& spine_id) const { bool ClockNetwork::valid_spine_id(const ClockSpineId& spine_id) const {
return (size_t(spine_id) < spine_ids_.size()) && (spine_id == spine_ids_[spine_id]); return (size_t(spine_id) < spine_ids_.size()) &&
(spine_id == spine_ids_[spine_id]);
} }
bool ClockNetwork::valid_spine_switch_point_id(const ClockSpineId& spine_id, const ClockSwitchPointId& switch_point_id) const { bool ClockNetwork::valid_spine_switch_point_id(
const ClockSpineId& spine_id,
const ClockSwitchPointId& switch_point_id) const {
if (!valid_spine_id(spine_id)) { if (!valid_spine_id(spine_id)) {
return false; return false;
} }

View File

@ -9,8 +9,8 @@
#include <string> #include <string>
/* Headers from vtrutil library */ /* Headers from vtrutil library */
#include "vtr_vector.h"
#include "vtr_geometry.h" #include "vtr_geometry.h"
#include "vtr_vector.h"
/* Headers from openfpgautil library */ /* Headers from openfpgautil library */
#include "clock_network_fwd.h" #include "clock_network_fwd.h"
@ -38,7 +38,7 @@ namespace openfpga { // Begin namespace openfpga
class ClockNetwork { class ClockNetwork {
public: /* Types */ public: /* Types */
typedef vtr::vector<ClockTreeId, ClockTreeId>::const_iterator typedef vtr::vector<ClockTreeId, ClockTreeId>::const_iterator
clock_tree_iterator; clock_tree_iterator;
/* Create range */ /* Create range */
typedef vtr::Range<clock_tree_iterator> clock_tree_range; typedef vtr::Range<clock_tree_iterator> clock_tree_range;
@ -58,10 +58,16 @@ class ClockNetwork {
vtr::Point<int> spine_start_point(const ClockSpineId& spine_id) const; vtr::Point<int> spine_start_point(const ClockSpineId& spine_id) const;
vtr::Point<int> spine_end_point(const ClockSpineId& spine_id) const; vtr::Point<int> spine_end_point(const ClockSpineId& spine_id) const;
/* Return the unique id of switch points under a clock spine*/ /* Return the unique id of switch points under a clock spine*/
std::vector<ClockSwitchPointId> spine_switch_points(const ClockSpineId& spine_id) const; std::vector<ClockSwitchPointId> spine_switch_points(
ClockSpineId spine_switch_point_tap(const ClockSpineId& spine_id, const ClockSwitchPointId& switch_point_id) const; const ClockSpineId& spine_id) const;
vtr::Point<int> spine_switch_point(const ClockSpineId& spine_id, const ClockSwitchPointId& switch_point_id) const; ClockSpineId spine_switch_point_tap(
/* Find a spine with a given name, if not found, return an valid id, otherwise return an invalid one */ const ClockSpineId& spine_id,
const ClockSwitchPointId& switch_point_id) const;
vtr::Point<int> spine_switch_point(
const ClockSpineId& spine_id,
const ClockSwitchPointId& switch_point_id) const;
/* Find a spine with a given name, if not found, return an valid id, otherwise
* return an invalid one */
ClockSpineId find_spine(const std::string& name) const; ClockSpineId find_spine(const std::string& name) const;
/* Check if there are clock tree */ /* Check if there are clock tree */
bool empty() const; bool empty() const;
@ -72,18 +78,29 @@ class ClockNetwork {
void reserve_spines(const size_t& num_spines); void reserve_spines(const size_t& num_spines);
/* Reserve a number of trees to be memory efficent */ /* Reserve a number of trees to be memory efficent */
void reserve_trees(const size_t& num_trees); void reserve_trees(const size_t& num_trees);
/* Create a new tree, by default the tree can accomodate only 1 clock signal; use width to adjust the size */ /* Create a new tree, by default the tree can accomodate only 1 clock signal;
* use width to adjust the size */
ClockTreeId create_tree(const std::string& name, size_t width = 1); ClockTreeId create_tree(const std::string& name, size_t width = 1);
/* Create a new spine, if the spine is already created, return an invalid id */ /* Create a new spine, if the spine is already created, return an invalid id
*/
ClockSpineId create_spine(const std::string& name); ClockSpineId create_spine(const std::string& name);
/* Try to create a new spine, if the spine is already existing, return the id. If not, create a new spine and return its id */ /* Try to create a new spine, if the spine is already existing, return the id.
* If not, create a new spine and return its id */
ClockSpineId try_create_spine(const std::string& name); ClockSpineId try_create_spine(const std::string& name);
/* Set the parent tree for a given spine. It is illegal that a spine which does not belong to any tree */ /* Set the parent tree for a given spine. It is illegal that a spine which
void set_spine_parent_tree(const ClockSpineId& spine_id, const ClockTreeId& tree_id); * does not belong to any tree */
void set_spine_start_point(const ClockSpineId& spine_id, const vtr::Point<int>& coord); void set_spine_parent_tree(const ClockSpineId& spine_id,
void set_spine_end_point(const ClockSpineId& spine_id, const vtr::Point<int>& coord); const ClockTreeId& tree_id);
void add_spine_switch_point(const ClockSpineId& spine_id, const ClockSpineId& drive_spine_id, const vtr::Point<int>& coord); void set_spine_start_point(const ClockSpineId& spine_id,
/* 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! */ const vtr::Point<int>& coord);
void set_spine_end_point(const ClockSpineId& spine_id,
const vtr::Point<int>& coord);
void add_spine_switch_point(const ClockSpineId& spine_id,
const ClockSpineId& drive_spine_id,
const vtr::Point<int>& 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(); bool link();
public: /* Public invalidators/validators */ public: /* Public invalidators/validators */
@ -91,7 +108,9 @@ class ClockNetwork {
bool valid_tree_id(const ClockTreeId& tree_id) const; bool valid_tree_id(const ClockTreeId& tree_id) const;
/* Show if the tree id is a valid for data queries */ /* Show if the tree id is a valid for data queries */
bool valid_spine_id(const ClockSpineId& spine_id) const; 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; bool valid_spine_switch_point_id(
const ClockSpineId& spine_id,
const ClockSwitchPointId& switch_point_id) const;
private: /* Private mutators */ private: /* Private mutators */
/* Build internal links between spines under a given tree */ /* Build internal links between spines under a given tree */

View File

@ -27,16 +27,18 @@ namespace openfpga { // Begin namespace openfpga
/******************************************************************** /********************************************************************
* Parse XML codes of a <switch_point> to an object of ClockNetwork * Parse XML codes of a <switch_point> to an object of ClockNetwork
*******************************************************************/ *******************************************************************/
static void read_xml_clock_spine_switch_point(pugi::xml_node& xml_switch_point, static void read_xml_clock_spine_switch_point(
const pugiutil::loc_data& loc_data, pugi::xml_node& xml_switch_point, const pugiutil::loc_data& loc_data,
ClockNetwork& clk_ntwk, const ClockSpineId& spine_id) { ClockNetwork& clk_ntwk, const ClockSpineId& spine_id) {
if (!clk_ntwk.valid_spine_id(spine_id)) { if (!clk_ntwk.valid_spine_id(spine_id)) {
archfpga_throw(loc_data.filename_c_str(), loc_data.line(xml_switch_point), archfpga_throw(loc_data.filename_c_str(), loc_data.line(xml_switch_point),
"Invalid id of a clock spine!\n"); "Invalid id of a clock spine!\n");
} }
std::string tap_spine_name = std::string tap_spine_name =
get_attribute(xml_switch_point, XML_CLOCK_SPINE_SWITCH_POINT_ATTRIBUTE_TAP, loc_data).as_string(); get_attribute(xml_switch_point, XML_CLOCK_SPINE_SWITCH_POINT_ATTRIBUTE_TAP,
loc_data)
.as_string();
/* Try to find an existing spine, if not, create one */ /* Try to find an existing spine, if not, create one */
ClockSpineId tap_spine_id = clk_ntwk.find_spine(tap_spine_name); ClockSpineId tap_spine_id = clk_ntwk.find_spine(tap_spine_name);
@ -49,12 +51,15 @@ static void read_xml_clock_spine_switch_point(pugi::xml_node& xml_switch_point,
"Fail to create a clock spine!\n"); "Fail to create a clock spine!\n");
} }
int tap_x = int tap_x = get_attribute(xml_switch_point,
get_attribute(xml_switch_point, XML_CLOCK_SPINE_SWITCH_POINT_ATTRIBUTE_X, loc_data).as_int(); XML_CLOCK_SPINE_SWITCH_POINT_ATTRIBUTE_X, loc_data)
int tap_y = .as_int();
get_attribute(xml_switch_point, XML_CLOCK_SPINE_SWITCH_POINT_ATTRIBUTE_Y, loc_data).as_int(); int tap_y = get_attribute(xml_switch_point,
XML_CLOCK_SPINE_SWITCH_POINT_ATTRIBUTE_Y, loc_data)
.as_int();
clk_ntwk.add_spine_switch_point(spine_id, tap_spine_id, vtr::Point<int>(tap_x, tap_y)); clk_ntwk.add_spine_switch_point(spine_id, tap_spine_id,
vtr::Point<int>(tap_x, tap_y));
} }
/******************************************************************** /********************************************************************
@ -62,14 +67,16 @@ static void read_xml_clock_spine_switch_point(pugi::xml_node& xml_switch_point,
*******************************************************************/ *******************************************************************/
static void read_xml_clock_spine(pugi::xml_node& xml_spine, static void read_xml_clock_spine(pugi::xml_node& xml_spine,
const pugiutil::loc_data& loc_data, const pugiutil::loc_data& loc_data,
ClockNetwork& clk_ntwk, const ClockTreeId& tree_id) { ClockNetwork& clk_ntwk,
const ClockTreeId& tree_id) {
if (!clk_ntwk.valid_tree_id(tree_id)) { if (!clk_ntwk.valid_tree_id(tree_id)) {
archfpga_throw(loc_data.filename_c_str(), loc_data.line(xml_spine), archfpga_throw(loc_data.filename_c_str(), loc_data.line(xml_spine),
"Invalid id of a clock tree!\n"); "Invalid id of a clock tree!\n");
} }
std::string clk_spine_name = std::string clk_spine_name =
get_attribute(xml_spine, XML_CLOCK_SPINE_ATTRIBUTE_NAME, loc_data).as_string(); get_attribute(xml_spine, XML_CLOCK_SPINE_ATTRIBUTE_NAME, loc_data)
.as_string();
/* Try to find an existing spine, if not, create one */ /* Try to find an existing spine, if not, create one */
ClockSpineId spine_id = clk_ntwk.find_spine(clk_spine_name); ClockSpineId spine_id = clk_ntwk.find_spine(clk_spine_name);
@ -85,23 +92,30 @@ static void read_xml_clock_spine(pugi::xml_node& xml_spine,
clk_ntwk.set_spine_parent_tree(spine_id, tree_id); clk_ntwk.set_spine_parent_tree(spine_id, tree_id);
int start_x = int start_x =
get_attribute(xml_spine, XML_CLOCK_SPINE_ATTRIBUTE_START_X, loc_data).as_int(); get_attribute(xml_spine, XML_CLOCK_SPINE_ATTRIBUTE_START_X, loc_data)
.as_int();
int start_y = int start_y =
get_attribute(xml_spine, XML_CLOCK_SPINE_ATTRIBUTE_START_Y, loc_data).as_int(); get_attribute(xml_spine, XML_CLOCK_SPINE_ATTRIBUTE_START_Y, loc_data)
.as_int();
clk_ntwk.set_spine_start_point(spine_id, vtr::Point<int>(start_x, start_y)); clk_ntwk.set_spine_start_point(spine_id, vtr::Point<int>(start_x, start_y));
int end_x = int end_x =
get_attribute(xml_spine, XML_CLOCK_SPINE_ATTRIBUTE_END_X, loc_data).as_int(); get_attribute(xml_spine, XML_CLOCK_SPINE_ATTRIBUTE_END_X, loc_data)
.as_int();
int end_y = int end_y =
get_attribute(xml_spine, XML_CLOCK_SPINE_ATTRIBUTE_END_Y, loc_data).as_int(); get_attribute(xml_spine, XML_CLOCK_SPINE_ATTRIBUTE_END_Y, loc_data)
.as_int();
clk_ntwk.set_spine_end_point(spine_id, vtr::Point<int>(end_x, end_y)); clk_ntwk.set_spine_end_point(spine_id, vtr::Point<int>(end_x, end_y));
for (pugi::xml_node xml_switch_point : xml_spine.children()) { for (pugi::xml_node xml_switch_point : xml_spine.children()) {
/* Error out if the XML child has an invalid name! */ /* Error out if the XML child has an invalid name! */
if (xml_switch_point.name() != std::string(XML_CLOCK_SPINE_SWITCH_POINT_NODE_NAME)) { if (xml_switch_point.name() !=
bad_tag(xml_switch_point, loc_data, xml_spine, {XML_CLOCK_SPINE_SWITCH_POINT_NODE_NAME}); std::string(XML_CLOCK_SPINE_SWITCH_POINT_NODE_NAME)) {
bad_tag(xml_switch_point, loc_data, xml_spine,
{XML_CLOCK_SPINE_SWITCH_POINT_NODE_NAME});
} }
read_xml_clock_spine_switch_point(xml_switch_point, loc_data, clk_ntwk, spine_id); read_xml_clock_spine_switch_point(xml_switch_point, loc_data, clk_ntwk,
spine_id);
} }
} }
@ -111,10 +125,12 @@ static void read_xml_clock_spine(pugi::xml_node& xml_spine,
static void read_xml_clock_tree(pugi::xml_node& xml_clk_tree, static void read_xml_clock_tree(pugi::xml_node& xml_clk_tree,
const pugiutil::loc_data& loc_data, const pugiutil::loc_data& loc_data,
ClockNetwork& clk_ntwk) { ClockNetwork& clk_ntwk) {
std::string clk_tree_name = std::string clk_tree_name =
get_attribute(xml_clk_tree, XML_CLOCK_TREE_ATTRIBUTE_NAME, loc_data).as_string(); get_attribute(xml_clk_tree, XML_CLOCK_TREE_ATTRIBUTE_NAME, loc_data)
int clk_tree_width = .as_string();
get_attribute(xml_clk_tree, XML_CLOCK_TREE_ATTRIBUTE_WIDTH, loc_data).as_int(); int clk_tree_width =
get_attribute(xml_clk_tree, XML_CLOCK_TREE_ATTRIBUTE_WIDTH, loc_data)
.as_int();
/* Create a new tree in the storage */ /* Create a new tree in the storage */
ClockTreeId tree_id = clk_ntwk.create_tree(clk_tree_name, clk_tree_width); ClockTreeId tree_id = clk_ntwk.create_tree(clk_tree_name, clk_tree_width);

View File

@ -1,5 +1,6 @@
/******************************************************************** /********************************************************************
* This file includes functions that outputs a clock network object to XML format * This file includes functions that outputs a clock network object to XML
*format
*******************************************************************/ *******************************************************************/
/* Headers from system goes first */ /* Headers from system goes first */
#include <algorithm> #include <algorithm>
@ -22,18 +23,21 @@
namespace openfpga { // Begin namespace openfpga namespace openfpga { // Begin namespace openfpga
static int write_xml_clock_spine_switch_point(std::fstream& fp, const ClockNetwork& clk_ntwk, static int write_xml_clock_spine_switch_point(
const ClockSpineId& spine_id, const ClockSwitchPointId& switch_point_id) { std::fstream& fp, const ClockNetwork& clk_ntwk, const ClockSpineId& spine_id,
const ClockSwitchPointId& switch_point_id) {
openfpga::write_tab_to_file(fp, 3); openfpga::write_tab_to_file(fp, 3);
fp << "<" << XML_CLOCK_SPINE_SWITCH_POINT_NODE_NAME << ""; fp << "<" << XML_CLOCK_SPINE_SWITCH_POINT_NODE_NAME << "";
write_xml_attribute(fp, XML_CLOCK_SPINE_SWITCH_POINT_ATTRIBUTE_TAP, write_xml_attribute(
clk_ntwk.spine_name(clk_ntwk.spine_switch_point_tap(spine_id, switch_point_id)).c_str()); fp, XML_CLOCK_SPINE_SWITCH_POINT_ATTRIBUTE_TAP,
vtr::Point<int> coord = clk_ntwk.spine_switch_point(spine_id, switch_point_id); clk_ntwk
write_xml_attribute(fp, XML_CLOCK_SPINE_SWITCH_POINT_ATTRIBUTE_X, .spine_name(clk_ntwk.spine_switch_point_tap(spine_id, switch_point_id))
coord.x()); .c_str());
write_xml_attribute(fp, XML_CLOCK_SPINE_SWITCH_POINT_ATTRIBUTE_Y, vtr::Point<int> coord =
coord.y()); clk_ntwk.spine_switch_point(spine_id, switch_point_id);
write_xml_attribute(fp, XML_CLOCK_SPINE_SWITCH_POINT_ATTRIBUTE_X, coord.x());
write_xml_attribute(fp, XML_CLOCK_SPINE_SWITCH_POINT_ATTRIBUTE_Y, coord.y());
fp << "/>" fp << "/>"
<< "\n"; << "\n";
@ -49,20 +53,17 @@ static int write_xml_clock_spine(std::fstream& fp, const ClockNetwork& clk_ntwk,
write_xml_attribute(fp, XML_CLOCK_SPINE_ATTRIBUTE_NAME, write_xml_attribute(fp, XML_CLOCK_SPINE_ATTRIBUTE_NAME,
clk_ntwk.spine_name(spine_id).c_str()); clk_ntwk.spine_name(spine_id).c_str());
vtr::Point<int> start_coord = clk_ntwk.spine_start_point(spine_id); vtr::Point<int> start_coord = clk_ntwk.spine_start_point(spine_id);
write_xml_attribute(fp, XML_CLOCK_SPINE_ATTRIBUTE_START_X, write_xml_attribute(fp, XML_CLOCK_SPINE_ATTRIBUTE_START_X, start_coord.x());
start_coord.x()); write_xml_attribute(fp, XML_CLOCK_SPINE_ATTRIBUTE_START_Y, start_coord.y());
write_xml_attribute(fp, XML_CLOCK_SPINE_ATTRIBUTE_START_Y,
start_coord.y());
vtr::Point<int> end_coord = clk_ntwk.spine_end_point(spine_id); vtr::Point<int> end_coord = clk_ntwk.spine_end_point(spine_id);
write_xml_attribute(fp, XML_CLOCK_SPINE_ATTRIBUTE_END_X, write_xml_attribute(fp, XML_CLOCK_SPINE_ATTRIBUTE_END_X, end_coord.x());
end_coord.x()); write_xml_attribute(fp, XML_CLOCK_SPINE_ATTRIBUTE_END_Y, end_coord.y());
write_xml_attribute(fp, XML_CLOCK_SPINE_ATTRIBUTE_END_Y,
end_coord.y());
fp << ">" fp << ">"
<< "\n"; << "\n";
for (const ClockSwitchPointId& switch_point_id : clk_ntwk.spine_switch_points(spine_id)) { for (const ClockSwitchPointId& switch_point_id :
clk_ntwk.spine_switch_points(spine_id)) {
write_xml_clock_spine_switch_point(fp, clk_ntwk, spine_id, switch_point_id); write_xml_clock_spine_switch_point(fp, clk_ntwk, spine_id, switch_point_id);
} }
@ -95,9 +96,8 @@ static int write_xml_clock_tree(std::fstream& fp, const ClockNetwork& clk_ntwk,
return 1; return 1;
} }
write_xml_attribute( write_xml_attribute(fp, XML_CLOCK_TREE_ATTRIBUTE_NAME,
fp, XML_CLOCK_TREE_ATTRIBUTE_NAME, clk_ntwk.tree_name(tree_id).c_str());
clk_ntwk.tree_name(tree_id).c_str());
write_xml_attribute(fp, XML_CLOCK_TREE_ATTRIBUTE_WIDTH, write_xml_attribute(fp, XML_CLOCK_TREE_ATTRIBUTE_WIDTH,
clk_ntwk.tree_width(tree_id)); clk_ntwk.tree_width(tree_id));
fp << ">" fp << ">"

View File

@ -27,7 +27,8 @@ int main(int argc, const char** argv) {
} }
VTR_ASSERT(clk_ntwk.is_valid()); VTR_ASSERT(clk_ntwk.is_valid());
for (auto tree_id : clk_ntwk.trees()) { for (auto tree_id : clk_ntwk.trees()) {
VTR_LOG("Max. depth of the clock tree '%lu' is %d", size_t(tree_id), clk_ntwk.tree_depth(tree_id)); VTR_LOG("Max. depth of the clock tree '%lu' is %d", size_t(tree_id),
clk_ntwk.tree_depth(tree_id));
} }
/* Output the bus group to an XML file /* Output the bus group to an XML file