Skip to content

Commit

Permalink
[Warnings] Changed C String to STD String
Browse files Browse the repository at this point in the history
GCC sometimes gets confused with how strings are allocated, when they
are C strings allocated by hand. Changed to an std string since it is
easier to work with and removes the warning.
  • Loading branch information
AlexandreSinger committed Aug 21, 2024
1 parent 574875f commit 5ee6721
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
3 changes: 1 addition & 2 deletions vpr/src/power/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static void power_usage_primitive(t_power_usage* power_usage, t_pb* pb, t_pb_gra
if (strcmp(pb_graph_node->pb_type->blif_model, MODEL_NAMES) == 0) {
/* LUT */

char* SRAM_values;
std::string SRAM_values;
float* input_probabilities;
float* input_densities;
int LUT_size;
Expand Down Expand Up @@ -174,7 +174,6 @@ static void power_usage_primitive(t_power_usage* power_usage, t_pb* pb, t_pb_gra
power_ctx.arch->LUT_transistor_size, SRAM_values,
input_probabilities, input_densities, power_ctx.solution_inf.T_crit);
power_add_usage(power_usage, &sub_power_usage);
delete[] SRAM_values;
delete[] input_probabilities;
delete[] input_densities;
} else if (strcmp(pb_graph_node->pb_type->blif_model, MODEL_LATCH) == 0) {
Expand Down
3 changes: 2 additions & 1 deletion vpr/src/power/power_components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
/************************* INCLUDES *********************************/
#include <cstring>
#include <cmath>
#include <string>

#include "vtr_math.h"
#include "vtr_assert.h"
Expand Down Expand Up @@ -203,7 +204,7 @@ void power_usage_ff(t_power_usage* power_usage, float size, float D_prob, float
* 7 _Z_|
*
*/
void power_usage_lut(t_power_usage* power_usage, int lut_size, float transistor_size, char* SRAM_values, float* input_prob, float* input_dens, float period) {
void power_usage_lut(t_power_usage* power_usage, int lut_size, float transistor_size, std::string SRAM_values, float* input_prob, float* input_dens, float period) {
float** internal_prob;
float** internal_dens;
float** internal_v;
Expand Down
3 changes: 2 additions & 1 deletion vpr/src/power/power_components.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define __POWER_COMPONENTS_H__

/************************* INCLUDES *********************************/
#include <string>
#include "power.h"
#include "clustered_netlist.h"

Expand Down Expand Up @@ -82,7 +83,7 @@ void power_component_add_usage(t_power_usage* power_usage,
float power_component_get_usage_sum(e_power_component_type component_idx);

void power_usage_ff(t_power_usage* power_usage, float size, float D_prob, float D_dens, float Q_prob, float Q_dens, float clk_prob, float clk_dens, float period);
void power_usage_lut(t_power_usage* power_usage, int LUT_size, float transistor_size, char* SRAM_values, float* input_densities, float* input_probabilities, float period);
void power_usage_lut(t_power_usage* power_usage, int LUT_size, float transistor_size, std::string SRAM_values, float* input_densities, float* input_probabilities, float period);
void power_usage_local_interc_mux(t_power_usage* power_usage, t_pb* pb, t_interconnect_pins* interc_pins, ClusterBlockId iblk);
void power_usage_mux_multilevel(t_power_usage* power_usage,
t_mux_arch* mux_arch,
Expand Down
10 changes: 4 additions & 6 deletions vpr/src/power/power_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <cstring>
#include <cmath>
#include <map>
#include <string>

#include "vtr_assert.h"
#include "vtr_memory.h"
Expand Down Expand Up @@ -211,16 +212,13 @@ float calc_buffer_stage_effort(int N, float final_stage_size) {
* - LUT_size: The number of LUT inputs
* - truth_table: The logic terms saved from the BLIF file
*/
char* alloc_SRAM_values_from_truth_table(int LUT_size,
const AtomNetlist::TruthTable& truth_table) {
std::string alloc_SRAM_values_from_truth_table(int LUT_size,
const AtomNetlist::TruthTable& truth_table) {
size_t num_SRAM_bits = 1 << LUT_size;

//SRAM value stored as a string of '0' and '1' characters
// Initialize to all zeros
char* SRAM_values = new char[num_SRAM_bits + 1];
for (size_t i = 0; i < num_SRAM_bits + 1; i++)
SRAM_values[i] = '0';
SRAM_values[num_SRAM_bits] = '\0';
std::string SRAM_values(num_SRAM_bits, '0');

if (truth_table.empty()) {
for (size_t i = 0; i < num_SRAM_bits; i++) {
Expand Down
5 changes: 3 additions & 2 deletions vpr/src/power/power_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define __POWER_UTIL_H__

/************************* INCLUDES *********************************/
#include <string>
#include "power.h"
#include "power_components.h"
#include "atom_netlist.h"
Expand Down Expand Up @@ -63,8 +64,8 @@ bool power_method_is_transistor_level(e_power_estimation_method estimation_metho
bool power_method_is_recursive(e_power_estimation_method method);

const char* transistor_type_name(e_tx_type type);
char* alloc_SRAM_values_from_truth_table(int LUT_size,
const AtomNetlist::TruthTable& truth_table);
std::string alloc_SRAM_values_from_truth_table(int LUT_size,
const AtomNetlist::TruthTable& truth_table);
float clb_net_density(ClusterNetId net_idx);
const char* interconnect_type_name(enum e_interconnect type);
float clb_net_prob(ClusterNetId net_idx);
Expand Down

0 comments on commit 5ee6721

Please sign in to comment.