User Guide
codegen_neuron_cpp_visitor.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Blue Brain Project, EPFL.
3  * See the top-level LICENSE file for details.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #pragma once
9 
10 /**
11  * \dir
12  * \brief Code generation backend implementations for NEURON
13  *
14  * \file
15  * \brief \copybrief nmodl::codegen::CodegenNeuronCppVisitor
16  */
17 
18 #include <algorithm>
19 #include <cmath>
20 #include <ctime>
21 #include <numeric>
22 #include <ostream>
23 #include <string>
24 #include <string_view>
25 #include <utility>
26 
28 #include "codegen/codegen_info.hpp"
30 #include "printer/code_printer.hpp"
31 #include "symtab/symbol_table.hpp"
32 #include "utils/logger.hpp"
33 #include "visitors/ast_visitor.hpp"
34 
35 
36 /// encapsulates code generation backend implementations
37 namespace nmodl {
38 
39 namespace codegen {
40 
41 
42 using printer::CodePrinter;
43 
44 
45 /**
46  * @brief Enum to switch between HOC and Python wrappers for functions and
47  * procedures defined in mechanisms
48  *
49  */
51 
52 
53 /**
54  * \defgroup codegen_backends Codegen Backends
55  * \ingroup codegen
56  * \brief Code generation backends for NEURON
57  * \{
58  */
59 
60 /**
61  * \class CodegenNeuronCppVisitor
62  * \brief %Visitor for printing C++ code compatible with legacy api of NEURON
63  *
64  * \todo
65  * - Handle define statement (i.e. macros)
66  * - If there is a return statement in the verbatim block
67  * of inlined function then it will be error. Need better
68  * error checking. For example, see netstim.mod where we
69  * have removed return from verbatim block.
70  */
72  public:
74 
75  protected:
76  /****************************************************************************************/
77  /* Member variables */
78  /****************************************************************************************/
79 
80 
81  /****************************************************************************************/
82  /* Generic information getters */
83  /****************************************************************************************/
84 
85 
86  /**
87  * Name of the simulator the code was generated for
88  */
89  std::string simulator_name() override;
90 
91 
92  /**
93  * Name of the code generation backend
94  */
95  virtual std::string backend_name() const override;
96 
97 
98  /****************************************************************************************/
99  /* Common helper routines accross codegen functions */
100  /****************************************************************************************/
101 
102 
103  /**
104  * Determine the position in the data array for a given float variable
105  * \param name The name of a float variable
106  * \return The position index in the data array
107  */
108  int position_of_float_var(const std::string& name) const override;
109 
110 
111  /**
112  * Determine the position in the data array for a given int variable
113  * \param name The name of an int variable
114  * \return The position index in the data array
115  */
116  int position_of_int_var(const std::string& name) const override;
117 
118 
119  /****************************************************************************************/
120  /* Backend specific routines */
121  /****************************************************************************************/
122 
123 
124  /**
125  * Print atomic update pragma for reduction statements
126  */
127  virtual void print_atomic_reduction_pragma() override;
128 
129 
130  /**
131  * Check if ion variable copies should be avoided
132  */
133  bool optimize_ion_variable_copies() const override;
134 
135  /****************************************************************************************/
136  /* Printing routines for code generation */
137  /****************************************************************************************/
138 
139 
140  /**
141  * Print call to \c net\_send
142  * \param node The AST node representing the function call
143  */
144  void print_net_send_call(const ast::FunctionCall& node) override;
145 
146 
147  /**
148  * Print call to net\_move
149  * \param node The AST node representing the function call
150  */
151  void print_net_move_call(const ast::FunctionCall& node) override;
152 
153 
154  /**
155  * Print call to net\_event
156  * \param node The AST node representing the function call
157  */
158  void print_net_event_call(const ast::FunctionCall& node) override;
159 
160 
161  /**
162  * Print POINT_PROCESS related functions
163  * Wrap external NEURON functions related to POINT_PROCESS mechanisms
164  *
165  */
167 
168  /**
169  * Print NEURON functions related to setting global variables of the mechanism
170  *
171  */
173 
174 
175  /**
176  * Print function and procedures prototype declaration
177  */
178  void print_function_prototypes() override;
179 
180 
181  /**
182  * Print nmodl function or procedure (common code)
183  * \param node the AST node representing the function or procedure in NMODL
184  * \param name the name of the function or procedure
185  */
186  void print_function_or_procedure(const ast::Block& node, const std::string& name) override;
187 
188 
189  /**
190  * Common helper function to help printing function or procedure blocks
191  * \param node the AST node representing the function or procedure in NMODL
192  */
193  void print_function_procedure_helper(const ast::Block& node) override;
194 
195 
196  /**
197  * Print NMODL procedure in target backend code
198  * \param node
199  */
200  virtual void print_procedure(const ast::ProcedureBlock& node) override;
201 
202 
203  /**
204  * Print NMODL function in target backend code
205  * \param node
206  */
207  void print_function(const ast::FunctionBlock& node) override;
208 
209 
210  void print_hoc_py_wrapper_function_body(const ast::Block* function_or_procedure_block,
211  InterpreterWrapper wrapper_type);
212 
213 
215 
216 
217  /****************************************************************************************/
218  /* Code-specific helper routines */
219  /****************************************************************************************/
220 
221 
222  /**
223  * Arguments for functions that are defined and used internally.
224  * \return the method arguments
225  */
226  std::string internal_method_arguments() override;
227 
228 
229  /**
230  * Parameters for internally defined functions
231  * \return the method parameters
232  */
234 
235 
236  /**
237  * Arguments for external functions called from generated code
238  * \return A string representing the arguments passed to an external function
239  */
240  const char* external_method_arguments() noexcept override;
241 
242 
243  /**
244  * Parameters for functions in generated code that are called back from external code
245  *
246  * Functions registered in NEURON during initialization for callback must adhere to a prescribed
247  * calling convention. This method generates the string representing the function parameters for
248  * these externally called functions.
249  * \param table
250  * \return A string representing the parameters of the function
251  */
252  const char* external_method_parameters(bool table = false) noexcept override;
253 
254 
255  /**
256  * Arguments for "_threadargs_" macro in neuron implementation
257  */
258  std::string nrn_thread_arguments() const override;
259 
260 
261  /**
262  * Arguments for "_threadargs_" macro in neuron implementation
263  */
264  std::string nrn_thread_internal_arguments() override;
265 
266 
267  /**
268  * Process a verbatim block for possible variable renaming
269  * \param text The verbatim code to be processed
270  * \return The code with all variables renamed as needed
271  */
272  std::string process_verbatim_text(std::string const& text) override;
273 
274 
275  /**
276  * Arguments for register_mech or point_register_mech function
277  */
278  std::string register_mechanism_arguments() const override;
279 
280  std::string conc_write_statement(const std::string& ion_name,
281  const std::string& concentration,
282  int index) override;
283 
284  /**
285  * All functions and procedures need a \c _hoc_<func_or_proc_name> to be available to the HOC
286  * interpreter
287  */
288  std::string hoc_function_name(const std::string& function_or_procedure_name) const;
289 
290 
291  /**
292  * Get the signature of the \c _hoc_<func_or_proc_name> function
293  */
294  std::string hoc_function_signature(const std::string& function_or_procedure_name) const;
295 
296 
297  /**
298  * In non POINT_PROCESS mechanisms all functions and procedures need a \c
299  * _py_<func_or_proc_name> to be available to the HOC interpreter
300  */
301  std::string py_function_name(const std::string& function_or_procedure_name) const;
302 
303  /**
304  * Get the signature of the \c _npy_<func_or_proc_name> function
305  */
306  std::string py_function_signature(const std::string& function_or_procedure_name) const;
307 
308 
309  /****************************************************************************************/
310  /* Code-specific printing routines for code generations */
311  /****************************************************************************************/
312 
313 
314  /**
315  * Prints the start of the \c neuron namespace
316  */
317  void print_namespace_start() override;
318 
319 
320  /**
321  * Prints the end of the \c neuron namespace
322  */
323  void print_namespace_stop() override;
324 
325 
326  /****************************************************************************************/
327  /* Routines for returning variable name */
328  /****************************************************************************************/
329 
330 
331  /**
332  * Determine the name of a \c float variable given its symbol
333  *
334  * This function typically returns the accessor expression in backend code for the given symbol.
335  * Since the model variables are stored in data arrays and accessed by offset, this function
336  * will return the C++ string representing the array access at the correct offset
337  *
338  * \param symbol The symbol of a variable for which we want to obtain its name
339  * \param use_instance Should the variable be accessed via instance or data array
340  * \return The backend code string representing the access to the given variable
341  * symbol
342  */
343  std::string float_variable_name(const SymbolType& symbol, bool use_instance) const override;
344 
345 
346  /**
347  * Determine the name of an \c int variable given its symbol
348  *
349  * This function typically returns the accessor expression in backend code for the given symbol.
350  * Since the model variables are stored in data arrays and accessed by offset, this function
351  * will return the C++ string representing the array access at the correct offset
352  *
353  * \param symbol The symbol of a variable for which we want to obtain its name
354  * \param name The name of the index variable
355  * \param use_instance Should the variable be accessed via instance or data array
356  * \return The backend code string representing the access to the given variable
357  * symbol
358  */
359  std::string int_variable_name(const IndexVariableInfo& symbol,
360  const std::string& name,
361  bool use_instance) const override;
362 
363 
364  /**
365  * Determine the variable name for a global variable given its symbol
366  * \param symbol The symbol of a variable for which we want to obtain its name
367  * \param use_instance Should the variable be accessed via the (host-only)
368  * global variable or the instance-specific copy (also available on GPU).
369  * \return The C++ string representing the access to the global variable
370  */
371  std::string global_variable_name(const SymbolType& symbol,
372  bool use_instance = true) const override;
373 
374 
375  /**
376  * Determine variable name in the structure of mechanism properties
377  *
378  * \param name Variable name that is being printed
379  * \param use_instance Should the variable be accessed via instance or data array
380  * \return The C++ string representing the access to the variable in the neuron
381  * thread structure
382  */
383  std::string get_variable_name(const std::string& name, bool use_instance = true) const override;
384 
385 
386  /****************************************************************************************/
387  /* Main printing routines for code generation */
388  /****************************************************************************************/
389 
390 
391  /**
392  * Print top file header printed in generated code
393  */
394  void print_backend_info() override;
395 
396 
397  /**
398  * Print standard C/C++ includes
399  */
400  void print_standard_includes() override;
401 
402 
403  /**
404  * Print includes from NEURON
405  */
406  void print_neuron_includes();
407 
408 
409  void print_sdlists_init(bool print_initializers) override;
410 
411 
412  /**
413  * Print the structure that wraps all global variables used in the NMODL
414  *
415  * \param print_initializers Whether to include default values in the struct
416  * definition (true: int foo{42}; false: int foo;)
417  */
418  void print_mechanism_global_var_structure(bool print_initializers) override;
419 
420 
421  /**
422  * Print byte arrays that register scalar and vector variables for hoc interface
423  *
424  */
425  void print_global_variables_for_hoc() override;
426 
427 
428  /**
429  * Print the mechanism registration function
430  *
431  */
432  void print_mechanism_register() override;
433 
434 
435  /**
436  * Print common code for global functions like nrn_init, nrn_cur and nrn_state
437  * \param type The target backend code block type
438  */
440  const std::string& function_name = "") override;
441 
442 
443  /**
444  * Print the \c nrn\_init function definition
445  * \param skip_init_check \c true to generate code executing the initialization conditionally
446  */
447  void print_nrn_init(bool skip_init_check = true);
448 
449  /** Print the initial block. */
450  void print_initial_block(const ast::InitialBlock* node);
451 
452  /**
453  * Print nrn_constructor function definition
454  *
455  */
456  void print_nrn_constructor() override;
457 
458 
459  /**
460  * Print nrn_destructor function definition
461  *
462  */
463  void print_nrn_destructor() override;
464 
465 
466  /**
467  * Print nrn_alloc function definition
468  *
469  */
470  void print_nrn_alloc() override;
471 
472 
473  /**
474  * Print nrn_jacob function definition
475  *
476  */
477  void print_nrn_jacob();
478 
479 
480  /****************************************************************************************/
481  /* Print nrn_state routine */
482  /****************************************************************************************/
483 
484 
485  /**
486  * Print nrn_state / state update function definition
487  */
488  void print_nrn_state() override;
489 
490 
491  /****************************************************************************************/
492  /* Print nrn_cur related routines */
493  /****************************************************************************************/
494 
495  std::string nrn_current_arguments();
497 
498  /**
499  * Print the \c nrn_current kernel
500  *
501  * \note nrn_cur_kernel will have two calls to nrn_current if no conductance keywords specified
502  * \param node the AST node representing the NMODL breakpoint block
503  */
504  void print_nrn_current(const ast::BreakpointBlock& node) override;
505 
506 
507  /**
508  * Print the \c nrn\_cur kernel with NMODL \c conductance keyword provisions
509  *
510  * If the NMODL \c conductance keyword is used in the \c breakpoint block, then
511  * CodegenCoreneuronCppVisitor::print_nrn_cur_kernel will use this printer
512  *
513  * \param node the AST node representing the NMODL breakpoint block
514  */
515  void print_nrn_cur_conductance_kernel(const ast::BreakpointBlock& node) override;
516 
517 
518  /**
519  * Print the \c nrn\_cur kernel without NMODL \c conductance keyword provisions
520  *
521  * If the NMODL \c conductance keyword is \b not used in the \c breakpoint block, then
522  * CodegenCoreneuronCppVisitor::print_nrn_cur_kernel will use this printer
523  */
524  void print_nrn_cur_non_conductance_kernel() override;
525 
526 
527  /**
528  * Print main body of nrn_cur function
529  * \param node the AST node representing the NMODL breakpoint block
530  */
531  void print_nrn_cur_kernel(const ast::BreakpointBlock& node) override;
532 
533 
534  /**
535  * Print fast membrane current calculation code
536  */
537  virtual void print_fast_imem_calculation() override;
538 
539 
540  /**
541  * Print nrn_cur / current update function definition
542  */
543  void print_nrn_cur() override;
544 
545 
546  /****************************************************************************************/
547  /* Main code printing entry points */
548  /****************************************************************************************/
549 
550 
551  /**
552  * Print all includes
553  *
554  */
555  void print_headers_include() override;
556 
557 
558  /**
559  * Print all NEURON macros
560  *
561  */
563 
564 
565  /**
566  * Print NEURON global variable macros
567  *
568  */
569  void print_global_macros();
570 
571 
572  /**
573  * Print mechanism variables' related macros
574  *
575  */
577 
578 
579  /**
580  * Print start of namespaces
581  *
582  */
583  void print_namespace_begin() override;
584 
585 
586  /**
587  * Print end of namespaces
588  *
589  */
590  void print_namespace_end() override;
591 
592 
593  /**
594  * Print all classes
595  * \param print_initializers Whether to include default values.
596  */
597  void print_data_structures(bool print_initializers) override;
598 
599  /** Print `make_*_instance`.
600  */
601  void print_make_instance() const;
602 
603  /** Print `make_*_node_data`.
604  */
605  void print_make_node_data() const;
606 
607  /**
608  * Set v_unused (voltage) for NRN_PRCELLSTATE feature
609  */
610  void print_v_unused() const override;
611 
612 
613  /**
614  * Set g_unused (conductance) for NRN_PRCELLSTATE feature
615  */
616  void print_g_unused() const override;
617 
618 
619  /**
620  * Print all compute functions for every backend
621  *
622  */
623  virtual void print_compute_functions() override;
624 
625 
626  /**
627  * Print entry point to code generation
628  *
629  */
630  void print_codegen_routines() override;
631 
632 
633  /****************************************************************************************/
634  /* Overloaded visitor routines */
635  /****************************************************************************************/
636 
637 
638  virtual void visit_watch_statement(const ast::WatchStatement& node) override;
639 
640 
641  /**
642  * Print prototype declarations of functions or procedures
643  * \tparam T The AST node type of the node (must be of nmodl::ast::Ast or subclass)
644  * \param node The AST node representing the function or procedure block
645  * \param name A user defined name for the function
646  */
647  template <typename T>
648  void print_function_declaration(const T& node, const std::string& name);
649 
650 
651  public:
652  /****************************************************************************************/
653  /* Public printing routines for code generation for use in unit tests */
654  /****************************************************************************************/
655 
656 
657  /**
658  * Print the structure that wraps all range and int variables required for the NMODL
659  *
660  * \param print_initializers Whether or not default values for variables
661  * be included in the struct declaration.
662  */
663  void print_mechanism_range_var_structure(bool print_initializers) override;
664 
665  /**
666  * Print the structure that wraps all node variables required for the NMODL.
667  *
668  * \param print_initializers Whether or not default values for variables
669  * be included in the struct declaration.
670  */
671  void print_node_data_structure(bool print_initializers);
672 };
673 
674 
675 /**
676  * \details If there is an argument with name (say alpha) same as range variable (say alpha),
677  * we want to avoid it being printed as instance->alpha. And hence we disable variable
678  * name lookup during prototype declaration. Note that the name of procedure can be
679  * different in case of table statement.
680  */
681 template <typename T>
682 void CodegenNeuronCppVisitor::print_function_declaration(const T& node, const std::string& name) {
684  auto type = default_float_data_type();
685 
686  // internal and user provided arguments
687  auto internal_params = internal_method_parameters();
688  const auto& params = node.get_parameters();
689  for (const auto& param: params) {
690  internal_params.emplace_back("", type, "", param.get()->get_node_name());
691  }
692 
693  // procedures have "int" return type by default
694  const char* return_type = "int";
695  if (node.is_function_block()) {
696  return_type = default_float_data_type();
697  }
698 
699  /// TODO: Edit for NEURON
700  printer->add_indent();
701  printer->fmt_text("inline {} {}({})",
702  return_type,
703  method_name(name),
704  get_parameter_str(internal_params));
705 
707 }
708 
709 /** \} */ // end of codegen_backends
710 
711 } // namespace codegen
712 } // namespace nmodl
nmodl::codegen::CodegenNeuronCppVisitor::external_method_parameters
const char * external_method_parameters(bool table=false) noexcept override
Parameters for functions in generated code that are called back from external code.
Definition: codegen_neuron_cpp_visitor.cpp:401
nmodl::codegen::CodegenNeuronCppVisitor::print_nrn_destructor
void print_nrn_destructor() override
Print nrn_destructor function definition.
Definition: codegen_neuron_cpp_visitor.cpp:1241
nmodl::codegen::CodegenNeuronCppVisitor::print_nrn_cur_non_conductance_kernel
void print_nrn_cur_non_conductance_kernel() override
Print the nrn_cur kernel without NMODL conductance keyword provisions.
Definition: codegen_neuron_cpp_visitor.cpp:1473
nmodl::codegen::CodegenNeuronCppVisitor::py_function_signature
std::string py_function_signature(const std::string &function_or_procedure_name) const
Get the signature of the npy <func_or_proc_name> function.
Definition: codegen_neuron_cpp_visitor.cpp:451
nmodl::codegen::IndexVariableInfo
Helper to represent information about index/int variables.
Definition: codegen_cpp_visitor.hpp:111
nmodl::codegen::CodegenNeuronCppVisitor::print_nrn_cur
void print_nrn_cur() override
Print nrn_cur / current update function definition.
Definition: codegen_neuron_cpp_visitor.cpp:1547
nmodl::codegen::CodegenNeuronCppVisitor::print_macro_definitions
void print_macro_definitions()
Print all NEURON macros.
Definition: codegen_neuron_cpp_visitor.cpp:1595
nmodl::ast::FunctionBlock
TODO.
Definition: function_block.hpp:39
nmodl::codegen::CodegenNeuronCppVisitor::print_net_event_call
void print_net_event_call(const ast::FunctionCall &node) override
Print call to net_event.
Definition: codegen_neuron_cpp_visitor.cpp:1736
nmodl::codegen::CodegenNeuronCppVisitor::print_neuron_includes
void print_neuron_includes()
Print includes from NEURON.
Definition: codegen_neuron_cpp_visitor.cpp:651
nmodl::codegen::CodegenNeuronCppVisitor::print_nrn_init
void print_nrn_init(bool skip_init_check=true)
Print the nrn_init function definition.
Definition: codegen_neuron_cpp_visitor.cpp:1211
nmodl::codegen::CodegenNeuronCppVisitor::print_hoc_py_wrapper_function_body
void print_hoc_py_wrapper_function_body(const ast::Block *function_or_procedure_block, InterpreterWrapper wrapper_type)
Definition: codegen_neuron_cpp_visitor.cpp:263
nmodl::codegen::CodegenNeuronCppVisitor::internal_method_arguments
std::string internal_method_arguments() override
Arguments for functions that are defined and used internally.
Definition: codegen_neuron_cpp_visitor.cpp:377
nmodl::codegen::CodegenCppVisitor::SymbolType
std::shared_ptr< symtab::Symbol > SymbolType
Definition: codegen_cpp_visitor.hpp:238
nmodl::codegen::CodegenNeuronCppVisitor::print_nrn_alloc
void print_nrn_alloc() override
Print nrn_alloc function definition.
Definition: codegen_neuron_cpp_visitor.cpp:1247
nmodl::codegen::CodegenNeuronCppVisitor::register_mechanism_arguments
std::string register_mechanism_arguments() const override
Arguments for register_mech or point_register_mech function.
Definition: codegen_neuron_cpp_visitor.cpp:425
nmodl::codegen::CodegenNeuronCppVisitor::position_of_int_var
int position_of_int_var(const std::string &name) const override
Determine the position in the data array for a given int variable.
Definition: codegen_neuron_cpp_visitor.cpp:65
nmodl::codegen::CodegenNeuronCppVisitor::nrn_current_arguments
std::string nrn_current_arguments()
Definition: codegen_neuron_cpp_visitor.cpp:1391
nmodl::codegen::CodegenNeuronCppVisitor::optimize_ion_variable_copies
bool optimize_ion_variable_copies() const override
Check if ion variable copies should be avoided.
Definition: codegen_neuron_cpp_visitor.cpp:89
nmodl::codegen::CodegenNeuronCppVisitor::internal_method_parameters
ParamVector internal_method_parameters() override
Parameters for internally defined functions.
Definition: codegen_neuron_cpp_visitor.cpp:382
nmodl::codegen::CodegenNeuronCppVisitor::hoc_function_name
std::string hoc_function_name(const std::string &function_or_procedure_name) const
All functions and procedures need a hoc <func_or_proc_name> to be available to the HOC interpreter.
Definition: codegen_neuron_cpp_visitor.cpp:430
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::codegen::MemberType::index
@ index
index / int variables
nmodl::codegen::CodegenNeuronCppVisitor::global_variable_name
std::string global_variable_name(const SymbolType &symbol, bool use_instance=true) const override
Determine the variable name for a global variable given its symbol.
Definition: codegen_neuron_cpp_visitor.cpp:537
nmodl::codegen::CodegenNeuronCppVisitor::nrn_thread_internal_arguments
std::string nrn_thread_internal_arguments() override
Arguments for "_threadargs_" macro in neuron implementation.
Definition: codegen_neuron_cpp_visitor.cpp:413
symbol_table.hpp
Implement classes for representing symbol table at block and file scope.
nmodl::codegen::CodegenNeuronCppVisitor::backend_name
virtual std::string backend_name() const override
Name of the code generation backend.
Definition: codegen_neuron_cpp_visitor.cpp:43
nmodl::codegen::CodegenNeuronCppVisitor::process_verbatim_text
std::string process_verbatim_text(std::string const &text) override
Process a verbatim block for possible variable renaming.
Definition: codegen_neuron_cpp_visitor.cpp:419
nmodl::codegen::CodegenNeuronCppVisitor::nrn_current_parameters
ParamVector nrn_current_parameters()
Definition: codegen_neuron_cpp_visitor.cpp:1399
nmodl::codegen::CodegenNeuronCppVisitor::print_g_unused
void print_g_unused() const override
Set g_unused (conductance) for NRN_PRCELLSTATE feature.
Definition: codegen_neuron_cpp_visitor.cpp:1684
nmodl::codegen::CodegenNeuronCppVisitor::visit_watch_statement
virtual void visit_watch_statement(const ast::WatchStatement &node) override
TODO: Edit for NEURON.
Definition: codegen_neuron_cpp_visitor.cpp:1746
nmodl::codegen::CodegenNeuronCppVisitor::print_net_send_call
void print_net_send_call(const ast::FunctionCall &node) override
Print call to net_send.
Definition: codegen_neuron_cpp_visitor.cpp:1728
nmodl::codegen::CodegenNeuronCppVisitor::print_namespace_end
void print_namespace_end() override
Print end of namespaces.
Definition: codegen_neuron_cpp_visitor.cpp:1658
nmodl::codegen::CodegenNeuronCppVisitor::print_net_move_call
void print_net_move_call(const ast::FunctionCall &node) override
Print call to net_move.
Definition: codegen_neuron_cpp_visitor.cpp:1732
nmodl::codegen::CodegenNeuronCppVisitor::print_nrn_state
void print_nrn_state() override
Print nrn_state / state update function definition.
Definition: codegen_neuron_cpp_visitor.cpp:1344
nmodl::codegen::CodegenCppVisitor::default_float_data_type
const char * default_float_data_type() const noexcept
Default data type for floating point elements.
Definition: codegen_cpp_visitor.hpp:423
nmodl::codegen::CodegenNeuronCppVisitor::print_initial_block
void print_initial_block(const ast::InitialBlock *node)
Print the initial block.
Definition: codegen_neuron_cpp_visitor.cpp:1173
nmodl::codegen::CodegenNeuronCppVisitor::print_global_function_common_code
virtual void print_global_function_common_code(BlockType type, const std::string &function_name="") override
Print common code for global functions like nrn_init, nrn_cur and nrn_state.
Definition: codegen_neuron_cpp_visitor.cpp:1195
nmodl::codegen::CodegenNeuronCppVisitor::float_variable_name
std::string float_variable_name(const SymbolType &symbol, bool use_instance) const override
Determine the name of a float variable given its symbol.
Definition: codegen_neuron_cpp_visitor.cpp:486
nmodl::codegen::CodegenNeuronCppVisitor::print_function
void print_function(const ast::FunctionBlock &node) override
Print NMODL function in target backend code.
Definition: codegen_neuron_cpp_visitor.cpp:244
nmodl::codegen::CodegenNeuronCppVisitor::print_hoc_py_wrapper_function_definitions
void print_hoc_py_wrapper_function_definitions()
Definition: codegen_neuron_cpp_visitor.cpp:360
nmodl::codegen::CodegenNeuronCppVisitor::print_v_unused
void print_v_unused() const override
Set v_unused (voltage) for NRN_PRCELLSTATE feature.
Definition: codegen_neuron_cpp_visitor.cpp:1672
codegen_cpp_visitor.hpp
Visitor for printing C++ code compatible with legacy api of CoreNEURON
codegen_naming.hpp
nmodl::ast::Block
Base class for all block scoped nodes.
Definition: block.hpp:41
nmodl::ast::InitialBlock
Represents a INITIAL block in the NMODL.
Definition: initial_block.hpp:49
nmodl::codegen::CodegenNeuronCppVisitor::print_point_process_function_definitions
void print_point_process_function_definitions()
Print POINT_PROCESS related functions Wrap external NEURON functions related to POINT_PROCESS mechani...
Definition: codegen_neuron_cpp_visitor.cpp:102
nmodl::ast::WatchStatement
Represent WATCH statement in NMODL.
Definition: watch_statement.hpp:39
nmodl::codegen::CodegenNeuronCppVisitor::print_function_declaration
void print_function_declaration(const T &node, const std::string &name)
Print prototype declarations of functions or procedures.
Definition: codegen_neuron_cpp_visitor.hpp:682
nmodl::ast::BreakpointBlock
Represents a BREAKPOINT block in NMODL.
Definition: breakpoint_block.hpp:53
nmodl::codegen::CodegenNeuronCppVisitor::print_nrn_cur_conductance_kernel
void print_nrn_cur_conductance_kernel(const ast::BreakpointBlock &node) override
Print the nrn_cur kernel with NMODL conductance keyword provisions.
Definition: codegen_neuron_cpp_visitor.cpp:1434
nmodl::codegen::CodegenNeuronCppVisitor::int_variable_name
std::string int_variable_name(const IndexVariableInfo &symbol, const std::string &name, bool use_instance) const override
Determine the name of an int variable given its symbol.
Definition: codegen_neuron_cpp_visitor.cpp:507
nmodl::codegen::InterpreterWrapper
InterpreterWrapper
Enum to switch between HOC and Python wrappers for functions and procedures defined in mechanisms.
Definition: codegen_neuron_cpp_visitor.hpp:50
nmodl::codegen::CodegenNeuronCppVisitor::print_namespace_begin
void print_namespace_begin() override
Print start of namespaces.
Definition: codegen_neuron_cpp_visitor.cpp:1653
nmodl::ast::FunctionCall
TODO.
Definition: function_call.hpp:38
nmodl::codegen::CodegenNeuronCppVisitor::print_global_variables_for_hoc
void print_global_variables_for_hoc() override
Print byte arrays that register scalar and vector variables for hoc interface.
Definition: codegen_neuron_cpp_visitor.cpp:803
nmodl::codegen::CodegenNeuronCppVisitor::print_standard_includes
void print_standard_includes() override
Print standard C/C++ includes.
Definition: codegen_neuron_cpp_visitor.cpp:638
nmodl::codegen::CodegenNeuronCppVisitor::print_mechanism_range_var_structure
void print_mechanism_range_var_structure(bool print_initializers) override
Print the structure that wraps all range and int variables required for the NMODL.
Definition: codegen_neuron_cpp_visitor.cpp:1054
nmodl::codegen::CodegenNeuronCppVisitor::print_procedure
virtual void print_procedure(const ast::ProcedureBlock &node) override
Print NMODL procedure in target backend code.
Definition: codegen_neuron_cpp_visitor.cpp:239
code_printer.hpp
Helper class for printing C/C++ code.
nmodl::codegen::CodegenNeuronCppVisitor::hoc_function_signature
std::string hoc_function_signature(const std::string &function_or_procedure_name) const
Get the signature of the hoc <func_or_proc_name> function.
Definition: codegen_neuron_cpp_visitor.cpp:436
nmodl::codegen::CodegenNeuronCppVisitor::print_namespace_start
void print_namespace_start() override
Prints the start of the neuron namespace.
Definition: codegen_neuron_cpp_visitor.cpp:462
nmodl::codegen::CodegenNeuronCppVisitor::print_backend_info
void print_backend_info() override
Print top file header printed in generated code.
Definition: codegen_neuron_cpp_visitor.cpp:618
nmodl::codegen::CodegenNeuronCppVisitor::print_compute_functions
virtual void print_compute_functions() override
Print all compute functions for every backend.
Definition: codegen_neuron_cpp_visitor.cpp:1694
nmodl::codegen::CodegenNeuronCppVisitor::print_nrn_cur_kernel
void print_nrn_cur_kernel(const ast::BreakpointBlock &node) override
Print main body of nrn_cur function.
Definition: codegen_neuron_cpp_visitor.cpp:1508
nmodl::codegen::CodegenNeuronCppVisitor::conc_write_statement
std::string conc_write_statement(const std::string &ion_name, const std::string &concentration, int index) override
Generate Function call statement for nrn_wrote_conc.
Definition: codegen_neuron_cpp_visitor.cpp:473
nmodl::codegen::CodegenNeuronCppVisitor::print_mechanism_register
void print_mechanism_register() override
Print the mechanism registration function.
Definition: codegen_neuron_cpp_visitor.cpp:922
nmodl::codegen::CodegenNeuronCppVisitor::print_nrn_jacob
void print_nrn_jacob()
Print nrn_jacob function definition.
Definition: codegen_neuron_cpp_visitor.cpp:1223
codegen_info.hpp
Various types to store code generation specific information.
nmodl::codegen::HOC
@ HOC
Definition: codegen_neuron_cpp_visitor.hpp:50
nmodl::codegen::CodegenNeuronCppVisitor::print_fast_imem_calculation
virtual void print_fast_imem_calculation() override
Print fast membrane current calculation code.
Definition: codegen_neuron_cpp_visitor.cpp:1541
nmodl::codegen::CodegenNeuronCppVisitor::print_data_structures
void print_data_structures(bool print_initializers) override
Print all classes.
Definition: codegen_neuron_cpp_visitor.cpp:1663
nmodl::codegen::CodegenNeuronCppVisitor::print_sdlists_init
void print_sdlists_init(bool print_initializers) override
Definition: codegen_neuron_cpp_visitor.cpp:662
nmodl::codegen::CodegenNeuronCppVisitor::py_function_name
std::string py_function_name(const std::string &function_or_procedure_name) const
In non POINT_PROCESS mechanisms all functions and procedures need a py <func_or_proc_name> to be avai...
Definition: codegen_neuron_cpp_visitor.cpp:445
nmodl::codegen::CodegenNeuronCppVisitor::print_node_data_structure
void print_node_data_structure(bool print_initializers)
Print the structure that wraps all node variables required for the NMODL.
Definition: codegen_neuron_cpp_visitor.cpp:1139
nmodl::codegen::CodegenCppVisitor::get_parameter_str
static std::string get_parameter_str(const ParamVector &params)
Generate the string representing the procedure parameter declaration.
Definition: codegen_cpp_visitor.cpp:34
nmodl::codegen::CodegenNeuronCppVisitor::print_make_instance
void print_make_instance() const
Print make_*_instance.
Definition: codegen_neuron_cpp_visitor.cpp:1095
nmodl::codegen::CodegenNeuronCppVisitor::print_atomic_reduction_pragma
virtual void print_atomic_reduction_pragma() override
Print atomic update pragma for reduction statements.
Definition: codegen_neuron_cpp_visitor.cpp:85
nmodl::codegen::CodegenNeuronCppVisitor::print_namespace_stop
void print_namespace_stop() override
Prints the end of the neuron namespace.
Definition: codegen_neuron_cpp_visitor.cpp:468
nmodl::codegen::CodegenNeuronCppVisitor::print_setdata_functions
void print_setdata_functions()
Print NEURON functions related to setting global variables of the mechanism.
Definition: codegen_neuron_cpp_visitor.cpp:147
nmodl::ast::ProcedureBlock
TODO.
Definition: procedure_block.hpp:39
nmodl::codegen::CodegenNeuronCppVisitor::print_mechanism_variables_macros
void print_mechanism_variables_macros()
Print mechanism variables' related macros.
Definition: codegen_neuron_cpp_visitor.cpp:1618
nmodl::codegen::CodegenNeuronCppVisitor
Visitor for printing C++ code compatible with legacy api of NEURON
Definition: codegen_neuron_cpp_visitor.hpp:71
nmodl::codegen::CodegenCppVisitor::CodegenCppVisitor
CodegenCppVisitor(std::string mod_filename, const std::string &output_dir, std::string float_type, const bool optimize_ionvar_copies, size_t blame_line=0)
Constructs the C++ code generator visitor.
Definition: codegen_cpp_visitor.hpp:198
nmodl::codegen::CodegenNeuronCppVisitor::print_nrn_constructor
void print_nrn_constructor() override
Print nrn_constructor function definition.
Definition: codegen_neuron_cpp_visitor.cpp:1235
logger.hpp
Implement logger based on spdlog library.
nmodl::codegen::CodegenCppVisitor::enable_variable_name_lookup
bool enable_variable_name_lookup
Variable name should be converted to instance name (but not for function arguments)
Definition: codegen_cpp_visitor.hpp:315
nmodl::codegen::BlockType
BlockType
Helper to represent various block types.
Definition: codegen_cpp_visitor.hpp:56
nmodl::codegen::CodegenNeuronCppVisitor::print_function_or_procedure
void print_function_or_procedure(const ast::Block &node, const std::string &name) override
Print nmodl function or procedure (common code)
Definition: codegen_neuron_cpp_visitor.cpp:207
nmodl::codegen::CodegenNeuronCppVisitor::print_headers_include
void print_headers_include() override
Print all includes.
Definition: codegen_neuron_cpp_visitor.cpp:1589
nmodl::codegen::CodegenNeuronCppVisitor::print_nrn_current
void print_nrn_current(const ast::BreakpointBlock &node) override
Print the nrn_current kernel.
Definition: codegen_neuron_cpp_visitor.cpp:1414
nmodl::codegen::CodegenNeuronCppVisitor::position_of_float_var
int position_of_float_var(const std::string &name) const override
Determine the position in the data array for a given float variable.
Definition: codegen_neuron_cpp_visitor.cpp:53
nmodl::codegen::CodegenNeuronCppVisitor::get_variable_name
std::string get_variable_name(const std::string &name, bool use_instance=true) const override
Determine variable name in the structure of mechanism properties.
Definition: codegen_neuron_cpp_visitor.cpp:547
nmodl::codegen::CodegenCppVisitor
Visitor for printing C++ code compatible with legacy api of CoreNEURON
Definition: codegen_cpp_visitor.hpp:180
nmodl::codegen::CodegenNeuronCppVisitor::print_make_node_data
void print_make_node_data() const
Print make_*_node_data.
Definition: codegen_neuron_cpp_visitor.cpp:1153
nmodl::codegen::CodegenNeuronCppVisitor::simulator_name
std::string simulator_name() override
Name of the simulator the code was generated for.
Definition: codegen_neuron_cpp_visitor.cpp:38
nmodl::codegen::CodegenNeuronCppVisitor::print_function_procedure_helper
void print_function_procedure_helper(const ast::Block &node) override
Common helper function to help printing function or procedure blocks.
Definition: codegen_neuron_cpp_visitor.cpp:228
nmodl::codegen::CodegenCppVisitor::printer
std::unique_ptr< CodePrinter > printer
Code printer object for target (C++)
Definition: codegen_cpp_visitor.hpp:260
nmodl::codegen::CodegenNeuronCppVisitor::external_method_arguments
const char * external_method_arguments() noexcept override
Arguments for external functions called from generated code.
Definition: codegen_neuron_cpp_visitor.cpp:395
nmodl::codegen::CodegenCppVisitor::method_name
std::string method_name(const std::string &name) const
Constructs the name of a function or procedure.
Definition: codegen_cpp_visitor.hpp:920
nmodl::codegen::CodegenNeuronCppVisitor::nrn_thread_arguments
std::string nrn_thread_arguments() const override
Arguments for "_threadargs_" macro in neuron implementation.
Definition: codegen_neuron_cpp_visitor.cpp:407
nmodl::codegen::Python
@ Python
Definition: codegen_neuron_cpp_visitor.hpp:50
nmodl::codegen::CodegenNeuronCppVisitor::print_codegen_routines
void print_codegen_routines() override
Print entry point to code generation.
Definition: codegen_neuron_cpp_visitor.cpp:1710
nmodl::codegen::CodegenNeuronCppVisitor::print_function_prototypes
void print_function_prototypes() override
Print function and procedures prototype declaration.
Definition: codegen_neuron_cpp_visitor.cpp:197
nmodl::codegen::CodegenNeuronCppVisitor::print_mechanism_global_var_structure
void print_mechanism_global_var_structure(bool print_initializers) override
Print the structure that wraps all global variables used in the NMODL.
Definition: codegen_neuron_cpp_visitor.cpp:704
nmodl::codegen::CodegenNeuronCppVisitor::print_global_macros
void print_global_macros()
Print NEURON global variable macros.
Definition: codegen_neuron_cpp_visitor.cpp:1601
nmodl::codegen::CodegenCppVisitor::ParamVector
std::vector< std::tuple< std::string, std::string, std::string, std::string > > ParamVector
A vector of parameters represented by a 4-tuple of strings:
Definition: codegen_cpp_visitor.hpp:250
ast_visitor.hpp
Concrete visitor for all AST classes.