Skip to content

Commit

Permalink
Move print_function_call to CodegenCppVisitor. (#1115)
Browse files Browse the repository at this point in the history
Additionally, adds stubs for `print_net_{send,move,event}_call` to
`CodegenNeuronCppVisitor`.
  • Loading branch information
1uc authored Dec 8, 2023
1 parent 1b60785 commit 7dbdd23
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 57 deletions.
37 changes: 0 additions & 37 deletions src/codegen/codegen_coreneuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,43 +507,6 @@ void CodegenCoreneuronCppVisitor::print_global_var_struct_decl() {
/****************************************************************************************/


void CodegenCoreneuronCppVisitor::print_function_call(const FunctionCall& node) {
const auto& name = node.get_node_name();
auto function_name = name;
if (defined_method(name)) {
function_name = method_name(name);
}

if (is_net_send(name)) {
print_net_send_call(node);
return;
}

if (is_net_move(name)) {
print_net_move_call(node);
return;
}

if (is_net_event(name)) {
print_net_event_call(node);
return;
}

const auto& arguments = node.get_arguments();
printer->add_text(function_name, '(');

if (defined_method(name)) {
printer->add_text(internal_method_arguments());
if (!arguments.empty()) {
printer->add_text(", ");
}
}

print_vector_elements(arguments, ", ");
printer->add_text(')');
}


void CodegenCoreneuronCppVisitor::print_top_verbatim_blocks() {
if (info.top_verbatim_blocks.empty()) {
return;
Expand Down
13 changes: 3 additions & 10 deletions src/codegen/codegen_coreneuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,6 @@ class CodegenCoreneuronCppVisitor: public CodegenCppVisitor {
/****************************************************************************************/


/**
* Print call to internal or external function
* \param node The AST node representing a function call
*/
void print_function_call(const ast::FunctionCall& node) override;


/**
* Print top level (global scope) verbatim blocks
*/
Expand Down Expand Up @@ -951,21 +944,21 @@ class CodegenCoreneuronCppVisitor: public CodegenCppVisitor {
* Print call to \c net\_send
* \param node The AST node representing the function call
*/
void print_net_send_call(const ast::FunctionCall& node);
void print_net_send_call(const ast::FunctionCall& node) override;


/**
* Print call to net\_move
* \param node The AST node representing the function call
*/
void print_net_move_call(const ast::FunctionCall& node);
void print_net_move_call(const ast::FunctionCall& node) override;


/**
* Print call to net\_event
* \param node The AST node representing the function call
*/
void print_net_event_call(const ast::FunctionCall& node);
void print_net_event_call(const ast::FunctionCall& node) override;


/**
Expand Down
36 changes: 36 additions & 0 deletions src/codegen/codegen_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,42 @@ bool CodegenCppVisitor::need_semicolon(const Statement& node) {
/* Main printing routines for code generation */
/****************************************************************************************/

void CodegenCppVisitor::print_function_call(const FunctionCall& node) {
const auto& name = node.get_node_name();
auto function_name = name;
if (defined_method(name)) {
function_name = method_name(name);
}

if (is_net_send(name)) {
print_net_send_call(node);
return;
}

if (is_net_move(name)) {
print_net_move_call(node);
return;
}

if (is_net_event(name)) {
print_net_event_call(node);
return;
}

const auto& arguments = node.get_arguments();
printer->add_text(function_name, '(');

if (defined_method(name)) {
printer->add_text(internal_method_arguments());
if (!arguments.empty()) {
printer->add_text(", ");
}
}

print_vector_elements(arguments, ", ");
printer->add_text(')');
}


void CodegenCppVisitor::print_prcellstate_macros() const {
printer->add_line("#ifndef NRN_PRCELLSTATE");
Expand Down
21 changes: 20 additions & 1 deletion src/codegen/codegen_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,27 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor {
* Print call to internal or external function
* \param node The AST node representing a function call
*/
virtual void print_function_call(const ast::FunctionCall& node) = 0;
virtual void print_function_call(const ast::FunctionCall& node);

/**
* Print call to \c net\_send
* \param node The AST node representing the function call
*/
virtual void print_net_send_call(const ast::FunctionCall& node) = 0;


/**
* Print call to net\_move
* \param node The AST node representing the function call
*/
virtual void print_net_move_call(const ast::FunctionCall& node) = 0;


/**
* Print call to net\_event
* \param node The AST node representing the function call
*/
virtual void print_net_event_call(const ast::FunctionCall& node) = 0;

/**
* Print function and procedures prototype declaration
Expand Down
18 changes: 12 additions & 6 deletions src/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ void CodegenNeuronCppVisitor::print_atomic_reduction_pragma() {
/****************************************************************************************/


/// TODO: Edit for NEURON
void CodegenNeuronCppVisitor::print_function_call(const FunctionCall& node) {
return;
}


/// TODO: Edit for NEURON
void CodegenNeuronCppVisitor::print_function_prototypes() {
if (info.functions.empty() && info.procedures.empty()) {
Expand Down Expand Up @@ -732,6 +726,18 @@ void CodegenNeuronCppVisitor::print_codegen_routines() {
codegen = false;
}

void CodegenNeuronCppVisitor::print_net_send_call(const ast::FunctionCall& node) {
throw std::runtime_error("Not implemented.");
}

void CodegenNeuronCppVisitor::print_net_move_call(const ast::FunctionCall& node) {
throw std::runtime_error("Not implemented.");
}

void CodegenNeuronCppVisitor::print_net_event_call(const ast::FunctionCall& node) {
throw std::runtime_error("Not implemented.");
}


/****************************************************************************************/
/* Overloaded visitor routines */
Expand Down
20 changes: 17 additions & 3 deletions src/codegen/codegen_neuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,24 @@ class CodegenNeuronCppVisitor: public CodegenCppVisitor {


/**
* Print call to internal or external function
* \param node The AST node representing a function call
* Print call to \c net\_send
* \param node The AST node representing the function call
*/
void print_function_call(const ast::FunctionCall& node) override;
void print_net_send_call(const ast::FunctionCall& node) override;


/**
* Print call to net\_move
* \param node The AST node representing the function call
*/
void print_net_move_call(const ast::FunctionCall& node) override;


/**
* Print call to net\_event
* \param node The AST node representing the function call
*/
void print_net_event_call(const ast::FunctionCall& node) override;


/**
Expand Down

0 comments on commit 7dbdd23

Please sign in to comment.