Skip to content

Commit 3ee4a62

Browse files
Merge pull request #3269 from verilog-to-routing/sg_parsing_fix_uninitialized
Fix bug where sg_link offsets would be uninitialized
2 parents a543f21 + e56d835 commit 3ee4a62

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

libs/libarchfpga/src/read_xml_arch_file_sg.cpp

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "pugixml_util.hpp"
55
#include "arch_error.h"
66
#include "switchblock_types.h"
7+
#include "vtr_util.h"
78

89
/**
910
* @brief Parses all <sg_link> tags under a <sg_link_list> tag.
@@ -26,32 +27,12 @@ static std::vector<t_sg_link> parse_sg_link_tags(pugi::xml_node sg_link_list_tag
2627
sg_link.seg_type = pugiutil::get_attribute(node, "seg_type", loc_data).as_string();
2728

2829
// Since the offset attributes are optional and might not exist, the as_int method will return a value of zero if the attribute is empty
29-
int x_offset = pugiutil::get_attribute(node, "x_offset", loc_data, pugiutil::OPTIONAL).as_int(0);
30-
int y_offset = pugiutil::get_attribute(node, "y_offset", loc_data, pugiutil::OPTIONAL).as_int(0);
31-
int z_offset = pugiutil::get_attribute(node, "z_offset", loc_data, pugiutil::OPTIONAL).as_int(0);
30+
sg_link.x_offset = pugiutil::get_attribute(node, "x_offset", loc_data, pugiutil::OPTIONAL).as_int(0);
31+
sg_link.y_offset = pugiutil::get_attribute(node, "y_offset", loc_data, pugiutil::OPTIONAL).as_int(0);
32+
sg_link.z_offset = pugiutil::get_attribute(node, "z_offset", loc_data, pugiutil::OPTIONAL).as_int(0);
3233

33-
if (x_offset == 0 && y_offset == 0 && z_offset == 0) {
34-
archfpga_throw(loc_data.filename_c_str(), loc_data.line(node), "All offset fields in the <sg_link> are zero or missing.");
35-
}
36-
37-
// We expect exactly one non-zero offset so the gather and scatter points are joined by a node that can be represented by a straight wire.
38-
if (x_offset != 0) {
39-
sg_link.x_offset = x_offset;
40-
if (y_offset != 0 || z_offset != 0) {
41-
archfpga_throw(loc_data.filename_c_str(), loc_data.line(node), "More than one of the offset fields in the <sg_link> are non-zero.");
42-
}
43-
}
44-
if (y_offset != 0) {
45-
sg_link.y_offset = y_offset;
46-
if (x_offset != 0 || z_offset != 0) {
47-
archfpga_throw(loc_data.filename_c_str(), loc_data.line(node), "More than one of the offset fields in the <sg_link> are non-zero.");
48-
}
49-
}
50-
if (z_offset != 0) {
51-
sg_link.z_offset = z_offset;
52-
if (y_offset != 0 || x_offset != 0) {
53-
archfpga_throw(loc_data.filename_c_str(), loc_data.line(node), "More than one of the offset fields in the <sg_link> are non-zero.");
54-
}
34+
if (!vtr::exactly_k_conditions(1, sg_link.x_offset != 0, sg_link.y_offset != 0, sg_link.z_offset != 0)) {
35+
archfpga_throw(loc_data.filename_c_str(), loc_data.line(node), "One and only one of the offset fields in the <sg_link> should be non-zero.");
5536
}
5637

5738
sg_link_list.push_back(sg_link);

0 commit comments

Comments
 (0)