User Guide
nmodl::codegen Namespace Reference

Namespaces

 naming
 different variable names used in code generation
 
 utils
 

Classes

class  CodegenAccVisitor
 Visitor for printing C++ code with OpenACC backend More...
 
class  CodegenCompatibilityVisitor
 Visitor for printing compatibility issues of the mod file More...
 
class  CodegenCoreneuronCppVisitor
 Visitor for printing C++ code compatible with legacy api of CoreNEURON More...
 
class  CodegenCppVisitor
 Visitor for printing C++ code compatible with legacy api of CoreNEURON More...
 
class  CodegenHelperVisitor
 Helper visitor to gather AST information to help code generation. More...
 
class  CodegenInfo
 Represent information collected from AST for code generation. More...
 
class  CodegenNeuronCppVisitor
 Visitor for printing C++ code compatible with legacy api of NEURON More...
 
class  Conductance
 Represent conductance statements used in mod file. More...
 
class  IndexSemantics
 Represent semantic information for index variable. More...
 
class  IndexVariableInfo
 Helper to represent information about index/int variables. More...
 
class  Ion
 Represent ions used in mod file. More...
 
class  LongitudinalDiffusionInfo
 Information required to print LONGITUDINAL_DIFFUSION callbacks. More...
 
class  ShadowUseStatement
 Represents ion write statement during code generation. More...
 
struct  ThreadVariableInfo
 

Enumerations

enum  BlockType {
  BlockType::Initial, BlockType::Constructor, BlockType::Destructor, BlockType::Equation,
  BlockType::State, BlockType::Watch, BlockType::NetReceive, BlockType::BeforeAfter,
  BlockType::BlockTypeEnd
}
 Helper to represent various block types. More...
 
enum  MemberType { MemberType::index, MemberType::range, MemberType::global, MemberType::thread }
 Helper to represent various variables types. More...
 
enum  CppObjectSpecifier {
  CppObjectSpecifier::Inline, CppObjectSpecifier::Static, CppObjectSpecifier::Virtual, CppObjectSpecifier::Explicit,
  CppObjectSpecifier::Friend, CppObjectSpecifier::Constexpr, CppObjectSpecifier::Extern, CppObjectSpecifier::ExternC,
  CppObjectSpecifier::ThreadLocal, CppObjectSpecifier::Const, CppObjectSpecifier::Volatile
}
 various specifiers (mostly for function codegen) More...
 
enum  InterpreterWrapper { HOC, Python }
 Enum to switch between HOC and Python wrappers for functions and procedures defined in mechanisms. More...
 

Functions

static std::string get_register_type_for_ba_block (const ast::Block *block)
 Return registration type for a given BEFORE/AFTER block /param block A BEFORE/AFTER block being registered. More...
 
static void rename_net_receive_arguments (const ast::NetReceiveBlock &net_receive_node, const ast::Node &node)
 Rename arguments to NET_RECEIVE block with corresponding pointer variable. More...
 
std::string get_name (ast::Ast const *sym)
 
std::string get_name (const std::shared_ptr< symtab::Symbol > &sym)
 
std::string get_name (const IndexVariableInfo &var)
 
template<class T >
int get_index_from_name (const std::vector< T > &variables, const std::string &name)
 
int get_length (const std::shared_ptr< symtab::Symbol > &sym)
 
int get_length (const IndexVariableInfo &var)
 
template<class T >
int get_prefixsum_from_name (const std::vector< T > &variables, const std::string &name)
 
static bool check_procedure_has_cvode (const std::shared_ptr< const ast::Ast > &solve_node, const std::shared_ptr< const ast::Ast > &procedure_node)
 Check whether a given SOLVE block solves a PROCEDURE with any of the CVode methods. More...
 
static std::shared_ptr< ast::Compartmentfind_compartment (const ast::LongitudinalDiffusionBlock &node, const std::string &var_name)
 
std::unordered_map< std::string, std::string > get_nonglobal_local_variable_names (const symtab::SymbolTable &symtab)
 Map of the non-(global/top-local) LOCAL variables. More...
 
