User Guide
nmodl::codegen::CodegenHelperVisitor Class Reference

Helper visitor to gather AST information to help code generation. More...

Detailed Description

Helper visitor to gather AST information to help code generation.

Code generation pass needs various information from AST and symbol table. Different code generation backends will need this information. This helper pass visit ast and collect all information into single class object of CodegenInfo.

Todo:
  • Determine vectorize as part of the pass
  • Determine threadsafe as part of the pass
  • Global variable order is not preserved, for example, below gives different order:
    • NEURON block: GLOBAL gq, gp
    • PARAMETER block: gp = 11, gq[2]
  • POINTER rng and if it's also assigned rng[4] then it is printed as one value. Need to check what is correct value.

Definition at line 47 of file codegen_helper_visitor.hpp.

#include <codegen_helper_visitor.hpp>

Inheritance diagram for nmodl::codegen::CodegenHelperVisitor:
nmodl::visitor::ConstAstVisitor nmodl::visitor::ConstVisitor

Public Member Functions

 CodegenHelperVisitor ()=default
 
codegen::CodegenInfo analyze (const ast::Program &node)
 run visitor and return information for code generation More...
 
void visit_electrode_current (const ast::ElectrodeCurrent &node) override
 visit node of type ast::ElectrodeCurrent More...
 
void visit_suffix (const ast::Suffix &node) override
 visit node of type ast::Suffix More...
 
void visit_function_call (const ast::FunctionCall &node) override
 visit node of type ast::FunctionCall More...
 
void visit_binary_expression (const ast::BinaryExpression &node) override
 visit node of type ast::BinaryExpression More...
 
void visit_conductance_hint (const ast::ConductanceHint &node) override
 visit node of type ast::ConductanceHint More...
 
void visit_procedure_block (const ast::ProcedureBlock &node) override
 visit node of type ast::ProcedureBlock More...
 
void visit_function_block (const ast::FunctionBlock &node) override
 visit node of type ast::FunctionBlock More...
 
void visit_function_table_block (const ast::FunctionTableBlock &node) override
 visit node of type ast::FunctionTableBlock More...
 
void visit_eigen_newton_solver_block (const ast::EigenNewtonSolverBlock &node) override
 visit node of type ast::EigenNewtonSolverBlock More...
 
void visit_eigen_linear_solver_block (const ast::EigenLinearSolverBlock &node) override
 visit node of type ast::EigenLinearSolverBlock More...
 
void visit_statement_block (const ast::StatementBlock &node) override
 Visit statement block and find prime symbols appear in derivative block. More...
 
void visit_initial_block (const ast::InitialBlock &node) override
 visit node of type ast::InitialBlock More...
 
void visit_constructor_block (const ast::ConstructorBlock &node) override
 visit node of type ast::ConstructorBlock More...
 
void visit_destructor_block (const ast::DestructorBlock &node) override
 visit node of type ast::DestructorBlock More...
 
void visit_breakpoint_block (const ast::BreakpointBlock &node) override
 visit node of type ast::BreakpointBlock More...
 
void visit_derivative_block (const ast::DerivativeBlock &node) override
 visit node of type ast::DerivativeBlock More...
 
void visit_derivimplicit_callback (const ast::DerivimplicitCallback &node) override
 visit node of type ast::DerivimplicitCallback More...
 
void visit_net_receive_block (const ast::NetReceiveBlock &node) override
 visit node of type ast::NetReceiveBlock More...
 
void visit_bbcore_pointer (const ast::BbcorePointer &node) override
 visit node of type ast::BbcorePointer More...
 
void visit_watch (const ast::Watch &node) override
 visit node of type ast::Watch More...
 
void visit_watch_statement (const ast::WatchStatement &node) override
 visit node of type ast::WatchStatement More...
 
void visit_for_netcon (const ast::ForNetcon &node) override
 visit node of type ast::ForNetcon More...
 
void visit_table_statement (const ast::TableStatement &node) override
 visit node of type ast::TableStatement More...
 
void visit_program (const ast::Program &node) override
 visit node of type ast::Program More...
 
void visit_factor_def (const ast::FactorDef &node) override
 visit node of type ast::FactorDef More...
 
void visit_nrn_state_block (const ast::NrnStateBlock &node) override
 visit node of type ast::NrnStateBlock More...
 
void visit_linear_block (const ast::LinearBlock &node) override
 visit node of type ast::LinearBlock More...
 
void visit_non_linear_block (const ast::NonLinearBlock &node) override
 visit node of type ast::NonLinearBlock More...
 
void visit_discrete_block (const ast::DiscreteBlock &node) override
 visit node of type ast::DiscreteBlock More...
 
void visit_update_dt (const ast::UpdateDt &node) override
 visit node of type ast::UpdateDt More...
 
void visit_verbatim (const ast::Verbatim &node) override
 visit verbatim block and find all symbols used More...
 
