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

Stubs of nrn_{alloc,init,jacob,cur,state}. #1103

Closed
wants to merge 5 commits into from
Closed
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
3 changes: 3 additions & 0 deletions src/codegen/codegen_naming.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ inline constexpr char NRN_PRIVATE_DESTRUCTOR_METHOD[] = "nrn_private_destructor"
/// nrn_alloc method in generated code
static constexpr char NRN_ALLOC_METHOD[] = "nrn_alloc";

/// nrn_jacob method in generated code
static constexpr char NRN_JACOB_METHOD[] = "nrn_jacob";

/// nrn_state method in generated code
static constexpr char NRN_STATE_METHOD[] = "nrn_state";

Expand Down
28 changes: 25 additions & 3 deletions src/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <regex>

#include "ast/all.hpp"
#include "codegen/codegen_naming.hpp"
#include "codegen/codegen_utils.hpp"
#include "config/config.h"
#include "utils/string_utils.hpp"
Expand Down Expand Up @@ -453,6 +454,17 @@ void CodegenNeuronCppVisitor::print_global_function_common_code(BlockType type,
return;
}

void CodegenNeuronCppVisitor::print_nrn_init() {
printer->fmt_line("void {}(_nrn_model_sorted_token const&, NrnThread*, Memb_list*, int) {{}}",
method_name(naming::NRN_INIT_METHOD));
}

void CodegenNeuronCppVisitor::print_nrn_jacob() {
printer->fmt_line(
"void {}(_nrn_model_sorted_token const&, NrnThread* _nt, Memb_list* _ml_arg, int "
"_type) {{}}",
method_name(naming::NRN_JACOB_METHOD));
}

/// TODO: Edit for NEURON
void CodegenNeuronCppVisitor::print_nrn_constructor() {
Expand All @@ -468,7 +480,7 @@ void CodegenNeuronCppVisitor::print_nrn_destructor() {

/// TODO: Print the equivalent of `nrn_alloc_<mech_name>`
void CodegenNeuronCppVisitor::print_nrn_alloc() {
return;
printer->fmt_line("void {}(Prop*) {{}}", method_name(naming::NRN_ALLOC_METHOD));
}


Expand All @@ -484,7 +496,11 @@ void CodegenNeuronCppVisitor::print_nrn_state() {
}
codegen = true;

printer->add_line("void nrn_state() {}");
printer->fmt_line(
"static void {}(_nrn_model_sorted_token const& _sorted_token, NrnThread* nt, Memb_list* "
"ml, int type) {{}}",
method_name(naming::NRN_STATE_METHOD));

/// TODO: Fill in

codegen = false;
Expand Down Expand Up @@ -534,7 +550,10 @@ void CodegenNeuronCppVisitor::print_nrn_cur() {

codegen = true;

printer->add_line("void nrn_cur() {}");
printer->add_line(
"void {}(_nrn_model_sorted_token const& sorted_token, NrnThread* nt, Memb_list* ml, "
"int type) {{}}",
method_name(naming::NRN_CUR_METHOD));
/// TODO: Fill in

codegen = false;
Expand Down Expand Up @@ -643,6 +662,7 @@ void CodegenNeuronCppVisitor::print_g_unused() const {
void CodegenNeuronCppVisitor::print_compute_functions() {
print_nrn_cur();
print_nrn_state();
print_nrn_jacob();
}


Expand All @@ -658,6 +678,8 @@ void CodegenNeuronCppVisitor::print_codegen_routines() {
print_mechanism_info();
print_data_structures(true);
print_global_variables_for_hoc();
print_nrn_init();
print_nrn_alloc();
print_compute_functions(); // only nrn_cur and nrn_state
print_mechanism_register();
print_namespace_end();
Expand Down
11 changes: 11 additions & 0 deletions src/codegen/codegen_neuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,17 @@ class CodegenNeuronCppVisitor: public CodegenCppVisitor {
virtual void print_global_function_common_code(BlockType type,
const std::string& function_name = "") override;

/**
* Print nrn_init function definition
*
*/
void print_nrn_init();

/**
* Print nrn_init function definition
*
*/
void print_nrn_jacob();

/**
* Print nrn_constructor function definition
Expand Down
24 changes: 16 additions & 8 deletions test/unit/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,24 @@ void _nrn_mechanism_register_data_fields(Args&&... args) {
ContainsSubstring(reindent_and_trim_text(expected_hoc_global_variables)));
}
THEN("Placeholder nrn_cur function is printed") {
std::string expected_placeholder_nrn_cur = R"(void nrn_cur() {})";

REQUIRE_THAT(generated,
ContainsSubstring(reindent_and_trim_text(expected_placeholder_nrn_cur)));
std::string expected = R"(void nrn_cur()";
REQUIRE_THAT(generated, ContainsSubstring(reindent_and_trim_text(expected)));
}
THEN("Placeholder nrn_state function is printed") {
std::string expected_placeholder_nrn_state = R"(void nrn_state() {})";

REQUIRE_THAT(generated,
ContainsSubstring(reindent_and_trim_text(expected_placeholder_nrn_state)));
std::string expected = R"(void nrn_state()";
REQUIRE_THAT(generated, ContainsSubstring(reindent_and_trim_text(expected)));
}
THEN("Placeholder nrn_jacob function is printed") {
std::string expected = R"(void nrn_jacob()";
REQUIRE_THAT(generated, ContainsSubstring(reindent_and_trim_text(expected)));
}
THEN("Placeholder nrn_init function is printed") {
std::string expected = R"(void nrn_init()";
REQUIRE_THAT(generated, ContainsSubstring(reindent_and_trim_text(expected)));
}
THEN("Placeholder nrn_alloc function is printed") {
std::string expected = R"(void nrn_alloc()";
REQUIRE_THAT(generated, ContainsSubstring(reindent_and_trim_text(expected)));
}
THEN("Placeholder registration function is printed") {
std::string expected_placeholder_reg = R"(/** register channel with the simulator */
Expand Down
Loading