static void rename_net_receive_arguments (const ast::NetReceiveBlock &net_receive_node, const ast::Node &node)
 Rename arguments to NET_RECEIVE block with corresponding pointer variable. More...
 
std::string get_name (const ThreadVariableInfo &var)
 

Variables

const std::regex regex_special_chars {R"([-[\]{}()*+?.,\^$|#\s])"}
 

Enumeration Type Documentation

◆ InterpreterWrapper

Enum to switch between HOC and Python wrappers for functions and procedures defined in mechanisms.

Enumerator
HOC 
Python 

Definition at line 52 of file codegen_neuron_cpp_visitor.hpp.

Function Documentation

◆ check_procedure_has_cvode()

static bool nmodl::codegen::check_procedure_has_cvode ( const std::shared_ptr< const ast::Ast > &  solve_node,
const std::shared_ptr< const ast::Ast > &  procedure_node 
)
static

Check whether a given SOLVE block solves a PROCEDURE with any of the CVode methods.

Definition at line 33 of file codegen_helper_visitor.cpp.

◆ find_compartment()

static std::shared_ptr<ast::Compartment> nmodl::codegen::find_compartment ( const ast::LongitudinalDiffusionBlock node,
const std::string &  var_name 
)
static

Definition at line 867 of file codegen_helper_visitor.cpp.

◆ get_nonglobal_local_variable_names()

std::unordered_map<std::string, std::string> nmodl::codegen::get_nonglobal_local_variable_names ( const symtab::SymbolTable symtab)

Map of the non-(global/top-local) LOCAL variables.

The map associates the name in the MOD file, e.g. a with the current name of that LOCAL variable, e.g. a_r_4.

auto map = get_nonglobal_local_variable_names();
assert map["a"] == "a_r_4";

The two names can differ, because an early pass makes all names unique by renaming local variables.

Definition at line 657 of file codegen_neuron_cpp_visitor.cpp.

◆ get_register_type_for_ba_block()

static std::string nmodl::codegen::get_register_type_for_ba_block ( const ast::Block block)
static

Return registration type for a given BEFORE/AFTER block /param block A BEFORE/AFTER block being registered.

Depending on a block type i.e. BEFORE or AFTER and also type of it's associated block i.e. BREAKPOINT, INITIAL, SOLVE and STEP, the registration type (as an integer) is calculated. These values are then interpreted by CoreNEURON internally.

before block have value 10 and after block 20

associated blocks have different values (1 to 4) based on type. These values are based on neuron/coreneuron implementation details.

Definition at line 1210 of file codegen_coreneuron_cpp_visitor.cpp.

◆ rename_net_receive_arguments() [1/2]

static void nmodl::codegen::rename_net_receive_arguments ( const ast::NetReceiveBlock net_receive_node,
const ast::Node node 
)
static

Rename arguments to NET_RECEIVE block with corresponding pointer variable.

Arguments to NET_RECEIVE block are packed and passed via weight vector. These variables need to be replaced with corresponding pointer variable. For example, if mod file is like

NET_RECEIVE (weight, R){
INITIAL {
R=1
}
}

then generated code for initial block should be:

double* R = weights + weight_index + 0;
(*R) = 1.0;

So, the R in AST needs to be renamed with (*R).

Definition at line 2266 of file codegen_coreneuron_cpp_visitor.cpp.

◆ rename_net_receive_arguments() [2/2]

static void nmodl::codegen::rename_net_receive_arguments ( const ast::NetReceiveBlock net_receive_node,
const ast::Node node 
)
static

Rename arguments to NET_RECEIVE block with corresponding pointer variable.

NET_RECEIVE (weight, R){
x = R
}

then generated code should be:

x[id] = _args[1];

So, the R in AST needs to be renamed with _args[1].

Definition at line 2792 of file codegen_neuron_cpp_visitor.cpp.

Variable Documentation

◆ regex_special_chars

const std::regex nmodl::codegen::regex_special_chars {R"([-[\]{}()*+?.,\^$|#\s])"}

Definition at line 912 of file codegen_cpp_visitor.cpp.