Skip to content

Commit efd922c

Browse files
committed
removed most mallocs
1 parent 532bc04 commit efd922c

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

libs/libarchfpga/src/arch_util.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static void free_pb_type(t_pb_type* pb_type) {
335335
for (int m = 0; m < pb_type->modes[i].interconnect[j].annotations[k].num_value_prop_pairs; ++m) {
336336
vtr::free(pb_type->modes[i].interconnect[j].annotations[k].value[m]);
337337
}
338-
vtr::free(pb_type->modes[i].interconnect[j].annotations[k].prop);
338+
delete[] pb_type->modes[i].interconnect[j].annotations[k].prop;
339339
vtr::free(pb_type->modes[i].interconnect[j].annotations[k].value);
340340
}
341341
vtr::free(pb_type->modes[i].interconnect[j].annotations);
@@ -355,7 +355,7 @@ static void free_pb_type(t_pb_type* pb_type) {
355355
vtr::free(pb_type->annotations[i].value[j]);
356356
}
357357
vtr::free(pb_type->annotations[i].value);
358-
vtr::free(pb_type->annotations[i].prop);
358+
delete[] pb_type->annotations[i].prop;
359359
if (pb_type->annotations[i].input_pins) {
360360
vtr::free(pb_type->annotations[i].input_pins);
361361
}
@@ -367,7 +367,7 @@ static void free_pb_type(t_pb_type* pb_type) {
367367
}
368368
}
369369
if (pb_type->num_annotations > 0) {
370-
vtr::free(pb_type->annotations);
370+
delete[] pb_type->annotations;
371371
}
372372

373373
if (pb_type->pb_type_power) {
@@ -527,7 +527,7 @@ void alloc_and_load_default_child_for_pb_type(t_pb_type* pb_type,
527527
}
528528
}
529529