void visit_before_block (const ast::BeforeBlock &node) override
 visit node of type ast::BeforeBlock More...
 
void visit_after_block (const ast::AfterBlock &node) override
 visit node of type ast::AfterBlock More...
 
- Public Member Functions inherited from nmodl::visitor::ConstAstVisitor
void visit_node (const ast::Node &node) override
 visit node of type ast::Node More...
 
void visit_statement (const ast::Statement &node) override
 visit node of type ast::Statement More...
 
void visit_expression (const ast::Expression &node) override
 visit node of type ast::Expression More...
 
void visit_block (const ast::Block &node) override
 visit node of type ast::Block More...
 
void visit_identifier (const ast::Identifier &node) override
 visit node of type ast::Identifier More...
 
void visit_number (const ast::Number &node) override
 visit node of type ast::Number More...
 
void visit_string (const ast::String &node) override
 visit node of type ast::String More...
 
void visit_integer (const ast::Integer &node) override
 visit node of type ast::Integer More...
 
void visit_float (const ast::Float &node) override
 visit node of type ast::Float More...
 
void visit_double (const ast::Double &node) override
 visit node of type ast::Double More...
 
void visit_boolean (const ast::Boolean &node) override
 visit node of type ast::Boolean More...
 
void visit_name (const ast::Name &node) override
 visit node of type ast::Name More...
 
void visit_prime_name (const ast::PrimeName &node) override
 visit node of type ast::PrimeName More...
 
void visit_indexed_name (const ast::IndexedName &node) override
 visit node of type ast::IndexedName More...
 
void visit_var_name (const ast::VarName &node) override
 visit node of type ast::VarName More...
 
void visit_argument (const ast::Argument &node) override
 visit node of type ast::Argument More...
 
void visit_react_var_name (const ast::ReactVarName &node) override
 visit node of type ast::ReactVarName More...
 
void visit_read_ion_var (const ast::ReadIonVar &node) override
 visit node of type ast::ReadIonVar More...
 
void visit_write_ion_var (const ast::WriteIonVar &node) override
 visit node of type ast::WriteIonVar More...
 
void visit_nonspecific_cur_var (const ast::NonspecificCurVar &node) override
 visit node of type ast::NonspecificCurVar More...
 
void visit_electrode_cur_var (const ast::ElectrodeCurVar &node) override
 visit node of type ast::ElectrodeCurVar More...
 
void visit_range_var (const ast::RangeVar &node) override
 visit node of type ast::RangeVar More...
 
void visit_global_var (const ast::GlobalVar &node) override
 visit node of type ast::GlobalVar More...
 
void visit_pointer_var (const ast::PointerVar &node) override
 visit node of type ast::PointerVar More...
 
void visit_random_var (const ast::RandomVar &node) override
 visit node of type ast::RandomVar More...
 
void visit_bbcore_pointer_var (const ast::BbcorePointerVar &node) override
 visit node of type ast::BbcorePointerVar More...
 
void visit_extern_var (const ast::ExternVar &node) override
 visit node of type ast::ExternVar More...
 
void visit_param_block (const ast::ParamBlock &node) override
 visit node of type ast::ParamBlock More...
 
void visit_independent_block (const ast::IndependentBlock &node) override
 visit node of type ast::IndependentBlock More...
 
void visit_assigned_block (const ast::AssignedBlock &node) override
 visit node of type ast::AssignedBlock More...
 
void visit_state_block (const ast::StateBlock &node) override
 visit node of type ast::StateBlock More...
 
void visit_initial_block (const ast::InitialBlock &node) override
 visit node of type ast::InitialBlock More...
 
void visit_constructor_block (const ast::ConstructorBlock &node) override
 visit node of type ast::ConstructorBlock More...
 
void visit_destructor_block (const ast::DestructorBlock &node) override
 visit node of type ast::DestructorBlock More...
 
void visit_statement_block (const ast::StatementBlock &node) override
 visit node of type ast::StatementBlock More...
 
void visit_derivative_block (const ast::DerivativeBlock &node) override
 visit node of type ast::DerivativeBlock More...
 
void visit_linear_block (const ast::LinearBlock &node) override
 visit node of type ast::LinearBlock More...
 
void visit_non_linear_block (const ast::NonLinearBlock &node) override
 visit node of type ast::NonLinearBlock More...
 
void visit_discrete_block (const ast::DiscreteBlock &node) override
 visit node of type ast::DiscreteBlock More...
 
void visit_function_table_block (const ast::FunctionTableBlock &node) override
 visit node of type ast::FunctionTableBlock More...
 
void visit_function_block (const ast::FunctionBlock &node) override
 visit node of type ast::FunctionBlock More...
 
void visit_procedure_block (const ast::ProcedureBlock &node) override
 visit node of type ast::ProcedureBlock More...
 
