Skip to content

Commit

Permalink
Move print_{function,procedure} upwards.
Browse files Browse the repository at this point in the history
The code has completely converged and can be moved to the common base.
  • Loading branch information
1uc committed Jul 31, 2024
1 parent 575a724 commit 6b4efff
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 79 deletions.
25 changes: 0 additions & 25 deletions src/codegen/codegen_coreneuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,31 +454,6 @@ void CodegenCoreneuronCppVisitor::print_function_procedure_helper(const ast::Blo
}


void CodegenCoreneuronCppVisitor::print_procedure(const ast::ProcedureBlock& node) {
print_function_procedure_helper(node);
}


void CodegenCoreneuronCppVisitor::print_function(const ast::FunctionBlock& node) {
auto name = node.get_node_name();

// name of return variable
std::string return_var;
if (info.function_uses_table(name)) {
return_var = "ret_f_" + name;
} else {
return_var = "ret_" + name;
}

// first rename return variable name
auto block = node.get_statement_block().get();
RenameVisitor v(name, return_var);
block->accept(v);

print_function_procedure_helper(node);
}


void CodegenCoreneuronCppVisitor::print_function_tables(const ast::FunctionTableBlock& node) {
auto name = node.get_node_name();
const auto& p = node.get_parameters();
Expand Down
14 changes: 0 additions & 14 deletions src/codegen/codegen_coreneuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,20 +371,6 @@ class CodegenCoreneuronCppVisitor: public CodegenCppVisitor {
void print_function_procedure_helper(const ast::Block& node) override;


/**
* Print NMODL procedure in target backend code
* \param node
*/
void print_procedure(const ast::ProcedureBlock& node) override;


/**
* Print NMODL function in target backend code
* \param node
*/
void print_function(const ast::FunctionBlock& node) override;


/**
* Print NMODL function_table in target backend code
* \param node
Expand Down
25 changes: 25 additions & 0 deletions src/codegen/codegen_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,31 @@ void CodegenCppVisitor::print_function_call(const FunctionCall& node) {
}


void CodegenCppVisitor::print_procedure(const ast::ProcedureBlock& node) {
print_function_procedure_helper(node);
}


void CodegenCppVisitor::print_function(const ast::FunctionBlock& node) {
auto name = node.get_node_name();

// name of return variable
std::string return_var;
if (info.function_uses_table(name)) {
return_var = "ret_f_" + name;
} else {
return_var = "ret_" + name;
}

// first rename return variable name
auto block = node.get_statement_block().get();
RenameVisitor v(name, return_var);
block->accept(v);

print_function_procedure_helper(node);
}


void CodegenCppVisitor::print_prcellstate_macros() const {
printer->add_line("#ifndef NRN_PRCELLSTATE");
printer->add_line("#define NRN_PRCELLSTATE 0");
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/codegen_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,14 +881,14 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor {
* Print NMODL procedure in target backend code
* \param node
*/
virtual void print_procedure(const ast::ProcedureBlock& node) = 0;
void print_procedure(const ast::ProcedureBlock& node);


/**
* Print NMODL function in target backend code
* \param node
*/
virtual void print_function(const ast::FunctionBlock& node) = 0;
void print_function(const ast::FunctionBlock& node);


/**
Expand Down
24 changes: 0 additions & 24 deletions src/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,30 +291,6 @@ void CodegenNeuronCppVisitor::print_function_procedure_helper(const ast::Block&
}


void CodegenNeuronCppVisitor::print_procedure(const ast::ProcedureBlock& node) {
print_function_procedure_helper(node);
}


void CodegenNeuronCppVisitor::print_function(const ast::FunctionBlock& node) {
auto name = node.get_node_name();

// name of return variable
std::string return_var;
if (info.function_uses_table(name)) {
return_var = "ret_f_" + name;
} else {
return_var = "ret_" + name;
}

// first rename return variable name
auto block = node.get_statement_block().get();
RenameVisitor v(name, return_var);
block->accept(v);

print_function_procedure_helper(node);
}

void CodegenNeuronCppVisitor::print_hoc_py_wrapper_function_body(
const ast::Block* function_or_procedure_block,
InterpreterWrapper wrapper_type) {
Expand Down
14 changes: 0 additions & 14 deletions src/codegen/codegen_neuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,6 @@ class CodegenNeuronCppVisitor: public CodegenCppVisitor {
void print_function_procedure_helper(const ast::Block& node) override;


/**
* Print NMODL procedure in target backend code
* \param node
*/
void print_procedure(const ast::ProcedureBlock& node) override;


/**
* Print NMODL function in target backend code
* \param node
*/
void print_function(const ast::FunctionBlock& node) override;


void print_hoc_py_wrapper_function_body(const ast::Block* function_or_procedure_block,
InterpreterWrapper wrapper_type);

Expand Down

0 comments on commit 6b4efff

Please sign in to comment.