Skip to content

Commit ca95008

Browse files
committed
[libs][arch] fix c-style code in read_xml_arch_file
1 parent 7c6a979 commit ca95008

File tree

1 file changed

+32
-60
lines changed

1 file changed

+32
-60
lines changed

libs/libarchfpga/src/read_xml_arch_file.cpp

Lines changed: 32 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,9 +2576,6 @@ static void process_model_ports(pugi::xml_node port_group, t_model& model, std::
25762576
static void process_layout(pugi::xml_node layout_tag, t_arch* arch, const pugiutil::loc_data& loc_data, int& num_of_avail_layer) {
25772577
VTR_ASSERT(layout_tag.name() == std::string("layout"));
25782578

2579-
//Expect no attributes on <layout>
2580-
//expect_only_attributes(layout_tag, {}, loc_data);
2581-
25822579
arch->tileable = get_attribute(layout_tag, "tileable", loc_data, ReqOpt::OPTIONAL).as_bool(false);
25832580
arch->perimeter_cb = get_attribute(layout_tag, "perimeter_cb", loc_data, ReqOpt::OPTIONAL).as_bool(false);
25842581
arch->shrink_boundary = get_attribute(layout_tag, "shrink_boundary", loc_data, ReqOpt::OPTIONAL).as_bool(false);
@@ -4156,17 +4153,15 @@ static std::vector<t_segment_inf> process_segments(pugi::xml_node Parent,
41564153
}
41574154

41584155
static void process_bend(pugi::xml_node Node, std::vector<int>& list, std::vector<int>& part_len, bool& is_bend, const int len, const pugiutil::loc_data& loc_data) {
4159-
const char* tmp = nullptr;
4160-
int i;
41614156

4162-
tmp = get_attribute(Node, "type", loc_data).value();
4163-
if (0 == strcmp(tmp, "pattern")) {
4164-
i = 0;
4157+
std::string tmp = std::string(get_attribute(Node, "type", loc_data).value());
4158+
if (tmp == "pattern") {
4159+
int i = 0;
41654160

41664161
/* Get the content string */
4167-
tmp = Node.child_value();
4168-
while (*tmp) {
4169-
switch (*tmp) {
4162+
std::string content = std::string(Node.child_value());
4163+
for (char c : content) {
4164+
switch (c) {
41704165
case ' ':
41714166
case '\t':
41724167
case '\n':
@@ -4184,28 +4179,24 @@ static void process_bend(pugi::xml_node Node, std::vector<int>& list, std::vecto
41844179
break;
41854180
case 'B':
41864181
archfpga_throw(loc_data.filename_c_str(), loc_data.line(Node),
4187-
"B pattern is not supported in current version\n",
4188-
*tmp);
4182+
"B pattern is not supported in current version\n");
41894183
break;
41904184
default:
41914185
archfpga_throw(loc_data.filename_c_str(), loc_data.line(Node),
41924186
"Invalid character %c in CB or SB depopulation list.\n",
4193-
*tmp);
4187+
c);
41944188
}
4195-
++tmp;
41964189
}
41974190

41984191
if (list.size() != size_t(len)) {
41994192
archfpga_throw(loc_data.filename_c_str(), loc_data.line(Node),
42004193
"Wrong length of bend list (%d). Expect %d symbols.\n",
42014194
i, len);
42024195
}
4203-
}
4204-
4205-
else {
4196+
} else {
42064197
archfpga_throw(loc_data.filename_c_str(), loc_data.line(Node),
42074198
"'%s' is not a valid type for specifying bend list.\n",
4208-
tmp);
4199+
tmp.c_str());
42094200
}
42104201

42114202
int tmp_len = 1;
@@ -5142,13 +5133,9 @@ static T* get_type_by_name(std::string_view type_name, std::vector<T>& types) {
51425133

51435134
/* for vib arch*/
51445135
static void process_vib_arch(pugi::xml_node Parent, std::vector<t_physical_tile_type>& PhysicalTileTypes, t_arch* arch, const pugiutil::loc_data& loc_data) {
5145-
pugi::xml_node Node;
5146-
//pugi::xml_node SubElem;
5147-
5148-
//arch->is_vib_arch = true;
51495136
int num_vibs = count_children(Parent, "vib", loc_data);
51505137
arch->vib_infs.reserve(num_vibs);
5151-
Node = get_first_child(Parent, "vib", loc_data);
5138+
pugi::xml_node Node = get_first_child(Parent, "vib", loc_data);
51525139

51535140
for (int i_vib = 0; i_vib < num_vibs; i_vib++) {
51545141
process_vib(Node, PhysicalTileTypes, arch, loc_data);
@@ -5157,25 +5144,18 @@ static void process_vib_arch(pugi::xml_node Parent, std::vector<t_physical_tile_
51575144
}
51585145

51595146
static void process_vib(pugi::xml_node Vib_node, std::vector<t_physical_tile_type>& PhysicalTileTypes, t_arch* arch, const pugiutil::loc_data& loc_data) {
5160-
pugi::xml_node Node;
5161-
pugi::xml_node SubElem;
5162-
const char* tmp;
5163-
int itmp;
5164-
51655147
VibInf vib;
5166-
// std::vector<t_segment_inf> segments = arch->Segments;
5167-
// t_arch_switch_inf* switches = arch->Switches;
51685148

5169-
tmp = get_attribute(Vib_node, "name", loc_data).as_string(nullptr);
5170-
if (tmp) {
5149+
std::string tmp = get_attribute(Vib_node, "name", loc_data).as_string("");
5150+
if (!tmp.empty()) {
51715151
vib.set_name(tmp);
51725152
} else {
51735153
archfpga_throw(loc_data.filename_c_str(), loc_data.line(Vib_node),
51745154
"No name specified for the vib!\n");
51755155
}
51765156

5177-
tmp = get_attribute(Vib_node, "pbtype_name", loc_data).as_string(nullptr);
5178-
if (tmp) {
5157+
tmp = get_attribute(Vib_node, "pbtype_name", loc_data).as_string("");
5158+
if (!tmp.empty()) {
51795159
vib.set_pbtype_name(tmp);
51805160
} else {
51815161
archfpga_throw(loc_data.filename_c_str(), loc_data.line(Vib_node),
@@ -5184,9 +5164,9 @@ static void process_vib(pugi::xml_node Vib_node, std::vector<t_physical_tile_typ
51845164

51855165
vib.set_seg_group_num(get_attribute(Vib_node, "vib_seg_group", loc_data).as_int(1));
51865166

5187-
tmp = get_attribute(Vib_node, "arch_vib_switch", loc_data).as_string(nullptr);
5167+
tmp = get_attribute(Vib_node, "arch_vib_switch", loc_data).as_string("");
51885168

5189-
if (tmp) {
5169+
if (!tmp.empty()) {
51905170
std::string str_tmp;
51915171
str_tmp = tmp;
51925172
vib.set_switch_name(str_tmp);
@@ -5200,35 +5180,35 @@ static void process_vib(pugi::xml_node Vib_node, std::vector<t_physical_tile_typ
52005180
int group_num = count_children(Vib_node, "seg_group", loc_data);
52015181
VTR_ASSERT(vib.get_seg_group_num() == group_num);
52025182
//vib.seg_groups.reserve(group_num);
5203-
Node = get_first_child(Vib_node, "seg_group", loc_data);
5183+
pugi::xml_node Node = get_first_child(Vib_node, "seg_group", loc_data);
52045184
for (int i_group = 0; i_group < group_num; i_group++) {
52055185
t_seg_group seg_group;
52065186

5207-
tmp = get_attribute(Node, "name", loc_data).as_string(nullptr);
5187+
tmp = get_attribute(Node, "name", loc_data).as_string("");
52085188

5209-
if (tmp) {
5189+
if (!tmp.empty()) {
52105190
seg_group.name = tmp;
52115191
} else {
52125192
archfpga_throw(loc_data.filename_c_str(), loc_data.line(Node),
52135193
"No name specified for the vib seg group!\n");
52145194
}
52155195

52165196
seg_group.axis = BOTH_DIR; /*DEFAULT value if no axis is specified*/
5217-
tmp = get_attribute(Node, "axis", loc_data, ReqOpt::OPTIONAL).as_string(nullptr);
5197+
tmp = get_attribute(Node, "axis", loc_data, ReqOpt::OPTIONAL).as_string("");
52185198

5219-
if (tmp) {
5220-
if (strcmp(tmp, "x") == 0) {
5199+
if (!tmp.empty()) {
5200+
if (tmp == "x") {
52215201
seg_group.axis = X;
5222-
} else if (strcmp(tmp, "y") == 0) {
5202+
} else if (tmp == "y") {
52235203
seg_group.axis = Y;
52245204
} else {
52255205
archfpga_throw(loc_data.filename_c_str(), loc_data.line(Node), "Unsopported parralel axis type: %s\n", tmp);
52265206
}
52275207
}
52285208

5229-
itmp = get_attribute(Node, "track_nums", loc_data).as_int();
5230-
if (itmp) {
5231-
seg_group.track_num = itmp;
5209+
int track_num = get_attribute(Node, "track_nums", loc_data).as_int();
5210+
if (track_num > 0) {
5211+
seg_group.track_num = track_num;
52325212
} else {
52335213
archfpga_throw(loc_data.filename_c_str(), loc_data.line(Node),
52345214
"No track_num specified for the vib seg group!\n");
@@ -5242,7 +5222,7 @@ static void process_vib(pugi::xml_node Vib_node, std::vector<t_physical_tile_typ
52425222
Node = get_single_child(Vib_node, "multistage_muxs", loc_data);
52435223
expect_only_children(Node, {"first_stage", "second_stage"}, loc_data);
52445224

5245-
SubElem = get_single_child(Node, "first_stage", loc_data);
5225+
pugi::xml_node SubElem = get_single_child(Node, "first_stage", loc_data);
52465226
if (SubElem) {
52475227
std::vector<t_first_stage_mux_inf> first_stages;
52485228
process_first_stage(SubElem, PhysicalTileTypes, first_stages, loc_data);
@@ -5266,21 +5246,16 @@ static void process_vib(pugi::xml_node Vib_node, std::vector<t_physical_tile_typ
52665246
}
52675247

52685248
static void process_first_stage(pugi::xml_node Stage_node, std::vector<t_physical_tile_type>& /*PhysicalTileTypes*/, std::vector<t_first_stage_mux_inf>& first_stages, const pugiutil::loc_data& loc_data) {
5269-
pugi::xml_node Node;
5270-
pugi::xml_node SubElem;
5271-
//pugi::xml_node Cur;
5272-
//const char* tmp;
5273-
52745249
expect_only_children(Stage_node, {"mux"}, loc_data);
52755250
int num_mux = count_children(Stage_node, "mux", loc_data);
52765251
first_stages.reserve(num_mux);
5277-
Node = get_first_child(Stage_node, "mux", loc_data);
5252+
pugi::xml_node Node = get_first_child(Stage_node, "mux", loc_data);
52785253
for (int i_mux = 0; i_mux < num_mux; i_mux++) {
52795254
t_first_stage_mux_inf first_stage_mux;
52805255
first_stage_mux.mux_name = get_attribute(Node, "name", loc_data).as_string();
52815256

52825257
expect_only_children(Node, {"from"}, loc_data);
5283-
SubElem = get_first_child(Node, "from", loc_data);
5258+
pugi::xml_node SubElem = get_first_child(Node, "from", loc_data);
52845259
int from_num = count_children(Node, "from", loc_data);
52855260
for (int i_from = 0; i_from < from_num; i_from++) {
52865261
std::vector<std::string> from_tokens = vtr::split(SubElem.child_value());
@@ -5294,20 +5269,17 @@ static void process_first_stage(pugi::xml_node Stage_node, std::vector<t_physica
52945269
}
52955270

52965271
static void process_second_stage(pugi::xml_node Stage_node, std::vector<t_physical_tile_type>& /*PhysicalTileTypes*/, std::vector<t_second_stage_mux_inf>& second_stages, const pugiutil::loc_data& loc_data) {
5297-
pugi::xml_node Node;
5298-
pugi::xml_node SubElem;
5299-
53005272
expect_only_children(Stage_node, {"mux"}, loc_data);
53015273
int num_mux = count_children(Stage_node, "mux", loc_data);
53025274
second_stages.reserve(num_mux);
5303-
Node = get_first_child(Stage_node, "mux", loc_data);
5275+
pugi::xml_node Node = get_first_child(Stage_node, "mux", loc_data);
53045276
for (int i_mux = 0; i_mux < num_mux; i_mux++) {
53055277
t_second_stage_mux_inf second_stage_mux;
53065278
second_stage_mux.mux_name = get_attribute(Node, "name", loc_data).as_string();
53075279

53085280
expect_only_children(Node, {"to", "from"}, loc_data);
53095281

5310-
SubElem = get_first_child(Node, "to", loc_data);
5282+
pugi::xml_node SubElem = get_first_child(Node, "to", loc_data);
53115283
int to_num = count_children(Node, "to", loc_data);
53125284
VTR_ASSERT(to_num == 1);
53135285
std::vector<std::string> to_tokens = vtr::split(SubElem.child_value());

0 commit comments

Comments
 (0)