Skip to content

Commit

Permalink
Fixing function declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
iomaganaris committed Dec 4, 2023
1 parent 6abad06 commit 9cf9bd8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 31 deletions.
18 changes: 0 additions & 18 deletions src/codegen/codegen_coreneuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,24 +290,6 @@ bool CodegenCoreneuronCppVisitor::is_constant_variable(const std::string& name)
/* Backend specific routines */
/****************************************************************************************/

std::string CodegenCoreneuronCppVisitor::get_parameter_str(const ParamVector& params) {
std::string str;
bool is_first = true;
for (const auto& param: params) {
if (is_first) {
is_first = false;
} else {
str += ", ";
}
str += fmt::format("{}{} {}{}",
std::get<0>(param),
std::get<1>(param),
std::get<2>(param),
std::get<3>(param));
}
return str;
}


void CodegenCoreneuronCppVisitor::print_deriv_advance_flag_transfer_to_device() const {
// backend specific, do nothing
Expand Down
12 changes: 0 additions & 12 deletions src/codegen/codegen_coreneuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,6 @@ class CodegenCoreneuronCppVisitor: public CodegenCppVisitor {
/****************************************************************************************/


/**
* Generate the string representing the procedure parameter declaration
*
* The procedure parameters are stored in a vector of 4-tuples each representing a parameter.
*
* \param params The parameters that should be concatenated into the function parameter
* declaration
* \return The string representing the declaration of function parameters
*/
static std::string get_parameter_str(const ParamVector& params);


/**
* Print the code to copy derivative advance flag to device
*/
Expand Down
19 changes: 19 additions & 0 deletions src/codegen/codegen_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ using symtab::syminfo::NmodlType;
/****************************************************************************************/


std::string CodegenCppVisitor::get_parameter_str(const ParamVector& params) {
std::string str;
bool is_first = true;
for (const auto& param: params) {
if (is_first) {
is_first = false;
} else {
str += ", ";
}
str += fmt::format("{}{} {}{}",
std::get<0>(param),
std::get<1>(param),
std::get<2>(param),
std::get<3>(param));
}
return str;
}


template <typename T>
bool CodegenCppVisitor::has_parameter_of_name(const T& node, const std::string& name) {
auto parameters = node->get_parameters();
Expand Down
12 changes: 12 additions & 0 deletions src/codegen/codegen_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,18 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor {
/****************************************************************************************/


/**
* Generate the string representing the procedure parameter declaration
*
* The procedure parameters are stored in a vector of 4-tuples each representing a parameter.
*
* \param params The parameters that should be concatenated into the function parameter
* declaration
* \return The string representing the declaration of function parameters
*/
static std::string get_parameter_str(const ParamVector& params);


/**
* Check if function or procedure node has parameter with given name
*
Expand Down
5 changes: 4 additions & 1 deletion src/codegen/codegen_neuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,10 @@ void CodegenNeuronCppVisitor::print_function_declaration(const T& node, const st

/// TODO: Edit for NEURON
printer->add_indent();
printer->fmt_text("inline {} {}({})", return_type, method_name(name), "params");
printer->fmt_text("inline {} {}({})",
return_type,
method_name(name),
get_parameter_str(internal_params));

enable_variable_name_lookup = true;
}
Expand Down

0 comments on commit 9cf9bd8

Please sign in to comment.