diff --git a/src/codegen/codegen_coreneuron_cpp_visitor.cpp b/src/codegen/codegen_coreneuron_cpp_visitor.cpp index 126921c35b..750faa7d78 100644 --- a/src/codegen/codegen_coreneuron_cpp_visitor.cpp +++ b/src/codegen/codegen_coreneuron_cpp_visitor.cpp @@ -552,7 +552,7 @@ void CodegenCoreneuronCppVisitor::print_top_verbatim_blocks() { printer->add_newline(2); printer->add_line("using namespace coreneuron;"); - codegen = true; + printing_top_verbatim_blocks = true; for (const auto& block: info.top_blocks) { @@ -563,7 +563,7 @@ void CodegenCoreneuronCppVisitor::print_top_verbatim_blocks() { } printing_top_verbatim_blocks = false; - codegen = false; + print_namespace_start(); } @@ -572,7 +572,7 @@ void CodegenCoreneuronCppVisitor::print_function_prototypes() { if (info.functions.empty() && info.procedures.empty()) { return; } - codegen = true; + printer->add_newline(2); for (const auto& node: info.functions) { print_function_declaration(*node, node->get_node_name()); @@ -584,7 +584,6 @@ void CodegenCoreneuronCppVisitor::print_function_prototypes() { printer->add_text(';'); printer->add_newline(); } - codegen = false; } @@ -869,7 +868,6 @@ void CodegenCoreneuronCppVisitor::print_function_or_procedure(const ast::Block& void CodegenCoreneuronCppVisitor::print_function_procedure_helper(const ast::Block& node) { - codegen = true; auto name = node.get_node_name(); if (info.function_uses_table(name)) { @@ -880,8 +878,6 @@ void CodegenCoreneuronCppVisitor::print_function_procedure_helper(const ast::Blo } else { print_function_or_procedure(node, name); } - - codegen = false; } @@ -2523,7 +2519,6 @@ void CodegenCoreneuronCppVisitor::print_global_function_common_code( } void CodegenCoreneuronCppVisitor::print_nrn_init(bool skip_init_check) { - codegen = true; printer->add_newline(2); printer->add_line("/** initialize channel */"); @@ -2596,13 +2591,10 @@ void CodegenCoreneuronCppVisitor::print_nrn_init(bool skip_init_check) { if (skip_init_check) { printer->pop_block(); } - codegen = false; } void CodegenCoreneuronCppVisitor::print_before_after_block(const ast::Block* node, size_t block_id) { - codegen = true; - std::string ba_type; std::shared_ptr ba_block; @@ -2653,8 +2645,6 @@ void CodegenCoreneuronCppVisitor::print_before_after_block(const ast::Block* nod printer->pop_block(); printer->pop_block(); print_kernel_data_present_annotation_block_end(); - - codegen = false; } void CodegenCoreneuronCppVisitor::print_nrn_constructor() { @@ -2682,12 +2672,10 @@ void CodegenCoreneuronCppVisitor::print_nrn_destructor() { void CodegenCoreneuronCppVisitor::print_functors_definitions() { - codegen = true; for (const auto& functor_name: info.functor_names) { printer->add_newline(2); print_functor_definition(*functor_name.first); } - codegen = false; } @@ -2708,7 +2696,7 @@ void CodegenCoreneuronCppVisitor::print_watch_activate() { if (info.watch_statements.empty()) { return; } - codegen = true; + printer->add_newline(2); auto inst = fmt::format("{}* inst", instance_struct()); @@ -2745,7 +2733,6 @@ void CodegenCoreneuronCppVisitor::print_watch_activate() { printer->pop_block(); } printer->pop_block(); - codegen = false; } @@ -2757,7 +2744,7 @@ void CodegenCoreneuronCppVisitor::print_watch_check() { if (info.watch_statements.empty()) { return; } - codegen = true; + printer->add_newline(2); printer->add_line("/** routine to check watch activation */"); print_global_function_common_code(BlockType::Watch); @@ -2832,7 +2819,6 @@ void CodegenCoreneuronCppVisitor::print_watch_check() { print_send_event_move(); print_kernel_data_present_annotation_block_end(); printer->pop_block(); - codegen = false; } @@ -3007,7 +2993,6 @@ void CodegenCoreneuronCppVisitor::print_net_init() { // rename net_receive arguments used in the initial block of net_receive rename_net_receive_arguments(*info.net_receive_node, *node); - codegen = true; printing_net_init = true; auto args = "Point_process* pnt, int weight_index, double flag"; printer->add_newline(2); @@ -3027,7 +3012,6 @@ void CodegenCoreneuronCppVisitor::print_net_init() { } } printer->pop_block(); - codegen = false; printing_net_init = false; } @@ -3169,7 +3153,7 @@ void CodegenCoreneuronCppVisitor::print_net_receive_kernel() { if (!net_receive_required()) { return; } - codegen = true; + printing_net_receive = true; const auto node = info.net_receive_node; @@ -3221,7 +3205,6 @@ void CodegenCoreneuronCppVisitor::print_net_receive_kernel() { printer->pop_block(); printing_net_receive = false; - codegen = false; } @@ -3229,7 +3212,7 @@ void CodegenCoreneuronCppVisitor::print_net_receive() { if (!net_receive_required()) { return; } - codegen = true; + printing_net_receive = true; if (!info.artificial_cell) { const auto& name = method_name("net_receive"); @@ -3256,7 +3239,6 @@ void CodegenCoreneuronCppVisitor::print_net_receive() { printer->pop_block(); } printing_net_receive = false; - codegen = false; } @@ -3307,9 +3289,9 @@ void CodegenCoreneuronCppVisitor::print_derivimplicit_kernel(const Block& block) printer->add_line(slist1); printer->add_line(dlist1); printer->add_line(dlist2); - codegen = true; + print_statement_block(*block.get_statement_block(), false, false); - codegen = false; + printer->add_line("int counter = -1;"); printer->fmt_push_block("for (int i=0; i<{}; i++)", info.num_primes); printer->fmt_push_block("if (*deriv{}_advance(thread))", list_num); @@ -3370,7 +3352,6 @@ void CodegenCoreneuronCppVisitor::print_nrn_state() { if (!nrn_state_required()) { return; } - codegen = true; printer->add_newline(2); printer->add_line("/** update state */"); @@ -3414,7 +3395,6 @@ void CodegenCoreneuronCppVisitor::print_nrn_state() { print_kernel_data_present_annotation_block_end(); printer->pop_block(); - codegen = false; } @@ -3583,7 +3563,6 @@ void CodegenCoreneuronCppVisitor::print_nrn_cur() { return; } - codegen = true; if (info.conductances.empty()) { print_nrn_current(*info.breakpoint_node); } @@ -3609,7 +3588,6 @@ void CodegenCoreneuronCppVisitor::print_nrn_cur() { print_kernel_data_present_annotation_block_end(); printer->pop_block(); - codegen = false; } @@ -3706,7 +3684,6 @@ void CodegenCoreneuronCppVisitor::print_compute_functions() { void CodegenCoreneuronCppVisitor::print_codegen_routines() { - codegen = true; print_backend_info(); print_headers_include(); print_namespace_begin(); @@ -3729,7 +3706,6 @@ void CodegenCoreneuronCppVisitor::print_codegen_routines() { print_check_table_thread_function(); print_mechanism_register(); print_namespace_end(); - codegen = false; } @@ -3739,9 +3715,6 @@ void CodegenCoreneuronCppVisitor::print_codegen_routines() { void CodegenCoreneuronCppVisitor::visit_derivimplicit_callback(const ast::DerivimplicitCallback& node) { - if (!codegen) { - return; - } printer->fmt_line("{}_{}({});", node.get_node_to_solve()->get_node_name(), info.mod_suffix, diff --git a/src/codegen/codegen_cpp_visitor.cpp b/src/codegen/codegen_cpp_visitor.cpp index 2a2c95bff8..d117b5bdba 100644 --- a/src/codegen/codegen_cpp_visitor.cpp +++ b/src/codegen/codegen_cpp_visitor.cpp @@ -348,9 +348,6 @@ extern const std::regex regex_special_chars{R"([-[\]{}()*+?.,\^$|#\s])"}; void CodegenCppVisitor::visit_string(const String& node) { - if (!codegen) { - return; - } std::string name = node.eval(); if (enable_variable_name_lookup) { name = get_variable_name(name); @@ -360,42 +357,27 @@ void CodegenCppVisitor::visit_string(const String& node) { void CodegenCppVisitor::visit_integer(const Integer& node) { - if (!codegen) { - return; - } const auto& value = node.get_value(); printer->add_text(std::to_string(value)); } void CodegenCppVisitor::visit_float(const Float& node) { - if (!codegen) { - return; - } printer->add_text(format_float_string(node.get_value())); } void CodegenCppVisitor::visit_double(const Double& node) { - if (!codegen) { - return; - } printer->add_text(format_double_string(node.get_value())); } void CodegenCppVisitor::visit_boolean(const Boolean& node) { - if (!codegen) { - return; - } printer->add_text(std::to_string(static_cast(node.eval()))); } void CodegenCppVisitor::visit_name(const Name& node) { - if (!codegen) { - return; - } node.visit_children(*this); } @@ -414,9 +396,6 @@ void CodegenCppVisitor::visit_prime_name(const PrimeName& /* node */) { * \todo : Validate how @ is being handled in neuron implementation */ void CodegenCppVisitor::visit_var_name(const VarName& node) { - if (!codegen) { - return; - } const auto& name = node.get_name(); const auto& at_index = node.get_at(); const auto& index = node.get_index(); @@ -436,9 +415,6 @@ void CodegenCppVisitor::visit_var_name(const VarName& node) { void CodegenCppVisitor::visit_indexed_name(const IndexedName& node) { - if (!codegen) { - return; - } node.get_name()->accept(*this); printer->add_text("["); printer->add_text("static_cast("); @@ -449,18 +425,12 @@ void CodegenCppVisitor::visit_indexed_name(const IndexedName& node) { void CodegenCppVisitor::visit_local_list_statement(const LocalListStatement& node) { - if (!codegen) { - return; - } printer->add_text(local_var_type(), ' '); print_vector_elements(node.get_variables(), ", "); } void CodegenCppVisitor::visit_if_statement(const IfStatement& node) { - if (!codegen) { - return; - } printer->add_text("if ("); node.get_condition()->accept(*this); printer->add_text(") "); @@ -474,9 +444,6 @@ void CodegenCppVisitor::visit_if_statement(const IfStatement& node) { void CodegenCppVisitor::visit_else_if_statement(const ElseIfStatement& node) { - if (!codegen) { - return; - } printer->add_text(" else if ("); node.get_condition()->accept(*this); printer->add_text(") "); @@ -485,9 +452,6 @@ void CodegenCppVisitor::visit_else_if_statement(const ElseIfStatement& node) { void CodegenCppVisitor::visit_else_statement(const ElseStatement& node) { - if (!codegen) { - return; - } printer->add_text(" else "); node.visit_children(*this); } @@ -502,9 +466,6 @@ void CodegenCppVisitor::visit_while_statement(const WhileStatement& node) { void CodegenCppVisitor::visit_from_statement(const ast::FromStatement& node) { - if (!codegen) { - return; - } auto name = node.get_node_name(); const auto& from = node.get_from(); const auto& to = node.get_to(); @@ -526,9 +487,6 @@ void CodegenCppVisitor::visit_from_statement(const ast::FromStatement& node) { void CodegenCppVisitor::visit_paren_expression(const ParenExpression& node) { - if (!codegen) { - return; - } printer->add_text("("); node.get_expression()->accept(*this); printer->add_text(")"); @@ -536,9 +494,6 @@ void CodegenCppVisitor::visit_paren_expression(const ParenExpression& node) { void CodegenCppVisitor::visit_binary_expression(const BinaryExpression& node) { - if (!codegen) { - return; - } auto op = node.get_op().eval(); const auto& lhs = node.get_lhs(); const auto& rhs = node.get_rhs(); @@ -557,17 +512,11 @@ void CodegenCppVisitor::visit_binary_expression(const BinaryExpression& node) { void CodegenCppVisitor::visit_binary_operator(const BinaryOperator& node) { - if (!codegen) { - return; - } printer->add_text(node.eval()); } void CodegenCppVisitor::visit_unary_operator(const UnaryOperator& node) { - if (!codegen) { - return; - } printer->add_text(" " + node.eval()); } @@ -578,26 +527,16 @@ void CodegenCppVisitor::visit_unary_operator(const UnaryOperator& node) { * false. Hence we visit children even if code generation is false. */ void CodegenCppVisitor::visit_statement_block(const StatementBlock& node) { - if (!codegen) { - node.visit_children(*this); - return; - } print_statement_block(node); } void CodegenCppVisitor::visit_function_call(const FunctionCall& node) { - if (!codegen) { - return; - } print_function_call(node); } void CodegenCppVisitor::visit_verbatim(const Verbatim& node) { - if (!codegen) { - return; - } const auto& text = node.get_statement()->eval(); const auto& result = process_verbatim_text(text); diff --git a/src/codegen/codegen_cpp_visitor.hpp b/src/codegen/codegen_cpp_visitor.hpp index 3bff88bacb..6aa3b4d01b 100644 --- a/src/codegen/codegen_cpp_visitor.hpp +++ b/src/codegen/codegen_cpp_visitor.hpp @@ -253,12 +253,6 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { std::vector codegen_global_variables; - /** - * Flag to indicate if visitor should print the visited nodes - */ - bool codegen = false; - - /** * Variable name should be converted to instance name (but not for function arguments) */ diff --git a/src/codegen/codegen_neuron_cpp_visitor.cpp b/src/codegen/codegen_neuron_cpp_visitor.cpp index c89b62083d..f4488038bc 100644 --- a/src/codegen/codegen_neuron_cpp_visitor.cpp +++ b/src/codegen/codegen_neuron_cpp_visitor.cpp @@ -482,7 +482,6 @@ void CodegenNeuronCppVisitor::print_global_function_common_code(BlockType type, void CodegenNeuronCppVisitor::print_nrn_init(bool skip_init_check) { - codegen = true; printer->add_newline(2); printer->add_line("/** initialize channel */"); @@ -490,8 +489,6 @@ void CodegenNeuronCppVisitor::print_nrn_init(bool skip_init_check) { "static void {}(_nrn_model_sorted_token const& _sorted_token, NrnThread* _nt, Memb_list* " "_ml_arg, int _type) {{}}", method_name(naming::NRN_INIT_METHOD)); - - codegen = false; } @@ -538,7 +535,7 @@ void CodegenNeuronCppVisitor::print_nrn_state() { if (!nrn_state_required()) { return; } - codegen = true; + printer->add_newline(2); printer->fmt_line( @@ -547,8 +544,6 @@ void CodegenNeuronCppVisitor::print_nrn_state() { method_name(naming::NRN_STATE_METHOD)); /// TODO: Fill in - - codegen = false; } @@ -714,7 +709,6 @@ void CodegenNeuronCppVisitor::print_compute_functions() { /// TODO: Edit for NEURON void CodegenNeuronCppVisitor::print_codegen_routines() { - codegen = true; print_backend_info(); print_headers_include(); print_macro_definitions(); @@ -729,7 +723,6 @@ void CodegenNeuronCppVisitor::print_codegen_routines() { print_sdlists_init(true); print_mechanism_register(); print_namespace_end(); - codegen = false; }