void visit_net_receive_block (const ast::NetReceiveBlock &node) override
 visit node of type ast::NetReceiveBlock More...
 
void visit_solve_block (const ast::SolveBlock &node) override
 visit node of type ast::SolveBlock More...
 
void visit_breakpoint_block (const ast::BreakpointBlock &node) override
 visit node of type ast::BreakpointBlock More...
 
void visit_before_block (const ast::BeforeBlock &node) override
 visit node of type ast::BeforeBlock More...
 
void visit_after_block (const ast::AfterBlock &node) override
 visit node of type ast::AfterBlock More...
 
void visit_ba_block (const ast::BABlock &node) override
 visit node of type ast::BABlock More...
 
void visit_for_netcon (const ast::ForNetcon &node) override
 visit node of type ast::ForNetcon More...
 
void visit_kinetic_block (const ast::KineticBlock &node) override
 visit node of type ast::KineticBlock More...
 
void visit_unit_block (const ast::UnitBlock &node) override
 visit node of type ast::UnitBlock More...
 
void visit_constant_block (const ast::ConstantBlock &node) override
 visit node of type ast::ConstantBlock More...
 
void visit_neuron_block (const ast::NeuronBlock &node) override
 visit node of type ast::NeuronBlock More...
 
void visit_unit (const ast::Unit &node) override
 visit node of type ast::Unit More...
 
void visit_double_unit (const ast::DoubleUnit &node) override
 visit node of type ast::DoubleUnit More...
 
void visit_local_var (const ast::LocalVar &node) override
 visit node of type ast::LocalVar More...
 
void visit_limits (const ast::Limits &node) override
 visit node of type ast::Limits More...
 
void visit_number_range (const ast::NumberRange &node) override
 visit node of type ast::NumberRange More...
 
void visit_constant_var (const ast::ConstantVar &node) override
 visit node of type ast::ConstantVar More...
 
void visit_binary_operator (const ast::BinaryOperator &node) override
 visit node of type ast::BinaryOperator More...
 
void visit_unary_operator (const ast::UnaryOperator &node) override
 visit node of type ast::UnaryOperator More...
 
void visit_reaction_operator (const ast::ReactionOperator &node) override
 visit node of type ast::ReactionOperator More...
 
void visit_paren_expression (const ast::ParenExpression &node) override
 visit node of type ast::ParenExpression More...
 
void visit_binary_expression (const ast::BinaryExpression &node) override
 visit node of type ast::BinaryExpression More...
 
void visit_diff_eq_expression (const ast::DiffEqExpression &node) override
 visit node of type ast::DiffEqExpression More...
 
void visit_unary_expression (const ast::UnaryExpression &node) override
 visit node of type ast::UnaryExpression More...
 
void visit_non_lin_equation (const ast::NonLinEquation &node) override
 visit node of type ast::NonLinEquation More...
 
void visit_lin_equation (const ast::LinEquation &node) override
 visit node of type ast::LinEquation More...
 
void visit_function_call (const ast::FunctionCall &node) override
 visit node of type ast::FunctionCall More...
 
void visit_watch (const ast::Watch &node) override
 visit node of type ast::Watch More...
 
void visit_ba_block_type (const ast::BABlockType &node) override
 visit node of type ast::BABlockType More...
 
void visit_unit_def (const ast::UnitDef &node) override
 visit node of type ast::UnitDef More...
 
void visit_factor_def (const ast::FactorDef &node) override
 visit node of type ast::FactorDef More...
 
void visit_valence (const ast::Valence &node) override
 visit node of type ast::Valence More...
 
void visit_unit_state (const ast::UnitState &node) override
 visit node of type ast::UnitState More...
 
void visit_local_list_statement (const ast::LocalListStatement &node) override
 visit node of type ast::LocalListStatement More...
 
void visit_model (const ast::Model &node) override
 visit node of type ast::Model More...
 
void visit_define (const ast::Define &node) override
 visit node of type ast::Define More...
 
void visit_include (const ast::Include &node) override
 visit node of type ast::Include More...
 
void visit_param_assign (const ast::ParamAssign &node) override
 visit node of type ast::ParamAssign More...
 
void visit_assigned_definition (const ast::AssignedDefinition &node) override
 visit node of type ast::AssignedDefinition More...
 
void visit_conductance_hint (const ast::ConductanceHint &node) override
 visit node of type ast::ConductanceHint More...
 
void visit_expression_statement (const ast::ExpressionStatement &node) override
 visit node of type ast::ExpressionStatement More...
 
void visit_protect_statement (const ast::ProtectStatement &node) override
 visit node of type ast::ProtectStatement More...
 
void visit_from_statement (const ast::FromStatement &node) override
 visit node of type ast::FromStatement More...
 
void visit_while_statement (const ast::WhileStatement &node) override
 visit node of type ast::WhileStatement More...
 
void visit_if_statement (const ast::IfStatement &node) override
 visit node of type ast::IfStatement More...
 
