Skip to content

Commit

Permalink
C: Generalize handing of extra codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
Smit-create committed Mar 3, 2023
1 parent 7155f68 commit 2be0570
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 86 deletions.
19 changes: 6 additions & 13 deletions src/libasr/codegen/asr_to_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ R"(
void visit_Assert(const ASR::Assert_t &x) {
std::string indent(indentation_level*indentation_spaces, ' ');
std::string out = indent;
tmp_src.clear();
bracket_open++;
if (x.m_msg) {
out += "ASSERT_MSG(";
visit_expr(*x.m_test);
Expand All @@ -1028,12 +1028,8 @@ R"(
visit_expr(*x.m_test);
out += src + ");\n";
}
src = "";
if (!tmp_src.empty()) {
for (auto &s: tmp_src) src += s;
}
src += out;
tmp_src.clear();
bracket_open--;
src = check_tmp_buffer() + out;
}

void visit_CPtrToPointer(const ASR::CPtrToPointer_t& x) {
Expand Down Expand Up @@ -1069,6 +1065,7 @@ R"(
void visit_Print(const ASR::Print_t &x) {
std::string indent(indentation_level*indentation_spaces, ' ');
std::string tmp_gen = indent + "printf(\"", out = "";
bracket_open++;
std::vector<std::string> v;
std::string separator;
if (x.m_separator) {
Expand All @@ -1093,11 +1090,6 @@ R"(
}
tmp_gen += ");\n";
out += tmp_gen;
if (ASR::is_a<ASR::ListConstant_t>(*x.m_values[i]) ||
ASR::is_a<ASR::TupleConstant_t>(*x.m_values[i])) {
out += src;
src = const_var_names[get_hash((ASR::asr_t*)x.m_values[i])];
}
tmp_gen = indent + "printf(\"";
v.clear();
std::string p_func = c_ds_api->get_print_func(value_type);
Expand Down Expand Up @@ -1129,8 +1121,9 @@ R"(
}
}
tmp_gen += ");\n";
bracket_open--;
out += tmp_gen;
src = out;
src = this->check_tmp_buffer() + out;
}

void visit_ArraySize(const ASR::ArraySize_t& x) {
Expand Down
Loading

0 comments on commit 2be0570

Please sign in to comment.