Skip to content

Commit 41a2802

Browse files
replace char* with std::string and use local loop vars
1 parent c8be807 commit 41a2802

21 files changed

+162
-181
lines changed

libs/libarchfpga/src/arch_util.cpp

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,17 @@ t_model_ports* free_arch_model_port(t_model_ports* model_port) {
250250
}
251251

252252
void free_type_descriptors(std::vector<t_physical_tile_type>& type_descriptors) {
253-
for (auto& type : type_descriptors) {
254-
vtr::free(type.name);
253+
for (t_physical_tile_type& type : type_descriptors) {
254+
vtr::release_memory(type.name);
255+
255256
if (type.index == EMPTY_TYPE_INDEX) {
256257
continue;
257258
}
258259

259-
for (auto& sub_tile : type.sub_tiles) {
260-
vtr::free(sub_tile.name);
260+
for (t_sub_tile& sub_tile : type.sub_tiles) {
261+
vtr::release_memory(sub_tile.name);
261262

262-
for (auto port : sub_tile.ports) {
263+
for (t_physical_tile_port& port : sub_tile.ports) {
263264
vtr::free(port.name);
264265
}
265266
}
@@ -270,8 +271,8 @@ void free_type_descriptors(std::vector<t_physical_tile_type>& type_descriptors)
270271
void free_type_descriptors(std::vector<t_logical_block_type>& type_descriptors) {
271272
free_all_pb_graph_nodes(type_descriptors);
272273

273-
for (auto& type : type_descriptors) {
274-
vtr::free(type.name);
274+
for (t_logical_block_type& type : type_descriptors) {
275+
vtr::release_memory(type.name);
275276
if (type.index == EMPTY_TYPE_INDEX) {
276277
continue;
277278
}
@@ -1098,7 +1099,6 @@ void SyncModelsPbTypes(t_arch* arch,
10981099

10991100
void SyncModelsPbTypes_rec(t_arch* arch,
11001101
t_pb_type* pb_type) {
1101-
int i, j, p;
11021102
t_model *model_match_prim, *cur_model;
11031103
t_model_ports* model_port;
11041104
vtr::t_linked_vptr* old;
@@ -1137,7 +1137,7 @@ void SyncModelsPbTypes_rec(t_arch* arch,
11371137
}
11381138
cur_model = cur_model->next;
11391139
}
1140-
if (found != true) {
1140+
if (!found) {
11411141
archfpga_throw(get_arch_file_name(), 0,
11421142
"No matching model for pb_type %s\n", pb_type->blif_model);
11431143
}
@@ -1148,7 +1148,7 @@ void SyncModelsPbTypes_rec(t_arch* arch,
11481148
model_match_prim->pb_types->next = old;
11491149
model_match_prim->pb_types->data_vptr = pb_type;
11501150

1151-
for (p = 0; p < pb_type->num_ports; p++) {
1151+
for (int p = 0; p < pb_type->num_ports; p++) {
11521152
found = false;
11531153
/* TODO: Parse error checking - check if INPUT matches INPUT and OUTPUT matches OUTPUT (not yet done) */
11541154
model_port = model_match_prim->inputs;
@@ -1197,17 +1197,16 @@ void SyncModelsPbTypes_rec(t_arch* arch,
11971197
}
11981198
model_port = model_port->next;
11991199
}
1200-
if (found != true) {
1200+
if (!found) {
12011201
archfpga_throw(get_arch_file_name(), 0,
12021202
"No matching model port for port %s in pb_type %s\n",
12031203
pb_type->ports[p].name, pb_type->name);
12041204
}
12051205
}
12061206
} else {
1207-
for (i = 0; i < pb_type->num_modes; i++) {
1208-
for (j = 0; j < pb_type->modes[i].num_pb_type_children; j++) {
1209-
SyncModelsPbTypes_rec(arch,
1210-
&(pb_type->modes[i].pb_type_children[j]));
1207+
for (int i = 0; i < pb_type->num_modes; i++) {
1208+
for (int j = 0; j < pb_type->modes[i].num_pb_type_children; j++) {
1209+
SyncModelsPbTypes_rec(arch, &(pb_type->modes[i].pb_type_children[j]));
12111210
}
12121211
}
12131212
}
@@ -1223,11 +1222,11 @@ void SyncModelsPbTypes_rec(t_arch* arch,
12231222
void primitives_annotation_clock_match(t_pin_to_pin_annotation* annotation,
12241223
t_pb_type* parent_pb_type) {
12251224
int i_port;
1226-
bool clock_valid = false; //Determine if annotation's clock is same as primtive's clock
1225+
bool clock_valid = false; //Determine if annotation's clock is same as primitive's clock
12271226

12281227
if (!parent_pb_type || !annotation) {
12291228
archfpga_throw(__FILE__, __LINE__,
1230-
"Annotation_clock check encouters invalid annotation or primitive.\n");
1229+
"Annotation_clock check encounters invalid annotation or primitive.\n");
12311230
}
12321231

12331232
for (i_port = 0; i_port < parent_pb_type->num_ports; i_port++) {
@@ -1247,18 +1246,17 @@ void primitives_annotation_clock_match(t_pin_to_pin_annotation* annotation,
12471246
}
12481247
}
12491248

1250-
const t_segment_inf* find_segment(const t_arch* arch, std::string name) {
1251-
for (size_t i = 0; i < (arch->Segments).size(); ++i) {
1252-
const t_segment_inf* seg = &arch->Segments[i];
1253-
if (seg->name == name) {
1254-
return seg;
1249+
const t_segment_inf* find_segment(const t_arch* arch, std::string_view name) {
1250+
for (const auto& segment : arch->Segments) {
1251+
if (segment.name == name) {
1252+
return &segment;
12551253
}
12561254
}
12571255

12581256
return nullptr;
12591257
}
12601258

1261-
bool segment_exists(const t_arch* arch, std::string name) {
1259+
bool segment_exists(const t_arch* arch, std::string_view name) {
12621260
return find_segment(arch, name) != nullptr;
12631261
}
12641262

@@ -1336,7 +1334,7 @@ const t_pin_to_pin_annotation* find_sequential_annotation(const t_pb_type* pb_ty
13361334
return nullptr;
13371335
}
13381336

1339-
const t_pin_to_pin_annotation* find_combinational_annotation(const t_pb_type* pb_type, std::string in_port, std::string out_port) {
1337+
const t_pin_to_pin_annotation* find_combinational_annotation(const t_pb_type* pb_type, std::string_view in_port, std::string_view out_port) {
13401338
for (int iannot = 0; iannot < pb_type->num_annotations; ++iannot) {
13411339
const t_pin_to_pin_annotation* annot = &pb_type->annotations[iannot];
13421340
for (const auto& annot_in_str : vtr::split(annot->input_pins)) {
@@ -1380,24 +1378,24 @@ void link_physical_logical_types(std::vector<t_physical_tile_type>& PhysicalTile
13801378

13811379
std::sort(equivalent_sites.begin(), equivalent_sites.end(), criteria);
13821380

1383-
for (auto& logical_block : LogicalBlockTypes) {
1381+
for (t_logical_block_type& logical_block : LogicalBlockTypes) {
13841382
for (auto site : equivalent_sites) {
1385-
if (0 == strcmp(logical_block.name, site->pb_type->name)) {
1383+
if (logical_block.name == site->pb_type->name) {
13861384
logical_block.equivalent_tiles.push_back(&physical_tile);
13871385
break;
13881386
}
13891387
}
13901388
}
13911389
}
13921390

1393-
for (auto& logical_block : LogicalBlockTypes) {
1391+
for (t_logical_block_type& logical_block : LogicalBlockTypes) {
13941392
if (logical_block.index == EMPTY_TYPE_INDEX) continue;
13951393

13961394
auto& equivalent_tiles = logical_block.equivalent_tiles;
13971395

13981396
if ((int)equivalent_tiles.size() <= 0) {
13991397
archfpga_throw(__FILE__, __LINE__,
1400-
"Logical Block %s does not have any equivalent tiles.\n", logical_block.name);
1398+
"Logical Block %s does not have any equivalent tiles.\n", logical_block.name.c_str());
14011399
}
14021400

14031401
std::unordered_map<int, bool> ignored_pins_check_map;
@@ -1433,7 +1431,7 @@ void link_physical_logical_types(std::vector<t_physical_tile_type>& PhysicalTile
14331431
if (result == direct_map.end()) {
14341432
archfpga_throw(__FILE__, __LINE__,
14351433
"Logical pin %d not present in pin mapping between Tile %s and Block %s.\n",
1436-
pin, tile->name, logical_block.name);
1434+
pin, tile->name.c_str(), logical_block.name.c_str());
14371435
}
14381436

14391437
int sub_tile_pin_index = result->second.pin;
@@ -1447,15 +1445,15 @@ void link_physical_logical_types(std::vector<t_physical_tile_type>& PhysicalTile
14471445
archfpga_throw(__FILE__, __LINE__,
14481446
"Physical Tile %s has a different value for the ignored pin (physical pin: %d, logical pin: %d) "
14491447
"different from the corresponding pins of the other equivalent site %s\n.",
1450-
tile->name, phy_index, pin, logical_block.name);
1448+
tile->name.c_str(), phy_index, pin, logical_block.name.c_str());
14511449
}
14521450

14531451
auto global_result = global_pins_check_map.insert(std::pair<int, bool>(pin, is_global));
14541452
if (!global_result.second && global_result.first->second != is_global) {
14551453
archfpga_throw(__FILE__, __LINE__,
14561454
"Physical Tile %s has a different value for the global pin (physical pin: %d, logical pin: %d) "
14571455
"different from the corresponding pins of the other equivalent sites\n.",
1458-
tile->name, phy_index, pin);
1456+
tile->name.c_str(), phy_index, pin);
14591457
}
14601458
}
14611459
}
@@ -1465,27 +1463,25 @@ void link_physical_logical_types(std::vector<t_physical_tile_type>& PhysicalTile
14651463

14661464
/* Sets up the pin classes for the type. */
14671465
void setup_pin_classes(t_physical_tile_type* type) {
1468-
int i, k;
1469-
int pin_count;
14701466
int num_class;
14711467

1472-
for (i = 0; i < type->num_pins; i++) {
1468+
for (int i = 0; i < type->num_pins; i++) {
14731469
type->pin_class.push_back(OPEN);
14741470
type->is_ignored_pin.push_back(true);
14751471
type->is_pin_global.push_back(true);
14761472
}
14771473

1478-
pin_count = 0;
1474+
int pin_count = 0;
14791475

14801476
t_class_range class_range;
14811477

14821478
/* Equivalent pins share the same class, non-equivalent pins belong to different pin classes */
1483-
for (auto& sub_tile : type->sub_tiles) {
1479+
for (const t_sub_tile& sub_tile : type->sub_tiles) {
14841480
int capacity = sub_tile.capacity.total();
14851481
class_range.low = type->class_inf.size();
14861482
class_range.high = class_range.low - 1;
1487-
for (i = 0; i < capacity; ++i) {
1488-
for (const auto& port : sub_tile.ports) {
1483+
for (int i = 0; i < capacity; ++i) {
1484+
for (const t_physical_tile_port& port : sub_tile.ports) {
14891485
if (port.equivalent != PortEquivalence::NONE) {
14901486
t_class class_inf;
14911487
num_class = (int)type->class_inf.size();
@@ -1499,7 +1495,7 @@ void setup_pin_classes(t_physical_tile_type* type) {
14991495
class_inf.type = DRIVER;
15001496
}
15011497

1502-
for (k = 0; k < port.num_pins; ++k) {
1498+
for (int k = 0; k < port.num_pins; ++k) {
15031499
class_inf.pinlist.push_back(pin_count);
15041500
type->pin_class[pin_count] = num_class;
15051501
// clock pins and other specified global ports are initially specified
@@ -1519,7 +1515,7 @@ void setup_pin_classes(t_physical_tile_type* type) {
15191515
type->class_inf.push_back(class_inf);
15201516
class_range.high++;
15211517
} else if (port.equivalent == PortEquivalence::NONE) {
1522-
for (k = 0; k < port.num_pins; ++k) {
1518+
for (int k = 0; k < port.num_pins; ++k) {
15231519
t_class class_inf;
15241520
num_class = (int)type->class_inf.size();
15251521
class_inf.num_pins = 1;
@@ -1538,7 +1534,7 @@ void setup_pin_classes(t_physical_tile_type* type) {
15381534
// as ignored pins (i.e. connections are not created in the rr_graph and
15391535
// nets connected to the port are ignored as well).
15401536
type->is_ignored_pin[pin_count] = port.is_clock || port.is_non_clock_global;
1541-
// clock pins and other specified global ports are flaged as global
1537+
// clock pins and other specified global ports are flagged as global
15421538
type->is_pin_global[pin_count] = port.is_clock || port.is_non_clock_global;
15431539

15441540
if (port.is_clock) {

libs/libarchfpga/src/arch_util.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ void SyncModelsPbTypes_rec(t_arch* arch,
9595
void primitives_annotation_clock_match(t_pin_to_pin_annotation* annotation,
9696
t_pb_type* parent_pb_type);
9797

98-
bool segment_exists(const t_arch* arch, std::string name);
99-
const t_segment_inf* find_segment(const t_arch* arch, std::string name);
98+
bool segment_exists(const t_arch* arch, std::string_view name);
99+
const t_segment_inf* find_segment(const t_arch* arch, std::string_view name);
100100
bool is_library_model(const char* model_name);
101101
bool is_library_model(const t_model* model);
102102

@@ -107,7 +107,7 @@ bool block_type_contains_blif_model(t_logical_block_type_ptr type, const std::st
107107
bool pb_type_contains_blif_model(const t_pb_type* pb_type, const std::string& blif_model_name);
108108

109109
const t_pin_to_pin_annotation* find_sequential_annotation(const t_pb_type* pb_type, const t_model_ports* port, enum e_pin_to_pin_delay_annotations annot_type);
110-
const t_pin_to_pin_annotation* find_combinational_annotation(const t_pb_type* pb_type, std::string in_port, std::string out_port);
110+
const t_pin_to_pin_annotation* find_combinational_annotation(const t_pb_type* pb_type, std::string_view in_port, std::string_view out_port);
111111

112112
/**
113113
* @brief Updates the physical and logical types based on the equivalence between one and the other.

0 commit comments

Comments
 (0)