void visit_else_if_statement (const ast::ElseIfStatement &node) override
 visit node of type ast::ElseIfStatement More...
 
void visit_else_statement (const ast::ElseStatement &node) override
 visit node of type ast::ElseStatement More...
 
void visit_watch_statement (const ast::WatchStatement &node) override
 visit node of type ast::WatchStatement More...
 
void visit_mutex_lock (const ast::MutexLock &node) override
 visit node of type ast::MutexLock More...
 
void visit_mutex_unlock (const ast::MutexUnlock &node) override
 visit node of type ast::MutexUnlock More...
 
void visit_conserve (const ast::Conserve &node) override
 visit node of type ast::Conserve More...
 
void visit_compartment (const ast::Compartment &node) override
 visit node of type ast::Compartment More...
 
void visit_lon_difuse (const ast::LonDifuse &node) override
 visit node of type ast::LonDifuse More...
 
void visit_reaction_statement (const ast::ReactionStatement &node) override
 visit node of type ast::ReactionStatement More...
 
void visit_lag_statement (const ast::LagStatement &node) override
 visit node of type ast::LagStatement More...
 
void visit_constant_statement (const ast::ConstantStatement &node) override
 visit node of type ast::ConstantStatement More...
 
void visit_table_statement (const ast::TableStatement &node) override
 visit node of type ast::TableStatement More...
 
void visit_suffix (const ast::Suffix &node) override
 visit node of type ast::Suffix More...
 
void visit_useion (const ast::Useion &node) override
 visit node of type ast::Useion More...
 
void visit_nonspecific (const ast::Nonspecific &node) override
 visit node of type ast::Nonspecific More...
 
void visit_electrode_current (const ast::ElectrodeCurrent &node) override
 visit node of type ast::ElectrodeCurrent More...
 
void visit_range (const ast::Range &node) override
 visit node of type ast::Range More...
 
void visit_global (const ast::Global &node) override
 visit node of type ast::Global More...
 
void visit_random_var_list (const ast::RandomVarList &node) override
 visit node of type ast::RandomVarList More...
 
void visit_pointer (const ast::Pointer &node) override
 visit node of type ast::Pointer More...
 
void visit_bbcore_pointer (const ast::BbcorePointer &node) override
 visit node of type ast::BbcorePointer More...
 
void visit_external (const ast::External &node) override
 visit node of type ast::External More...
 
void visit_thread_safe (const ast::ThreadSafe &node) override
 visit node of type ast::ThreadSafe More...
 
void visit_verbatim (const ast::Verbatim &node) override
 visit node of type ast::Verbatim More...
 
void visit_line_comment (const ast::LineComment &node) override
 visit node of type ast::LineComment More...
 
void visit_block_comment (const ast::BlockComment &node) override
 visit node of type ast::BlockComment More...
 
void visit_ontology_statement (const ast::OntologyStatement &node) override
 visit node of type ast::OntologyStatement More...
 
void visit_program (const ast::Program &node) override
 visit node of type ast::Program More...
 
void visit_nrn_state_block (const ast::NrnStateBlock &node) override
 visit node of type ast::NrnStateBlock More...
 
void visit_eigen_newton_solver_block (const ast::EigenNewtonSolverBlock &node) override
 visit node of type ast::EigenNewtonSolverBlock More...
 
void visit_eigen_linear_solver_block (const ast::EigenLinearSolverBlock &node) override
 visit node of type ast::EigenLinearSolverBlock More...
 
void visit_wrapped_expression (const ast::WrappedExpression &node) override
 visit node of type ast::WrappedExpression More...
 
void visit_derivimplicit_callback (const ast::DerivimplicitCallback &node) override
 visit node of type ast::DerivimplicitCallback More...
 
void visit_solution_expression (const ast::SolutionExpression &node) override
 visit node of type ast::SolutionExpression More...
 
void visit_update_dt (const ast::UpdateDt &node) override
 visit node of type ast::UpdateDt More...
 
- Public Member Functions inherited from nmodl::visitor::ConstVisitor
virtual ~ConstVisitor ()=default
 

Private Types

using SymbolType = std::shared_ptr< symtab::Symbol >
 
using SymbolVectorType = std::vector< std::shared_ptr< symtab::Symbol > >
 

Private Member Functions

void find_ion_variables (const ast::Program &node)
 Find all ions used in mod file. More...
 
void find_table_variables ()
 
void find_range_variables ()
 Find range variables i.e. More...
 
void find_non_range_variables ()
 Find non-range variables i.e. More...
 
void find_neuron_global_variables ()
 

Static Private Member Functions

static void sort_with_mod2c_symbol_order (std::vector< SymbolType > &symbols)
 How symbols are stored in NEURON? See notes written in markdown file. More...
 

Private Attributes

codegen::CodegenInfo info
 holds all codegen related information More...
 