530-
copy->annotations = (t_pin_to_pin_annotation*)vtr::calloc(pb_type->num_annotations, sizeof(t_pin_to_pin_annotation));
530+
copy->annotations = new t_pin_to_pin_annotation[pb_type->num_annotations]();
531531
copy->num_annotations = pb_type->num_annotations;
532532
for (i = 0; i < copy->num_annotations; i++) {
533533
copy->annotations[i].clock = vtr::strdup(pb_type->annotations[i].clock);
@@ -549,7 +549,7 @@ void alloc_and_load_default_child_for_pb_type(t_pb_type* pb_type,
549549
copy->annotations[i].format = pb_type->annotations[i].format;
550550
copy->annotations[i].type = pb_type->annotations[i].type;
551551
copy->annotations[i].num_value_prop_pairs = pb_type->annotations[i].num_value_prop_pairs;
552-
copy->annotations[i].prop = (int*)vtr::malloc(sizeof(int) * pb_type->annotations[i].num_value_prop_pairs);
552+
copy->annotations[i].prop = new int[pb_type->annotations[i].num_value_prop_pairs];
553553
copy->annotations[i].value = (char**)vtr::malloc(sizeof(char*) * pb_type->annotations[i].num_value_prop_pairs);
554554
for (j = 0; j < pb_type->annotations[i].num_value_prop_pairs; j++) {
555555
copy->annotations[i].prop[j] = pb_type->annotations[i].prop[j];
@@ -627,8 +627,7 @@ void ProcessLutClass(t_pb_type* lut_pb_type) {
627627
lut_pb_type->modes[0].interconnect[0].annotations[i].format = lut_pb_type->annotations[i].format;
628628
lut_pb_type->modes[0].interconnect[0].annotations[i].type = lut_pb_type->annotations[i].type;
629629
lut_pb_type->modes[0].interconnect[0].annotations[i].num_value_prop_pairs = lut_pb_type->annotations[i].num_value_prop_pairs;
630-
lut_pb_type->modes[0].interconnect[0].annotations[i].prop = (int*)vtr::malloc(sizeof(int)
631-
* lut_pb_type->annotations[i].num_value_prop_pairs);
630+
lut_pb_type->modes[0].interconnect[0].annotations[i].prop = new int[lut_pb_type->annotations[i].num_value_prop_pairs];
632631
lut_pb_type->modes[0].interconnect[0].annotations[i].value = (char**)vtr::malloc(sizeof(char*)
633632
* lut_pb_type->annotations[i].num_value_prop_pairs);
634633
for (j = 0; j < lut_pb_type->annotations[i].num_value_prop_pairs; j++) {
@@ -654,7 +653,7 @@ void ProcessLutClass(t_pb_type* lut_pb_type) {
654653
free(lut_pb_type->annotations[i].value[j]);
655654
}
656655
free(lut_pb_type->annotations[i].value);
657-
free(lut_pb_type->annotations[i].prop);
656+
delete[] lut_pb_type->annotations[i].prop;
658657
if (lut_pb_type->annotations[i].input_pins) {
659658
free(lut_pb_type->annotations[i].input_pins);
660659
}
@@ -666,7 +665,7 @@ void ProcessLutClass(t_pb_type* lut_pb_type) {
666665
}
667666
}
668667
lut_pb_type->num_annotations = 0;
669-
free(lut_pb_type->annotations);
668+
delete[] lut_pb_type->annotations;
670669
lut_pb_type->annotations = nullptr;
671670
lut_pb_type->modes[1].pb_type_children[0].depth = lut_pb_type->depth + 1;
672671
lut_pb_type->modes[1].pb_type_children[0].parent_mode = &lut_pb_type->modes[1];
@@ -944,7 +943,7 @@ void SyncModelsPbTypes_rec(t_arch* arch,
944943

945944
pb_type->model_id = model_match_prim_id;
946945
vtr::t_linked_vptr* old = model_match_prim.pb_types;
947-
model_match_prim.pb_types = (vtr::t_linked_vptr*)vtr::malloc(sizeof(vtr::t_linked_vptr));
946+
model_match_prim.pb_types = new vtr::t_linked_vptr;
948947
model_match_prim.pb_types->next = old;
949948
model_match_prim.pb_types->data_vptr = pb_type;
950949

libs/libarchfpga/src/echo_arch.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ static void print_model(FILE* echo, const t_model& model) {
383383
static void PrintPb_types_rec(FILE* Echo, const t_pb_type* pb_type, int level, const LogicalModels& models) {
384384
char* tabs;
385385

386-
tabs = (char*)vtr::malloc((level + 1) * sizeof(char));
386+
tabs = new char[level + 1];
387387
for (int i = 0; i < level; i++) {
388388
tabs[i] = '\t';
389389
}
@@ -455,7 +455,7 @@ static void PrintPb_types_rec(FILE* Echo, const t_pb_type* pb_type, int level, c
455455
if (pb_type->pb_type_power) {
456456
PrintPb_types_recPower(Echo, pb_type, tabs);
457457
}
458-
free(tabs);
458+
delete[] tabs;
459459
}
460460

461461
//Added May 2013 Daniel Chen, help dump arch info after loading from XML

libs/libarchfpga/src/logic_types.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void LogicalModels::free_model_data(t_model& model) {
144144
while (vptr) {
145145
vtr::t_linked_vptr* vptr_prev = vptr;
146146
vptr = vptr->next;
147-
vtr::free(vptr_prev);
147+
delete vptr_prev;
148148
}
149149

150150
if (model.instances)

libs/libarchfpga/src/read_xml_arch_file.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ void XmlReadArch(const char* ArchFile,
536536
t_clock_arch* clocks_fake = (t_clock_arch*)vtr::calloc(1,
537537
sizeof(t_clock_arch));
538538
ProcessClocks(Next, clocks_fake, loc_data);
539-
free(clocks_fake->clock_inf);
539+
delete[] clocks_fake->clock_inf;
540540
free(clocks_fake);
541541
}
542542
}
@@ -887,7 +887,7 @@ static void ProcessPinToPinAnnotations(pugi::xml_node Parent,
887887
}
888888

889889
annotation->num_value_prop_pairs = i;
890-
annotation->prop = (int*)vtr::calloc(i, sizeof(int));
890+
annotation->prop = new int[i]();
891891
annotation->value = (char**)vtr::calloc(i, sizeof(char*));
892892
annotation->line_num = loc_data.line(Parent);
893893
/* Todo: This is slow, I should use a case lookup */
@@ -1377,7 +1377,7 @@ static void ProcessPb_Type(pugi::xml_node Parent,
13771377
num_annotations += count_children(Parent, child_name, loc_data, ReqOpt::OPTIONAL);
13781378
}
13791379

1380-
pb_type->annotations = (t_pin_to_pin_annotation*)vtr::calloc(num_annotations, sizeof(t_pin_to_pin_annotation));
1380+
pb_type->annotations = new t_pin_to_pin_annotation[num_annotations]();
13811381
pb_type->num_annotations = num_annotations;
13821382

13831383
int annotation_idx = 0;
@@ -4725,7 +4725,7 @@ static void ProcessClocks(pugi::xml_node Parent, t_clock_arch* clocks, const pug
47254725
/* Alloc the clockdetails */
47264726
clocks->clock_inf = nullptr;
47274727
if (clocks->num_global_clocks > 0) {
4728-
clocks->clock_inf = (t_clock_network*)vtr::malloc(clocks->num_global_clocks * sizeof(t_clock_network));
4728+
clocks->clock_inf = new t_clock_network[clocks->num_global_clocks];
47294729
memset(clocks->clock_inf, 0,
47304730
clocks->num_global_clocks * sizeof(t_clock_network));
47314731
}

0 commit comments

Comments
 (0)