From 4b3cfcfaadc2f31c21f1c8f486a7fc7c164a81d3 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Fri, 1 Dec 2023 11:00:22 +0100 Subject: [PATCH 1/5] Stubs of `nrn_{alloc,init,jacob,cur,state}`. --- src/codegen/codegen_neuron_cpp_visitor.cpp | 14 ++++++++++++-- src/codegen/codegen_neuron_cpp_visitor.hpp | 11 +++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/codegen/codegen_neuron_cpp_visitor.cpp b/src/codegen/codegen_neuron_cpp_visitor.cpp index f4b3747ce0..ccda553d42 100644 --- a/src/codegen/codegen_neuron_cpp_visitor.cpp +++ b/src/codegen/codegen_neuron_cpp_visitor.cpp @@ -453,6 +453,13 @@ void CodegenNeuronCppVisitor::print_global_function_common_code(BlockType type, return; } +void CodegenNeuronCppVisitor::print_nrn_init() { + printer->add_line("void nrn_init(_nrn_model_sorted_token const&, NrnThread*, Memb_list*, int) {}"); +} + +void CodegenNeuronCppVisitor::print_nrn_jacob() { + printer->add_line("void nrn_jacob(_nrn_model_sorted_token const&, NrnThread* _nt, Memb_list* _ml_arg, int _type) {}"); +} /// TODO: Edit for NEURON void CodegenNeuronCppVisitor::print_nrn_constructor() { @@ -468,6 +475,7 @@ void CodegenNeuronCppVisitor::print_nrn_destructor() { /// TODO: Print the equivalent of `nrn_alloc_` void CodegenNeuronCppVisitor::print_nrn_alloc() { + printer->add_line("void nrn_alloc(Prop*) {}"); return; } @@ -484,7 +492,7 @@ void CodegenNeuronCppVisitor::print_nrn_state() { } codegen = true; - printer->add_line("void nrn_state() {}"); + printer->add_line("void nrn_state(_nrn_model_sorted_token const& sorted_token, NrnThread* nt, Memb_list* ml, int type) {}"); /// TODO: Fill in codegen = false; @@ -534,7 +542,7 @@ void CodegenNeuronCppVisitor::print_nrn_cur() { codegen = true; - printer->add_line("void nrn_cur() {}"); + printer->add_line("void nrn_cur(_nrn_model_sorted_token const& sorted_token, NrnThread* nt, Memb_list* ml, int type) {}"); /// TODO: Fill in codegen = false; @@ -641,8 +649,10 @@ void CodegenNeuronCppVisitor::print_g_unused() const { /// TODO: Edit for NEURON void CodegenNeuronCppVisitor::print_compute_functions() { + print_nrn_init(); print_nrn_cur(); print_nrn_state(); + print_nrn_jacob(); } diff --git a/src/codegen/codegen_neuron_cpp_visitor.hpp b/src/codegen/codegen_neuron_cpp_visitor.hpp index e8bf7e36af..56387e4ffa 100644 --- a/src/codegen/codegen_neuron_cpp_visitor.hpp +++ b/src/codegen/codegen_neuron_cpp_visitor.hpp @@ -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 From 0fff43896f4ef74680a01caf29577dde74d616a8 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Fri, 1 Dec 2023 15:18:52 +0100 Subject: [PATCH 2/5] whitespace --- src/codegen/codegen_neuron_cpp_visitor.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/codegen/codegen_neuron_cpp_visitor.cpp b/src/codegen/codegen_neuron_cpp_visitor.cpp index ccda553d42..63bf728bc7 100644 --- a/src/codegen/codegen_neuron_cpp_visitor.cpp +++ b/src/codegen/codegen_neuron_cpp_visitor.cpp @@ -454,11 +454,14 @@ void CodegenNeuronCppVisitor::print_global_function_common_code(BlockType type, } void CodegenNeuronCppVisitor::print_nrn_init() { - printer->add_line("void nrn_init(_nrn_model_sorted_token const&, NrnThread*, Memb_list*, int) {}"); + printer->add_line( + "void nrn_init(_nrn_model_sorted_token const&, NrnThread*, Memb_list*, int) {}"); } void CodegenNeuronCppVisitor::print_nrn_jacob() { - printer->add_line("void nrn_jacob(_nrn_model_sorted_token const&, NrnThread* _nt, Memb_list* _ml_arg, int _type) {}"); + printer->add_line( + "void nrn_jacob(_nrn_model_sorted_token const&, NrnThread* _nt, Memb_list* _ml_arg, int " + "_type) {}"); } /// TODO: Edit for NEURON @@ -492,7 +495,9 @@ void CodegenNeuronCppVisitor::print_nrn_state() { } codegen = true; - printer->add_line("void nrn_state(_nrn_model_sorted_token const& sorted_token, NrnThread* nt, Memb_list* ml, int type) {}"); + printer->add_line( + "void nrn_state(_nrn_model_sorted_token const& sorted_token, NrnThread* nt, Memb_list* ml, " + "int type) {}"); /// TODO: Fill in codegen = false; @@ -542,7 +547,9 @@ void CodegenNeuronCppVisitor::print_nrn_cur() { codegen = true; - printer->add_line("void nrn_cur(_nrn_model_sorted_token const& sorted_token, NrnThread* nt, Memb_list* ml, int type) {}"); + printer->add_line( + "void nrn_cur(_nrn_model_sorted_token const& sorted_token, NrnThread* nt, Memb_list* ml, " + "int type) {}"); /// TODO: Fill in codegen = false; From 852cc1e0c11cc3360e026f6d411701e98123914e Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Fri, 1 Dec 2023 15:31:11 +0100 Subject: [PATCH 3/5] Update tests. --- .../codegen/codegen_neuron_cpp_visitor.cpp | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/test/unit/codegen/codegen_neuron_cpp_visitor.cpp b/test/unit/codegen/codegen_neuron_cpp_visitor.cpp index 50dbf9ca9c..6f8a373c56 100644 --- a/test/unit/codegen/codegen_neuron_cpp_visitor.cpp +++ b/test/unit/codegen/codegen_neuron_cpp_visitor.cpp @@ -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 */ From 4c4b91da9ecb22ba14bd7d058585eb6cdd770046 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Fri, 1 Dec 2023 15:34:36 +0100 Subject: [PATCH 4/5] missing print --- src/codegen/codegen_neuron_cpp_visitor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/codegen/codegen_neuron_cpp_visitor.cpp b/src/codegen/codegen_neuron_cpp_visitor.cpp index 63bf728bc7..edbb1c322b 100644 --- a/src/codegen/codegen_neuron_cpp_visitor.cpp +++ b/src/codegen/codegen_neuron_cpp_visitor.cpp @@ -657,6 +657,7 @@ void CodegenNeuronCppVisitor::print_g_unused() const { /// TODO: Edit for NEURON void CodegenNeuronCppVisitor::print_compute_functions() { print_nrn_init(); + print_nrn_alloc(); print_nrn_cur(); print_nrn_state(); print_nrn_jacob(); From 97d43f668ab1ce65c4d82836785829637ae4c419 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Fri, 1 Dec 2023 16:18:15 +0100 Subject: [PATCH 5/5] cosmetics. --- src/codegen/codegen_naming.hpp | 3 ++ src/codegen/codegen_neuron_cpp_visitor.cpp | 32 ++++++++++++---------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/codegen/codegen_naming.hpp b/src/codegen/codegen_naming.hpp index 3af8a49e88..5c326e2f8e 100644 --- a/src/codegen/codegen_naming.hpp +++ b/src/codegen/codegen_naming.hpp @@ -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"; diff --git a/src/codegen/codegen_neuron_cpp_visitor.cpp b/src/codegen/codegen_neuron_cpp_visitor.cpp index edbb1c322b..b883b361b5 100644 --- a/src/codegen/codegen_neuron_cpp_visitor.cpp +++ b/src/codegen/codegen_neuron_cpp_visitor.cpp @@ -14,6 +14,7 @@ #include #include "ast/all.hpp" +#include "codegen/codegen_naming.hpp" #include "codegen/codegen_utils.hpp" #include "config/config.h" #include "utils/string_utils.hpp" @@ -454,14 +455,15 @@ void CodegenNeuronCppVisitor::print_global_function_common_code(BlockType type, } void CodegenNeuronCppVisitor::print_nrn_init() { - printer->add_line( - "void nrn_init(_nrn_model_sorted_token const&, NrnThread*, Memb_list*, int) {}"); + 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->add_line( - "void nrn_jacob(_nrn_model_sorted_token const&, NrnThread* _nt, Memb_list* _ml_arg, int " - "_type) {}"); + 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 @@ -478,8 +480,7 @@ void CodegenNeuronCppVisitor::print_nrn_destructor() { /// TODO: Print the equivalent of `nrn_alloc_` void CodegenNeuronCppVisitor::print_nrn_alloc() { - printer->add_line("void nrn_alloc(Prop*) {}"); - return; + printer->fmt_line("void {}(Prop*) {{}}", method_name(naming::NRN_ALLOC_METHOD)); } @@ -495,9 +496,11 @@ void CodegenNeuronCppVisitor::print_nrn_state() { } codegen = true; - printer->add_line( - "void nrn_state(_nrn_model_sorted_token const& sorted_token, NrnThread* nt, Memb_list* ml, " - "int type) {}"); + 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; @@ -548,8 +551,9 @@ void CodegenNeuronCppVisitor::print_nrn_cur() { codegen = true; printer->add_line( - "void nrn_cur(_nrn_model_sorted_token const& sorted_token, NrnThread* nt, Memb_list* ml, " - "int type) {}"); + "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; @@ -656,8 +660,6 @@ void CodegenNeuronCppVisitor::print_g_unused() const { /// TODO: Edit for NEURON void CodegenNeuronCppVisitor::print_compute_functions() { - print_nrn_init(); - print_nrn_alloc(); print_nrn_cur(); print_nrn_state(); print_nrn_jacob(); @@ -676,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();