bool under_net_receive_block = false
 if visiting net receive block More...
 
bool under_derivative_block = false
 if visiting derivative block More...
 
bool under_breakpoint_block = false
 if visiting breakpoint block More...
 
bool table_statement_used = false
 table statement found More...
 
symtab::SymbolTablepsymtab = nullptr
 symbol table for the program More...
 
std::shared_ptr< ast::Expressionassign_lhs
 lhs of assignment in derivative block More...
 

Member Typedef Documentation

◆ SymbolType

Definition at line 48 of file codegen_helper_visitor.hpp.

◆ SymbolVectorType

using nmodl::codegen::CodegenHelperVisitor::SymbolVectorType = std::vector<std::shared_ptr<symtab::Symbol> >
private

Definition at line 49 of file codegen_helper_visitor.hpp.

Constructor & Destructor Documentation

◆ CodegenHelperVisitor()

nmodl::codegen::CodegenHelperVisitor::CodegenHelperVisitor ( )
default

Member Function Documentation

◆ analyze()

CodegenInfo nmodl::codegen::CodegenHelperVisitor::analyze ( const ast::Program node)

run visitor and return information for code generation

Definition at line 736 of file codegen_helper_visitor.cpp.

◆ find_ion_variables()

void nmodl::codegen::CodegenHelperVisitor::find_ion_variables ( const ast::Program node)
private

Find all ions used in mod file.

Check if given variable belongs to given ion. For example, eca belongs to ca ion, nai belongs to na ion. We just check if we exclude first/last char, if that is ion name.

iterate over all ion types and construct the Ion objects

once ions are populated, we can find all currents

check if write_conc(...) will be needed

Definition at line 68 of file codegen_helper_visitor.cpp.

◆ find_neuron_global_variables()

void nmodl::codegen::CodegenHelperVisitor::find_neuron_global_variables ( )
private

Definition at line 470 of file codegen_helper_visitor.cpp.

◆ find_non_range_variables()

void nmodl::codegen::CodegenHelperVisitor::find_non_range_variables ( )
private

Find non-range variables i.e.

ones that are not belong to per instance allocation

Certain variables like pointers, global, parameters are not necessary to be per instance variables. NEURON apply certain rules to determine which variables become thread, static or global variables. Here we construct those variables.

Top local variables are local variables appear in global scope. All local variables in program symbol table are in global scope.

All global variables remain global if mod file is not marked thread safe. Otherwise, global variables written at least once gets promoted to thread variables.

If parameter is not a range and used only as read variable then it becomes global variable. To qualify it as thread variable it must be be written at least once and mod file must be marked as thread safe. To exclusively get parameters only, we exclude all other variables (in without) and then sort them with neuron/mod2c order.

Todo:
Below we calculate thread related id and sizes. This will need to do from global analysis pass as here we are handling top local variables, global variables, derivimplicit method. There might be more use cases with other solver methods.

If derivimplicit is used, then first three thread ids get assigned to: 1st thread is used for: deriv_advance 2nd thread is used for: dith 3rd thread is used for: newtonspace

slist and dlist represent the offsets for prime variables used. For euler or derivimplicit methods its always first number.

next thread id is allocated for top local variables

next thread id is allocated for thread promoted variables

find total size of local variables in global scope

find number of prime variables and total size

find pointer or bbcore pointer variables

find RANDOM variables

Definition at line 153 of file codegen_helper_visitor.cpp.

◆ find_range_variables()

void nmodl::codegen::CodegenHelperVisitor::find_range_variables ( )
private

Find range variables i.e.

ones that are belong to per instance allocation

In order to be compatible with NEURON, we need to print all variables in exact order as NEURON/MOD2C implementation. This is important because memory for all variables is allocated in single 1-D array with certain offset for each variable. The order of variables determine the offset and hence they must be in same order as NEURON.

Here is how order is determined into NEURON/MOD2C implementation:

First, following three lists are created

  • variables with parameter and range property (List 1)
  • variables with state and range property (List 2)
  • variables with assigned and range property (List 3)

Once created, we remove some variables due to the following criteria:

  • In NEURON/MOD2C implementation, we remove variables with NRNPRANGEIN or NRNPRANGEOUT type
  • So who has NRNPRANGEIN and NRNPRANGEOUT type? these are USEION read or write variables that are not ionic currents.
  • This is the reason for mod files CaDynamics_E2.mod or cal_mig.mod, ica variable is printed earlier in the list but other variables like cai, cao don't appear in same order.

Finally we create 4th list:

  • variables with assigned property and not in the previous 3 lists

We now print the variables in following order:

  • List 1 i.e. range + parameter variables are printed first
  • List 3 i.e. range + assigned variables are printed next
  • List 2 i.e. range + state variables are printed next
  • List 4 i.e. assigned and ion variables not present in the previous 3 lists

