From d0f23f83ec4868eb5c5d8562ee64c42317738cf3 Mon Sep 17 00:00:00 2001 From: Matthias Wolf Date: Mon, 15 Jul 2024 11:39:42 +0200 Subject: [PATCH 1/7] Don't include solver headers verbatim. This first version will create a `solver` directory to contain the same structure of `newton/newton.hpp` and `crout/crout.hpp` as present in the NMODL sources. *By default, NMODL will create the solver headers in the output directory.* There are two new arguments to the NMODL invocation: * `--dump-solvers ` will dump the `solver/*/*.hpp` files into the specified directory. * `--no-dump-solvers` will keep a regular NMODL from creating the solver headers. --- .../codegen_coreneuron_cpp_visitor.cpp | 5 +- src/codegen/codegen_neuron_cpp_visitor.cpp | 3 +- src/main.cpp | 61 ++++++++++++++++++- src/solver/CMakeLists.txt | 8 +-- src/solver/newton/newton.hpp | 2 +- src/solver/solver.hpp.inc | 3 +- 6 files changed, 67 insertions(+), 15 deletions(-) diff --git a/src/codegen/codegen_coreneuron_cpp_visitor.cpp b/src/codegen/codegen_coreneuron_cpp_visitor.cpp index b477a58912..490f047625 100644 --- a/src/codegen/codegen_coreneuron_cpp_visitor.cpp +++ b/src/codegen/codegen_coreneuron_cpp_visitor.cpp @@ -21,7 +21,6 @@ #include "config/config.h" #include "lexer/token_mapping.hpp" #include "parser/c11_driver.hpp" -#include "solver/solver.hpp" #include "utils/logger.hpp" #include "utils/string_utils.hpp" #include "visitors/defuse_analyze_visitor.hpp" @@ -1005,7 +1004,7 @@ void CodegenCoreneuronCppVisitor::print_coreneuron_includes() { #include )CODE"); if (info.eigen_newton_solver_exist) { - printer->add_multi_line(nmodl::solvers::newton_hpp); + printer->add_line("#include \"solver/newton/newton.hpp\""); } if (info.eigen_linear_solver_exist) { if (std::accumulate(info.state_vars.begin(), @@ -1014,7 +1013,7 @@ void CodegenCoreneuronCppVisitor::print_coreneuron_includes() { [](int l, const SymbolType& variable) { return l += variable->get_length(); }) > 4) { - printer->add_multi_line(nmodl::solvers::crout_hpp); + printer->add_line("#include \"solver/crout/crout.hpp\""); } else { printer->add_line("#include "); printer->add_line("#include "); diff --git a/src/codegen/codegen_neuron_cpp_visitor.cpp b/src/codegen/codegen_neuron_cpp_visitor.cpp index 3ee0053610..f049cdba90 100644 --- a/src/codegen/codegen_neuron_cpp_visitor.cpp +++ b/src/codegen/codegen_neuron_cpp_visitor.cpp @@ -20,7 +20,6 @@ #include "codegen/codegen_utils.hpp" #include "codegen_naming.hpp" #include "config/config.h" -#include "solver/solver.hpp" #include "utils/string_utils.hpp" #include "visitors/rename_visitor.hpp" #include "visitors/var_usage_visitor.hpp" @@ -754,7 +753,7 @@ void CodegenNeuronCppVisitor::print_standard_includes() { #include )CODE"); if (info.eigen_newton_solver_exist) { - printer->add_multi_line(nmodl::solvers::newton_hpp); + printer->add_line("#include \"solver/newton/newton.hpp\""); } } diff --git a/src/main.cpp b/src/main.cpp index be322c0e99..5253db7799 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,11 +5,12 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include +#include #include #include #include -#include #include "ast/program.hpp" #include "codegen/codegen_acc_visitor.hpp" @@ -20,6 +21,7 @@ #include "config/config.h" #include "parser/nmodl_driver.hpp" #include "pybind/pyembed.hpp" +#include "solver/solver.hpp" #include "utils/common_utils.hpp" #include "utils/logger.hpp" #include "visitors/after_cvode_to_cnexp_visitor.hpp" @@ -60,6 +62,40 @@ using namespace codegen; using namespace visitor; using nmodl::parser::NmodlDriver; +std::pair get_solver_paths(const fs::path& directory) { + return { + directory / "solver" / "crout" / "crout.hpp", + directory / "solver" / "newton" / "newton.hpp" + }; +} + +bool check_solvers(const std::string& directory) { + auto [crout_path, newton_path] = get_solver_paths(directory); + + return fs::exists(crout_path) && fs::exists(newton_path); +} + +void dump_solvers(const std::string& directory) { + fs::path output(directory); + + auto [crout_path, newton_path] = get_solver_paths(directory); + + fs::create_directories(crout_path.parent_path()); + fs::create_directories(newton_path.parent_path()); + + { + std::fstream fcrout(crout_path); + fcrout << nmodl::solver::crout_hpp; + logger->info("Generated {}", crout_path.string()); + } + + { + std::fstream fnewton(newton_path); + fnewton << nmodl::solver::newton_hpp; + logger->info("Generated {}", newton_path.string()); + } +} + // NOLINTNEXTLINE(readability-function-cognitive-complexity) int main(int argc, const char* argv[]) { CLI::App app{fmt::format("NMODL : Source-to-Source Code Generation Framework [{}]", @@ -135,6 +171,9 @@ int main(int argc, const char* argv[]) { /// true if ion variable copies should be avoided bool optimize_ionvar_copies_codegen(false); + /// true if we should not generate the solver headers + bool skip_dump_solvers(false); + /// directory where code will be generated std::string output_dir("."); @@ -172,6 +211,15 @@ int main(int argc, const char* argv[]) { ->ignore_case() ->check(CLI::IsMember({"trace", "debug", "info", "warning", "error", "critical", "off"})); + app.add_option_function( + "--dump-solvers", + [](const std::string& directory) { + dump_solvers(directory); + exit(0); + }, + "Create solver headers in directory and exit"); + app.add_flag("--no-dump-solvers", skip_dump_solvers, "Skip generating solvers if not present"); + app.add_option("file", mod_files, "One or more MOD files to process") ->ignore_case() ->required() @@ -302,6 +350,17 @@ int main(int argc, const char* argv[]) { } }; + if (skip_dump_solvers) { + if (! check_solvers(output_dir)) { + logger->error("Solvers not found in output directory. Please use --dump-solvers first"); + } + } else { + // Unconditionally update the solver files to ensure that they are compatible with + // the current NMODL version. + dump_solvers(output_dir); + } + + for (const auto& file: mod_files) { logger->info("Processing {}", file.string()); diff --git a/src/solver/CMakeLists.txt b/src/solver/CMakeLists.txt index cbb40784f2..fbf9c92366 100644 --- a/src/solver/CMakeLists.txt +++ b/src/solver/CMakeLists.txt @@ -1,10 +1,6 @@ # Read headers, remove everything up to and including "#pragma once", then remove header includes. -file(READ ${CMAKE_CURRENT_SOURCE_DIR}/crout/crout.hpp NMODL_CROUT_HPP_RAW) -string(REGEX REPLACE ".*#pragma once[ \t\r\n]*" "" NMODL_CROUT_HPP "${NMODL_CROUT_HPP_RAW}") -file(READ ${CMAKE_CURRENT_SOURCE_DIR}/newton/newton.hpp NMODL_NEWTON_HPP_RAW) -string(REGEX REPLACE ".*#pragma once[ \t\r\n]*" "" NMODL_NEWTON_HPP_TMP "${NMODL_NEWTON_HPP_RAW}") -string(REGEX REPLACE "#include [ \t\r\n]*" "" NMODL_NEWTON_HPP - "${NMODL_NEWTON_HPP_TMP}") +file(READ ${CMAKE_CURRENT_SOURCE_DIR}/crout/crout.hpp NMODL_CROUT_HPP) +file(READ ${CMAKE_CURRENT_SOURCE_DIR}/newton/newton.hpp NMODL_NEWTON_HPP) set_property( DIRECTORY APPEND diff --git a/src/solver/newton/newton.hpp b/src/solver/newton/newton.hpp index 973b4cd332..15d52f2096 100644 --- a/src/solver/newton/newton.hpp +++ b/src/solver/newton/newton.hpp @@ -15,7 +15,7 @@ * \brief Implementation of Newton method for solving system of non-linear equations */ -#include +#include "../crout/crout.hpp" #include #include diff --git a/src/solver/solver.hpp.inc b/src/solver/solver.hpp.inc index a73c8ee40d..ab0c2c6d2f 100644 --- a/src/solver/solver.hpp.inc +++ b/src/solver/solver.hpp.inc @@ -8,12 +8,11 @@ // However, because we want to be able to test the headers separately we can't // move them here. -namespace nmodl::solvers { +namespace nmodl::solver { const std::string crout_hpp = R"jiowi( @NMODL_CROUT_HPP@ )jiowi"; const std::string newton_hpp = R"jiowi( -@NMODL_CROUT_HPP@ @NMODL_NEWTON_HPP@ )jiowi"; From f673c802666bbfbc2c7f07ef7e134824128d87ac Mon Sep 17 00:00:00 2001 From: Matthias Wolf Date: Tue, 16 Jul 2024 11:14:43 +0200 Subject: [PATCH 2/7] Reorganize a wee bit. --- src/main.cpp | 62 +++++++++++++++++++-------------------- src/solver/solver.hpp.inc | 20 +++++++++---- 2 files changed, 44 insertions(+), 38 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5253db7799..bcdb5e054c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -62,37 +62,32 @@ using namespace codegen; using namespace visitor; using nmodl::parser::NmodlDriver; -std::pair get_solver_paths(const fs::path& directory) { - return { - directory / "solver" / "crout" / "crout.hpp", - directory / "solver" / "newton" / "newton.hpp" - }; +fs::path get_solver_path(const fs::path& directory, const std::string& solver) { + auto path = directory / "solver" / solver/ solver; + path += ".hpp"; + return path; } bool check_solvers(const std::string& directory) { - auto [crout_path, newton_path] = get_solver_paths(directory); - - return fs::exists(crout_path) && fs::exists(newton_path); + for (const auto& solver: nmodl::solver::get_names()) { + const auto& path = get_solver_path(directory, solver); + if (!fs::exists(path)) { + return false; + } + } + return true; } -void dump_solvers(const std::string& directory) { +void dump_solvers(const std::string& directory, const std::vector& solvers = nmodl::solver::get_names()) { fs::path output(directory); - auto [crout_path, newton_path] = get_solver_paths(directory); - - fs::create_directories(crout_path.parent_path()); - fs::create_directories(newton_path.parent_path()); + for (const auto& solver: solvers) { + const auto& path = get_solver_path(directory, solver); + fs::create_directories(path.parent_path()); - { - std::fstream fcrout(crout_path); - fcrout << nmodl::solver::crout_hpp; - logger->info("Generated {}", crout_path.string()); - } - - { - std::fstream fnewton(newton_path); - fnewton << nmodl::solver::newton_hpp; - logger->info("Generated {}", newton_path.string()); + std::ofstream fout(path); + fout << nmodl::solver::get_hpp(solver); + logger->info("Generated {}", path.string()); } } @@ -211,15 +206,6 @@ int main(int argc, const char* argv[]) { ->ignore_case() ->check(CLI::IsMember({"trace", "debug", "info", "warning", "error", "critical", "off"})); - app.add_option_function( - "--dump-solvers", - [](const std::string& directory) { - dump_solvers(directory); - exit(0); - }, - "Create solver headers in directory and exit"); - app.add_flag("--no-dump-solvers", skip_dump_solvers, "Skip generating solvers if not present"); - app.add_option("file", mod_files, "One or more MOD files to process") ->ignore_case() ->required() @@ -228,6 +214,18 @@ int main(int argc, const char* argv[]) { app.add_option("-o,--output", output_dir, "Directory for backend code output") ->capture_default_str() ->ignore_case(); + + app.add_option_function>( + "--dump-solvers", + [&](const std::vector& solvers) { + dump_solvers(output_dir, solvers); + exit(0); + }, + "Create solver headers in directory and exit") + ->expected(1, 2) + ->check(CLI::IsMember(nmodl::solver::get_names())); + + app.add_flag("--no-dump-solvers", skip_dump_solvers, "Skip generating solvers if not present"); app.add_option("--scratch", scratch_dir, "Directory for intermediate code output") ->capture_default_str() ->ignore_case(); diff --git a/src/solver/solver.hpp.inc b/src/solver/solver.hpp.inc index ab0c2c6d2f..dc0f6757d2 100644 --- a/src/solver/solver.hpp.inc +++ b/src/solver/solver.hpp.inc @@ -1,4 +1,5 @@ #include +#include // This file is generated from `crout/crout.hpp` and `newton/newton.hpp`. // @@ -9,11 +10,18 @@ // move them here. namespace nmodl::solver { -const std::string crout_hpp = R"jiowi( -@NMODL_CROUT_HPP@ -)jiowi"; -const std::string newton_hpp = R"jiowi( -@NMODL_NEWTON_HPP@ -)jiowi"; +const std::vector get_names() { + return {"crout", "newton"}; +} + +const std::string get_hpp(const std::string& solver) { + if (solver == "crout") { + return R"jiowi(@NMODL_CROUT_HPP@)jiowi"; + } else if (solver == "newton") { + return R"jiowi(@NMODL_NEWTON_HPP@)jiowi"; + } else { + throw std::runtime_error("unknown solver '" + solver + "'"); + } +}; } From 338189686e01e09322693e1ffc1b090359c8e8ba Mon Sep 17 00:00:00 2001 From: Matthias Wolf Date: Tue, 16 Jul 2024 13:18:34 +0200 Subject: [PATCH 3/7] Simplify structure to appease GNU Make capabilities. --- src/codegen/codegen_coreneuron_cpp_visitor.cpp | 4 ++-- src/codegen/codegen_neuron_cpp_visitor.cpp | 2 +- src/language/code_generator.cmake | 17 ----------------- src/main.cpp | 2 +- src/solver/CMakeLists.txt | 8 ++++---- src/solver/{crout => }/crout.hpp | 0 src/solver/{newton => }/newton.hpp | 2 +- test/unit/newton/newton.cpp | 2 +- 8 files changed, 10 insertions(+), 27 deletions(-) rename src/solver/{crout => }/crout.hpp (100%) rename src/solver/{newton => }/newton.hpp (99%) diff --git a/src/codegen/codegen_coreneuron_cpp_visitor.cpp b/src/codegen/codegen_coreneuron_cpp_visitor.cpp index 490f047625..4304d5dec4 100644 --- a/src/codegen/codegen_coreneuron_cpp_visitor.cpp +++ b/src/codegen/codegen_coreneuron_cpp_visitor.cpp @@ -1004,7 +1004,7 @@ void CodegenCoreneuronCppVisitor::print_coreneuron_includes() { #include )CODE"); if (info.eigen_newton_solver_exist) { - printer->add_line("#include \"solver/newton/newton.hpp\""); + printer->add_line("#include \"solver/newton.hpp\""); } if (info.eigen_linear_solver_exist) { if (std::accumulate(info.state_vars.begin(), @@ -1013,7 +1013,7 @@ void CodegenCoreneuronCppVisitor::print_coreneuron_includes() { [](int l, const SymbolType& variable) { return l += variable->get_length(); }) > 4) { - printer->add_line("#include \"solver/crout/crout.hpp\""); + printer->add_line("#include \"solver/crout.hpp\""); } else { printer->add_line("#include "); printer->add_line("#include "); diff --git a/src/codegen/codegen_neuron_cpp_visitor.cpp b/src/codegen/codegen_neuron_cpp_visitor.cpp index f049cdba90..d09d4adcb4 100644 --- a/src/codegen/codegen_neuron_cpp_visitor.cpp +++ b/src/codegen/codegen_neuron_cpp_visitor.cpp @@ -753,7 +753,7 @@ void CodegenNeuronCppVisitor::print_standard_includes() { #include )CODE"); if (info.eigen_newton_solver_exist) { - printer->add_line("#include \"solver/newton/newton.hpp\""); + printer->add_line("#include \"solver/newton.hpp\""); } } diff --git a/src/language/code_generator.cmake b/src/language/code_generator.cmake index a3dea0767f..1cf626fe82 100644 --- a/src/language/code_generator.cmake +++ b/src/language/code_generator.cmake @@ -10,12 +10,6 @@ set(CODE_GENERATOR_JINJA_FILES ${PROJECT_SOURCE_DIR}/src/language/templates/ast/ast_decl.hpp ${PROJECT_SOURCE_DIR}/src/language/templates/ast/node.hpp ${PROJECT_SOURCE_DIR}/src/language/templates/ast/node_class.template - ${PROJECT_SOURCE_DIR}/src/language/templates/pybind/pyast.cpp - ${PROJECT_SOURCE_DIR}/src/language/templates/pybind/pyast.hpp - ${PROJECT_SOURCE_DIR}/src/language/templates/pybind/pynode.cpp - ${PROJECT_SOURCE_DIR}/src/language/templates/pybind/pysymtab.cpp - ${PROJECT_SOURCE_DIR}/src/language/templates/pybind/pyvisitor.cpp - ${PROJECT_SOURCE_DIR}/src/language/templates/pybind/pyvisitor.hpp ${PROJECT_SOURCE_DIR}/src/language/templates/visitors/ast_visitor.cpp ${PROJECT_SOURCE_DIR}/src/language/templates/visitors/ast_visitor.hpp ${PROJECT_SOURCE_DIR}/src/language/templates/visitors/checkparent_visitor.cpp @@ -174,16 +168,6 @@ set(AST_GENERATED_SOURCES ${PROJECT_BINARY_DIR}/src/ast/write_ion_var.hpp ) -set(PYBIND_GENERATED_SOURCES - ${PROJECT_BINARY_DIR}/src/pybind/pyast.cpp - ${PROJECT_BINARY_DIR}/src/pybind/pyast.hpp - ${PROJECT_BINARY_DIR}/src/pybind/pynode_0.cpp - ${PROJECT_BINARY_DIR}/src/pybind/pynode_1.cpp - ${PROJECT_BINARY_DIR}/src/pybind/pysymtab.cpp - ${PROJECT_BINARY_DIR}/src/pybind/pyvisitor.cpp - ${PROJECT_BINARY_DIR}/src/pybind/pyvisitor.hpp -) - set(VISITORS_GENERATED_SOURCES ${PROJECT_BINARY_DIR}/src/visitors/ast_visitor.cpp ${PROJECT_BINARY_DIR}/src/visitors/ast_visitor.hpp @@ -202,7 +186,6 @@ set(VISITORS_GENERATED_SOURCES set(NMODL_GENERATED_SOURCES ${AST_GENERATED_SOURCES} - ${PYBIND_GENERATED_SOURCES} ${VISITORS_GENERATED_SOURCES} ) # cmake-format: on diff --git a/src/main.cpp b/src/main.cpp index bcdb5e054c..f92123d133 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -63,7 +63,7 @@ using namespace visitor; using nmodl::parser::NmodlDriver; fs::path get_solver_path(const fs::path& directory, const std::string& solver) { - auto path = directory / "solver" / solver/ solver; + auto path = directory / "solver" / solver; path += ".hpp"; return path; } diff --git a/src/solver/CMakeLists.txt b/src/solver/CMakeLists.txt index fbf9c92366..3923d0b996 100644 --- a/src/solver/CMakeLists.txt +++ b/src/solver/CMakeLists.txt @@ -1,11 +1,11 @@ # Read headers, remove everything up to and including "#pragma once", then remove header includes. -file(READ ${CMAKE_CURRENT_SOURCE_DIR}/crout/crout.hpp NMODL_CROUT_HPP) -file(READ ${CMAKE_CURRENT_SOURCE_DIR}/newton/newton.hpp NMODL_NEWTON_HPP) +file(READ ${CMAKE_CURRENT_SOURCE_DIR}/crout.hpp NMODL_CROUT_HPP) +file(READ ${CMAKE_CURRENT_SOURCE_DIR}/newton.hpp NMODL_NEWTON_HPP) set_property( DIRECTORY APPEND - PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/crout/crout.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/newton/newton.hpp) + PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/crout.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/newton.hpp) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/solver.hpp.inc ${CMAKE_CURRENT_BINARY_DIR}/solver.hpp) add_custom_target(nmodl_copy_solver_files ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/solver.hpp") diff --git a/src/solver/crout/crout.hpp b/src/solver/crout.hpp similarity index 100% rename from src/solver/crout/crout.hpp rename to src/solver/crout.hpp diff --git a/src/solver/newton/newton.hpp b/src/solver/newton.hpp similarity index 99% rename from src/solver/newton/newton.hpp rename to src/solver/newton.hpp index 15d52f2096..20b14e6492 100644 --- a/src/solver/newton/newton.hpp +++ b/src/solver/newton.hpp @@ -15,7 +15,7 @@ * \brief Implementation of Newton method for solving system of non-linear equations */ -#include "../crout/crout.hpp" +#include "crout.hpp" #include #include diff --git a/test/unit/newton/newton.cpp b/test/unit/newton/newton.cpp index 33f4086980..2560a150f2 100644 --- a/test/unit/newton/newton.cpp +++ b/test/unit/newton/newton.cpp @@ -5,7 +5,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "newton/newton.hpp" +#include "newton.hpp" #include #include From 740fd68ace203ac881e66659060d1f6e8ae324c4 Mon Sep 17 00:00:00 2001 From: Matthias Wolf Date: Tue, 16 Jul 2024 13:39:32 +0200 Subject: [PATCH 4/7] Fix. --- test/unit/crout/crout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/crout/crout.cpp b/test/unit/crout/crout.cpp index cb90e9162e..bb9398ed93 100644 --- a/test/unit/crout/crout.cpp +++ b/test/unit/crout/crout.cpp @@ -5,7 +5,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "crout/crout.hpp" +#include "crout.hpp" #include From 9602f34131482df14887f20754dc4fec38b9f70a Mon Sep 17 00:00:00 2001 From: Matthias Wolf Date: Tue, 16 Jul 2024 14:46:36 +0200 Subject: [PATCH 5/7] Fix automatic CMake changes. --- src/language/code_generator.cmake | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/language/code_generator.cmake b/src/language/code_generator.cmake index 1cf626fe82..a3dea0767f 100644 --- a/src/language/code_generator.cmake +++ b/src/language/code_generator.cmake @@ -10,6 +10,12 @@ set(CODE_GENERATOR_JINJA_FILES ${PROJECT_SOURCE_DIR}/src/language/templates/ast/ast_decl.hpp ${PROJECT_SOURCE_DIR}/src/language/templates/ast/node.hpp ${PROJECT_SOURCE_DIR}/src/language/templates/ast/node_class.template + ${PROJECT_SOURCE_DIR}/src/language/templates/pybind/pyast.cpp + ${PROJECT_SOURCE_DIR}/src/language/templates/pybind/pyast.hpp + ${PROJECT_SOURCE_DIR}/src/language/templates/pybind/pynode.cpp + ${PROJECT_SOURCE_DIR}/src/language/templates/pybind/pysymtab.cpp + ${PROJECT_SOURCE_DIR}/src/language/templates/pybind/pyvisitor.cpp + ${PROJECT_SOURCE_DIR}/src/language/templates/pybind/pyvisitor.hpp ${PROJECT_SOURCE_DIR}/src/language/templates/visitors/ast_visitor.cpp ${PROJECT_SOURCE_DIR}/src/language/templates/visitors/ast_visitor.hpp ${PROJECT_SOURCE_DIR}/src/language/templates/visitors/checkparent_visitor.cpp @@ -168,6 +174,16 @@ set(AST_GENERATED_SOURCES ${PROJECT_BINARY_DIR}/src/ast/write_ion_var.hpp ) +set(PYBIND_GENERATED_SOURCES + ${PROJECT_BINARY_DIR}/src/pybind/pyast.cpp + ${PROJECT_BINARY_DIR}/src/pybind/pyast.hpp + ${PROJECT_BINARY_DIR}/src/pybind/pynode_0.cpp + ${PROJECT_BINARY_DIR}/src/pybind/pynode_1.cpp + ${PROJECT_BINARY_DIR}/src/pybind/pysymtab.cpp + ${PROJECT_BINARY_DIR}/src/pybind/pyvisitor.cpp + ${PROJECT_BINARY_DIR}/src/pybind/pyvisitor.hpp +) + set(VISITORS_GENERATED_SOURCES ${PROJECT_BINARY_DIR}/src/visitors/ast_visitor.cpp ${PROJECT_BINARY_DIR}/src/visitors/ast_visitor.hpp @@ -186,6 +202,7 @@ set(VISITORS_GENERATED_SOURCES set(NMODL_GENERATED_SOURCES ${AST_GENERATED_SOURCES} + ${PYBIND_GENERATED_SOURCES} ${VISITORS_GENERATED_SOURCES} ) # cmake-format: on From a702641349d9708c614398cf57f37a523ae8171c Mon Sep 17 00:00:00 2001 From: Matthias Wolf Date: Tue, 16 Jul 2024 15:59:21 +0200 Subject: [PATCH 6/7] =?UTF-8?q?=E2=9D=84=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f92123d133..43be24d9dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,8 +5,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include #include +#include #include #include @@ -78,7 +78,8 @@ bool check_solvers(const std::string& directory) { return true; } -void dump_solvers(const std::string& directory, const std::vector& solvers = nmodl::solver::get_names()) { +void dump_solvers(const std::string& directory, + const std::vector& solvers = nmodl::solver::get_names()) { fs::path output(directory); for (const auto& solver: solvers) { @@ -216,12 +217,12 @@ int main(int argc, const char* argv[]) { ->ignore_case(); app.add_option_function>( - "--dump-solvers", - [&](const std::vector& solvers) { - dump_solvers(output_dir, solvers); - exit(0); - }, - "Create solver headers in directory and exit") + "--dump-solvers", + [&](const std::vector& solvers) { + dump_solvers(output_dir, solvers); + exit(0); + }, + "Create solver headers in directory and exit") ->expected(1, 2) ->check(CLI::IsMember(nmodl::solver::get_names())); @@ -349,8 +350,9 @@ int main(int argc, const char* argv[]) { }; if (skip_dump_solvers) { - if (! check_solvers(output_dir)) { - logger->error("Solvers not found in output directory. Please use --dump-solvers first"); + if (!check_solvers(output_dir)) { + logger->error( + "Solvers not found in output directory. Please use --dump-solvers first"); } } else { // Unconditionally update the solver files to ensure that they are compatible with From 9d4696a85436df94e71b42162b794be4b19e4e36 Mon Sep 17 00:00:00 2001 From: Matthias Wolf Date: Mon, 22 Jul 2024 09:32:28 +0200 Subject: [PATCH 7/7] Switch over to @1uc's suggestion. --- src/main.cpp | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 43be24d9dd..b9111f29c8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,18 +68,8 @@ fs::path get_solver_path(const fs::path& directory, const std::string& solver) { return path; } -bool check_solvers(const std::string& directory) { - for (const auto& solver: nmodl::solver::get_names()) { - const auto& path = get_solver_path(directory, solver); - if (!fs::exists(path)) { - return false; - } - } - return true; -} - -void dump_solvers(const std::string& directory, - const std::vector& solvers = nmodl::solver::get_names()) { +void write_shared_headers(const std::string& directory, + const std::vector& solvers = nmodl::solver::get_names()) { fs::path output(directory); for (const auto& solver: solvers) { @@ -167,9 +157,6 @@ int main(int argc, const char* argv[]) { /// true if ion variable copies should be avoided bool optimize_ionvar_copies_codegen(false); - /// true if we should not generate the solver headers - bool skip_dump_solvers(false); - /// directory where code will be generated std::string output_dir("."); @@ -217,16 +204,15 @@ int main(int argc, const char* argv[]) { ->ignore_case(); app.add_option_function>( - "--dump-solvers", + "--write-shared-headers", [&](const std::vector& solvers) { - dump_solvers(output_dir, solvers); + write_shared_headers(output_dir, solvers); exit(0); }, "Create solver headers in directory and exit") ->expected(1, 2) ->check(CLI::IsMember(nmodl::solver::get_names())); - app.add_flag("--no-dump-solvers", skip_dump_solvers, "Skip generating solvers if not present"); app.add_option("--scratch", scratch_dir, "Directory for intermediate code output") ->capture_default_str() ->ignore_case(); @@ -349,18 +335,6 @@ int main(int argc, const char* argv[]) { } }; - if (skip_dump_solvers) { - if (!check_solvers(output_dir)) { - logger->error( - "Solvers not found in output directory. Please use --dump-solvers first"); - } - } else { - // Unconditionally update the solver files to ensure that they are compatible with - // the current NMODL version. - dump_solvers(output_dir); - } - - for (const auto& file: mod_files) { logger->info("Processing {}", file.string());