Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation of generated MOD file for NEURON #1101

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/codegen/codegen_coreneuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1258,13 +1258,15 @@ std::string CodegenCoreneuronCppVisitor::process_verbatim_text(std::string const


std::string CodegenCoreneuronCppVisitor::register_mechanism_arguments() const {
auto nrn_channel_info_var_name = get_channel_info_var_name();
auto nrn_cur = nrn_cur_required() ? method_name(naming::NRN_CUR_METHOD) : "nullptr";
auto nrn_state = nrn_state_required() ? method_name(naming::NRN_STATE_METHOD) : "nullptr";
auto nrn_alloc = method_name(naming::NRN_ALLOC_METHOD);
auto nrn_init = method_name(naming::NRN_INIT_METHOD);
auto const nrn_private_constructor = method_name(naming::NRN_PRIVATE_CONSTRUCTOR_METHOD);
auto const nrn_private_destructor = method_name(naming::NRN_PRIVATE_DESTRUCTOR_METHOD);
return fmt::format("mechanism, {}, {}, nullptr, {}, {}, {}, {}, first_pointer_var_index()",
return fmt::format("{}, {}, {}, nullptr, {}, {}, {}, {}, first_pointer_var_index()",
nrn_channel_info_var_name,
nrn_alloc,
nrn_cur,
nrn_state,
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/codegen_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void CodegenCppVisitor::print_mechanism_info() {

printer->add_newline(2);
printer->add_line("/** channel information */");
printer->add_line("static const char *mechanism[] = {");
printer->fmt_line("static const char *{}[] = {{", get_channel_info_var_name());
printer->increase_indent();
printer->add_line(add_escape_quote(nmodl_version()), ",");
printer->add_line(add_escape_quote(info.mod_suffix), ",");
Expand Down
8 changes: 8 additions & 0 deletions src/codegen/codegen_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,14 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor {
return info.electrode_current ? "-=" : "+=";
}

/**
* Name of channel info variable
*
*/
std::string get_channel_info_var_name() const noexcept {
return std::string("mechanism_info");
}


/****************************************************************************************/
/* Common helper routines accross codegen functions */
Expand Down
13 changes: 6 additions & 7 deletions src/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,23 +298,23 @@
/// TODO: Also needs a test
printer->fmt_push_block("for (int _i = 0; _i < {}; ++_i)", prime_var->get_length());
printer->fmt_line("/* {}[{}] */", prime_var->get_name(), prime_var->get_length());
printer->fmt_line("_slist1[{}+_i] = {{{}, _i}}",
printer->fmt_line("_slist1[{}+_i] = {{{}, _i}};",

Check warning on line 301 in src/codegen/codegen_neuron_cpp_visitor.cpp

View check run for this annotation

Codecov / codecov/patch

src/codegen/codegen_neuron_cpp_visitor.cpp#L301

Added line #L301 was not covered by tests
i,
position_of_float_var(prime_var->get_name()));
const auto prime_var_deriv_name = "D" + prime_var->get_name();
printer->fmt_line("/* {}[{}] */", prime_var_deriv_name, prime_var->get_length());
printer->fmt_line("_dlist1[{}+_i] = {{{}, _i}}",
printer->fmt_line("_dlist1[{}+_i] = {{{}, _i}};",

Check warning on line 306 in src/codegen/codegen_neuron_cpp_visitor.cpp

View check run for this annotation

Codecov / codecov/patch

src/codegen/codegen_neuron_cpp_visitor.cpp#L306

Added line #L306 was not covered by tests
i,
position_of_float_var(prime_var_deriv_name));
printer->pop_block();
} else {
printer->fmt_line("/* {} */", prime_var->get_name());
printer->fmt_line("_slist1[{}] = {{{}, 0}}",
printer->fmt_line("_slist1[{}] = {{{}, 0}};",
i,
position_of_float_var(prime_var->get_name()));
const auto prime_var_deriv_name = "D" + prime_var->get_name();
printer->fmt_line("/* {} */", prime_var_deriv_name);
printer->fmt_line("_dlist1[{}] = {{{}, 0}}",
printer->fmt_line("_dlist1[{}] = {{{}, 0}};",
i,
position_of_float_var(prime_var_deriv_name));
}
Expand Down Expand Up @@ -391,12 +391,11 @@
printer->fmt_push_block("void _{}_reg()", info.mod_file);
print_sdlists_init(true);
// type related information
auto suffix = add_escape_quote(info.mod_suffix);
printer->add_newline();
printer->fmt_line("int mech_type = nrn_get_mechtype({});", suffix);
printer->fmt_line("int mech_type = nrn_get_mechtype({}[1]);", get_channel_info_var_name());

// More things to add here
printer->add_line("_nrn_mechanism_register_data_fields(_mechtype,");
printer->add_line("_nrn_mechanism_register_data_fields(mech_type,");
printer->increase_indent();
const auto codegen_float_variables_size = codegen_float_variables.size();
for (int i = 0; i < codegen_float_variables_size; ++i) {
Expand Down
10 changes: 5 additions & 5 deletions test/unit/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void _nrn_mechanism_register_data_fields(Args&&... args) {
}
THEN("Correct channel information are printed") {
std::string expected_channel_info = R"(/** channel information */
static const char *mechanism[] = {
static const char *mechanism_info[] = {
"6.2.0",
"pas_test",
"g_pas_test",
Expand Down Expand Up @@ -228,12 +228,12 @@ void _nrn_mechanism_register_data_fields(Args&&... args) {
std::string expected_placeholder_reg = R"(/** register channel with the simulator */
void __test_reg() {
/* s */
_slist1[0] = {4, 0}
_slist1[0] = {4, 0};
/* Ds */
_dlist1[0] = {7, 0}
_dlist1[0] = {7, 0};

int mech_type = nrn_get_mechtype("pas_test");
_nrn_mechanism_register_data_fields(_mechtype,
int mech_type = nrn_get_mechtype(mechanism_info[1]);
_nrn_mechanism_register_data_fields(mech_type,
_nrn_mechanism_field<double>{"g"} /* 0 */,
_nrn_mechanism_field<double>{"e"} /* 1 */,
_nrn_mechanism_field<double>{"i"} /* 2 */,
Expand Down
Loading