NOTE:

  • State variables also have the property assigned_definition but these variables are not from ASSIGNED block.
  • Variable can not be range as well as state, it's redeclaration error
  • Variable can be parameter as well as range. Without range, parameter is considered as global variable i.e. one value for all instances.
  • If a variable is only defined as RANGE and not in assigned or parameter or state block then it's not printed.
  • Note that a variable property is different than the variable type. For example, if variable has range property, it doesn't mean the variable is declared as RANGE. Other variables like STATE and ASSIGNED block variables also get range property without being explicitly declared as RANGE in the mod file.
  • Also, there is difference between declaration order vs. definition order. For example, POINTER variable in NEURON block is just declaration and doesn't determine the order in which they will get printed. Below we query symbol table and order all instance variables into certain order.

comparator to decide the order based on definition

from symbols vector vars, remove all ion variables which are not ionic currents

if secondary vector contains any symbol that exist in the primary then remove it

First come parameters which are range variables.

Second come assigned variables which are range variables.

Third come state variables. All state variables are kind of range by default. Note that some mod files like CaDynamics_E2.mod use cai as state variable which appear in USEION read/write list. These variables are not considered in this variables because non ionic-current variables are removed and printed later.

range_state_vars is copy of state variables but without non ionic current variables

Remaining variables are assigned and ion variables which are not in the previous 3 lists

make sure that variables already present in previous lists are removed to avoid any duplication

sort variables with their definition order

Definition at line 346 of file codegen_helper_visitor.cpp.

◆ find_table_variables()

void nmodl::codegen::CodegenHelperVisitor::find_table_variables ( )
private

Definition at line 463 of file codegen_helper_visitor.cpp.

◆ sort_with_mod2c_symbol_order()

void nmodl::codegen::CodegenHelperVisitor::sort_with_mod2c_symbol_order ( std::vector< SymbolType > &  symbols)
staticprivate

How symbols are stored in NEURON? See notes written in markdown file.

Some variables get printed by iterating over symbol table in mod2c. The example of this is thread variables (and also ions?). In this case we must have to arrange order if we are going keep compatibility with NEURON.

Suppose there are three global variables: bcd, abc, abd, abe They will be in the 'a' bucket in order: abe, abd, abc and in 'b' bucket bcd So when we print thread variables, we first have to sort in the opposite order in which they come and then again order by first character in increasing order.

Note that variables in double array do not need this transformation and it seems like they should just follow definition order.

first sort by global id to get in reverse order

