Skip to content

Commit

Permalink
Avoid duplicate calculation of number of float variables (#1067)
Browse files Browse the repository at this point in the history
* Refactor `float_variables_size` and `int_variables_size`
  • Loading branch information
iomaganaris authored Sep 12, 2023
1 parent 8af222d commit 0d1ffea
Showing 1 changed file with 3 additions and 40 deletions.
43 changes: 3 additions & 40 deletions src/codegen/codegen_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,50 +536,13 @@ std::string CodegenCppVisitor::breakpoint_current(std::string current) const {


int CodegenCppVisitor::float_variables_size() const {
auto count_length = [](int l, const SymbolType& variable) {
return l += variable->get_length();
};

int float_size = std::accumulate(info.range_parameter_vars.begin(),
info.range_parameter_vars.end(),
0,
count_length);
float_size += std::accumulate(info.range_assigned_vars.begin(),
info.range_assigned_vars.end(),
0,
count_length);
float_size += std::accumulate(info.range_state_vars.begin(),
info.range_state_vars.end(),
0,
count_length);
float_size +=
std::accumulate(info.assigned_vars.begin(), info.assigned_vars.end(), 0, count_length);

/// all state variables for which we add Dstate variables
float_size += std::accumulate(info.state_vars.begin(), info.state_vars.end(), 0, count_length);

/// for v_unused variable
if (info.vectorize) {
float_size++;
}
/// for g_unused variable
if (breakpoint_exist()) {
float_size++;
}
/// for tsave variable
if (net_receive_exist()) {
float_size++;
}
return float_size;
return codegen_float_variables.size();
}


int CodegenCppVisitor::int_variables_size() const {
int num_variables = 0;
for (const auto& semantic: info.semantics) {
num_variables += semantic.size;
}
return num_variables;
const auto count_semantics = [](int sum, const IndexSemantics& sem) { return sum += sem.size; };
return std::accumulate(info.semantics.begin(), info.semantics.end(), 0, count_semantics);
}


Expand Down

0 comments on commit 0d1ffea

Please sign in to comment.