Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove codegen flag from Codegen visitors #1118

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 9 additions & 36 deletions src/codegen/codegen_coreneuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -563,7 +563,7 @@ void CodegenCoreneuronCppVisitor::print_top_verbatim_blocks() {
}

printing_top_verbatim_blocks = false;
codegen = false;

print_namespace_start();
}

Expand All @@ -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());
Expand All @@ -584,7 +584,6 @@ void CodegenCoreneuronCppVisitor::print_function_prototypes() {
printer->add_text(';');
printer->add_newline();
}
codegen = false;
}


Expand Down Expand Up @@ -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)) {
Expand All @@ -880,8 +878,6 @@ void CodegenCoreneuronCppVisitor::print_function_procedure_helper(const ast::Blo
} else {
print_function_or_procedure(node, name);
}

codegen = false;
}


Expand Down Expand Up @@ -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 */");

Expand Down Expand Up @@ -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<ast::BABlock> ba_block;

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}


Expand All @@ -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());

Expand Down Expand Up @@ -2745,7 +2733,6 @@ void CodegenCoreneuronCppVisitor::print_watch_activate() {
printer->pop_block();
}
printer->pop_block();
codegen = false;
}


Expand All @@ -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);
Expand Down Expand Up @@ -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;
}


Expand Down Expand Up @@ -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);
Expand All @@ -3027,7 +3012,6 @@ void CodegenCoreneuronCppVisitor::print_net_init() {
}
}
printer->pop_block();
codegen = false;
printing_net_init = false;
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -3221,15 +3205,14 @@ void CodegenCoreneuronCppVisitor::print_net_receive_kernel() {
printer->pop_block();

printing_net_receive = false;
codegen = false;
}


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");
Expand All @@ -3256,7 +3239,6 @@ void CodegenCoreneuronCppVisitor::print_net_receive() {
printer->pop_block();
}
printing_net_receive = false;
codegen = false;
}


Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */");
Expand Down Expand Up @@ -3414,7 +3395,6 @@ void CodegenCoreneuronCppVisitor::print_nrn_state() {
print_kernel_data_present_annotation_block_end();

printer->pop_block();
codegen = false;
}


Expand Down Expand Up @@ -3583,7 +3563,6 @@ void CodegenCoreneuronCppVisitor::print_nrn_cur() {
return;
}

codegen = true;
if (info.conductances.empty()) {
print_nrn_current(*info.breakpoint_node);
}
Expand All @@ -3609,7 +3588,6 @@ void CodegenCoreneuronCppVisitor::print_nrn_cur() {

print_kernel_data_present_annotation_block_end();
printer->pop_block();
codegen = false;
}


Expand Down Expand Up @@ -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();
Expand All @@ -3729,7 +3706,6 @@ void CodegenCoreneuronCppVisitor::print_codegen_routines() {
print_check_table_thread_function();
print_mechanism_register();
print_namespace_end();
codegen = false;
}


Expand All @@ -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,
Expand Down
Loading
Loading