now order by name (to be same as neuron's bucket)

Definition at line 47 of file codegen_helper_visitor.cpp.

◆ visit_after_block()

void nmodl::codegen::CodegenHelperVisitor::visit_after_block ( const ast::AfterBlock node)
overridevirtual

visit node of type ast::AfterBlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 780 of file codegen_helper_visitor.cpp.

◆ visit_bbcore_pointer()

void nmodl::codegen::CodegenHelperVisitor::visit_bbcore_pointer ( const ast::BbcorePointer node)
overridevirtual

visit node of type ast::BbcorePointer

Implements nmodl::visitor::ConstVisitor.

Definition at line 691 of file codegen_helper_visitor.cpp.

◆ visit_before_block()

void nmodl::codegen::CodegenHelperVisitor::visit_before_block ( const ast::BeforeBlock node)
overridevirtual

visit node of type ast::BeforeBlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 776 of file codegen_helper_visitor.cpp.

◆ visit_binary_expression()

void nmodl::codegen::CodegenHelperVisitor::visit_binary_expression ( const ast::BinaryExpression node)
overridevirtual

visit node of type ast::BinaryExpression

Implements nmodl::visitor::ConstVisitor.

Definition at line 682 of file codegen_helper_visitor.cpp.

◆ visit_breakpoint_block()

void nmodl::codegen::CodegenHelperVisitor::visit_breakpoint_block ( const ast::BreakpointBlock node)
overridevirtual

visit node of type ast::BreakpointBlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 545 of file codegen_helper_visitor.cpp.

◆ visit_conductance_hint()

void nmodl::codegen::CodegenHelperVisitor::visit_conductance_hint ( const ast::ConductanceHint node)
overridevirtual

visit node of type ast::ConductanceHint

Implements nmodl::visitor::ConstVisitor.

Definition at line 614 of file codegen_helper_visitor.cpp.

◆ visit_constructor_block()

void nmodl::codegen::CodegenHelperVisitor::visit_constructor_block ( const ast::ConstructorBlock node)
overridevirtual

visit node of type ast::ConstructorBlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 513 of file codegen_helper_visitor.cpp.

◆ visit_derivative_block()

void nmodl::codegen::CodegenHelperVisitor::visit_derivative_block ( const ast::DerivativeBlock node)
overridevirtual

visit node of type ast::DerivativeBlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 534 of file codegen_helper_visitor.cpp.

◆ visit_derivimplicit_callback()

void nmodl::codegen::CodegenHelperVisitor::visit_derivimplicit_callback ( const ast::DerivimplicitCallback node)
overridevirtual

visit node of type ast::DerivimplicitCallback

Implements nmodl::visitor::ConstVisitor.

Definition at line 540 of file codegen_helper_visitor.cpp.

◆ visit_destructor_block()

void nmodl::codegen::CodegenHelperVisitor::visit_destructor_block ( const ast::DestructorBlock node)
overridevirtual

visit node of type ast::DestructorBlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 519 of file codegen_helper_visitor.cpp.

◆ visit_discrete_block()

void nmodl::codegen::CodegenHelperVisitor::visit_discrete_block ( const ast::DiscreteBlock node)
overridevirtual

visit node of type ast::DiscreteBlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 749 of file codegen_helper_visitor.cpp.

◆ visit_eigen_linear_solver_block()

void nmodl::codegen::CodegenHelperVisitor::visit_eigen_linear_solver_block ( const ast::EigenLinearSolverBlock node)
overridevirtual

visit node of type ast::EigenLinearSolverBlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 597 of file codegen_helper_visitor.cpp.

◆ visit_eigen_newton_solver_block()

void nmodl::codegen::CodegenHelperVisitor::visit_eigen_newton_solver_block ( const ast::EigenNewtonSolverBlock node)
overridevirtual

visit node of type ast::EigenNewtonSolverBlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 584 of file codegen_helper_visitor.cpp.

◆ visit_electrode_current()

void nmodl::codegen::CodegenHelperVisitor::visit_electrode_current ( const ast::ElectrodeCurrent node)
overridevirtual

visit node of type ast::ElectrodeCurrent

Implements nmodl::visitor::ConstVisitor.

Definition at line 498 of file codegen_helper_visitor.cpp.

◆ visit_factor_def()

void nmodl::codegen::CodegenHelperVisitor::visit_factor_def ( const ast::FactorDef node)
overridevirtual

visit node of type ast::FactorDef

Implements nmodl::visitor::ConstVisitor.

Definition at line 677 of file codegen_helper_visitor.cpp.

◆ visit_for_netcon()

void nmodl::codegen::CodegenHelperVisitor::visit_for_netcon ( const ast::ForNetcon node)
overridevirtual

visit node of type ast::ForNetcon

Implements nmodl::visitor::ConstVisitor.

Definition at line 707 of file codegen_helper_visitor.cpp.

◆ visit_function_block()

void nmodl::codegen::CodegenHelperVisitor::visit_function_block ( const ast::FunctionBlock node)
overridevirtual

visit node of type ast::FunctionBlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 569 of file codegen_helper_visitor.cpp.

◆ visit_function_call()

void nmodl::codegen::CodegenHelperVisitor::visit_function_call ( const ast::FunctionCall node)
overridevirtual

visit node of type ast::FunctionCall

Implements nmodl::visitor::ConstVisitor.

Definition at line 603 of file codegen_helper_visitor.cpp.

◆ visit_function_table_block()

void nmodl::codegen::CodegenHelperVisitor::visit_function_table_block ( const ast::FunctionTableBlock node)
overridevirtual

visit node of type ast::FunctionTableBlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 579 of file codegen_helper_visitor.cpp.

◆ visit_initial_block()

void nmodl::codegen::CodegenHelperVisitor::visit_initial_block ( const ast::InitialBlock node)
overridevirtual

visit node of type ast::InitialBlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 503 of file codegen_helper_visitor.cpp.

◆ visit_linear_block()

void nmodl::codegen::CodegenHelperVisitor::visit_linear_block ( const ast::LinearBlock node)
overridevirtual

visit node of type ast::LinearBlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 741 of file codegen_helper_visitor.cpp.

◆ visit_net_receive_block()

void nmodl::codegen::CodegenHelperVisitor::visit_net_receive_block ( const ast::NetReceiveBlock node)
overridevirtual

visit node of type ast::NetReceiveBlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 525 of file codegen_helper_visitor.cpp.

◆ visit_non_linear_block()

void nmodl::codegen::CodegenHelperVisitor::visit_non_linear_block ( const ast::NonLinearBlock node)
overridevirtual

visit node of type ast::NonLinearBlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 745 of file codegen_helper_visitor.cpp.

◆ visit_nrn_state_block()

void nmodl::codegen::CodegenHelperVisitor::visit_nrn_state_block ( const ast::NrnStateBlock node)
overridevirtual

visit node of type ast::NrnStateBlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 553 of file codegen_helper_visitor.cpp.

◆ visit_procedure_block()

void nmodl::codegen::CodegenHelperVisitor::visit_procedure_block ( const ast::ProcedureBlock node)
overridevirtual

visit node of type ast::ProcedureBlock

Implements nmodl::visitor::ConstVisitor.

Definition at line 559 of file codegen_helper_visitor.cpp.

◆ visit_program()

void nmodl::codegen::CodegenHelperVisitor::visit_program ( const ast::Program node)
overridevirtual

visit node of type ast::Program

Implements nmodl::visitor::ConstVisitor.

Definition at line 718 of file codegen_helper_visitor.cpp.

◆ visit_statement_block()

void nmodl::codegen::CodegenHelperVisitor::visit_statement_block ( const ast::StatementBlock node)
overridevirtual

Visit statement block and find prime symbols appear in derivative block.

Equation statements in derivative block has prime on the lhs. The order of primes could be different that declaration state block. Also, not all state variables need to appear in equation block. In this case, we want to find out the the primes in the order of equation definition. This is just to keep the same order as neuron implementation.

The primes are already solved and replaced by Dstate or name. And hence we need to check if the lhs variable is derived from prime name. If it's Dstate then we have to lookup state to find out corresponding symbol. This is because prime_variables_by_order should contain state variable name and not the one replaced by solver pass.

Todo:
AST can have duplicate DERIVATIVE blocks if a mod file uses SOLVE statements in its INITIAL block (e.g. in case of kinetic schemes using STEADYSTATE sparse solver). Such duplicated DERIVATIVE blocks could be removed by SolveBlockVisitor, or we have to avoid visiting them here. See e.g. SH_na8st.mod test and original reduced_dentate .mod.

Implements nmodl::visitor::ConstVisitor.

Definition at line 646 of file codegen_helper_visitor.cpp.

◆ visit_suffix()

void nmodl::codegen::CodegenHelperVisitor::visit_suffix ( const ast::Suffix node)
overridevirtual

visit node of type ast::Suffix

Implements nmodl::visitor::ConstVisitor.

Definition at line 484 of file codegen_helper_visitor.cpp.

◆ visit_table_statement()

void nmodl::codegen::CodegenHelperVisitor::visit_table_statement ( const ast::TableStatement node)
overridevirtual

visit node of type ast::TableStatement

Implements nmodl::visitor::ConstVisitor.

Definition at line 712 of file codegen_helper_visitor.cpp.

◆ visit_update_dt()

void nmodl::codegen::CodegenHelperVisitor::visit_update_dt ( const ast::UpdateDt node)
overridevirtual

visit node of type ast::UpdateDt

Implements nmodl::visitor::ConstVisitor.

Definition at line 753 of file codegen_helper_visitor.cpp.

◆ visit_verbatim()

void nmodl::codegen::CodegenHelperVisitor::visit_verbatim ( const ast::Verbatim node)
overridevirtual

visit verbatim block and find all symbols used

Implements nmodl::visitor::ConstVisitor.

Definition at line 758 of file codegen_helper_visitor.cpp.

◆ visit_watch()

void nmodl::codegen::CodegenHelperVisitor::visit_watch ( const ast::Watch node)
overridevirtual

visit node of type ast::Watch

Implements nmodl::visitor::ConstVisitor.

Definition at line 696 of file codegen_helper_visitor.cpp.

◆ visit_watch_statement()

void nmodl::codegen::CodegenHelperVisitor::visit_watch_statement ( const ast::WatchStatement node)
overridevirtual

visit node of type ast::WatchStatement

Implements nmodl::visitor::ConstVisitor.

Definition at line 701 of file codegen_helper_visitor.cpp.

Member Data Documentation

◆ assign_lhs

std::shared_ptr<ast::Expression> nmodl::codegen::CodegenHelperVisitor::assign_lhs
private

lhs of assignment in derivative block

Definition at line 70 of file codegen_helper_visitor.hpp.

◆ info

codegen::CodegenInfo nmodl::codegen::CodegenHelperVisitor::info
private

holds all codegen related information

Definition at line 52 of file codegen_helper_visitor.hpp.

◆ psymtab

symtab::SymbolTable* nmodl::codegen::CodegenHelperVisitor::psymtab = nullptr
private

symbol table for the program

Definition at line 67 of file codegen_helper_visitor.hpp.

◆ table_statement_used

bool nmodl::codegen::CodegenHelperVisitor::table_statement_used = false
private

table statement found

Definition at line 64 of file codegen_helper_visitor.hpp.

◆ under_breakpoint_block

bool nmodl::codegen::CodegenHelperVisitor::under_breakpoint_block = false
private

if visiting breakpoint block

Definition at line 61 of file codegen_helper_visitor.hpp.

◆ under_derivative_block

bool nmodl::codegen::CodegenHelperVisitor::under_derivative_block = false
private

if visiting derivative block

Definition at line 58 of file codegen_helper_visitor.hpp.

◆ under_net_receive_block

bool nmodl::codegen::CodegenHelperVisitor::under_net_receive_block = false
private

if visiting net receive block

Definition at line 55 of file codegen_helper_visitor.hpp.


The documentation for this class was generated from the following files: