Skip to content

Commit

Permalink
Use value when fast is enable
Browse files Browse the repository at this point in the history
  • Loading branch information
Smit-create committed Mar 15, 2023
1 parent 128270c commit 4dba0b6
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 24 deletions.
44 changes: 40 additions & 4 deletions src/libasr/codegen/asr_to_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class ASRToCVisitor : public BaseCCPPVisitor<ASRToCVisitor>

int counter;

ASRToCVisitor(diag::Diagnostics &diag, Platform &platform,
ASRToCVisitor(diag::Diagnostics &diag, CompilerOptions &co,
int64_t default_lower_bound)
: BaseCCPPVisitor(diag, platform, false, false, true, default_lower_bound),
: BaseCCPPVisitor(diag, co.platform, co, false, false, true, default_lower_bound),
array_types_decls(std::string("\nstruct dimension_descriptor\n"
"{\n int32_t lower_bound, length;\n};\n")),
c_utils_functions{std::make_unique<CUtils::CUtilFunctions>()},
Expand Down Expand Up @@ -970,15 +970,27 @@ R"(
}

void visit_EnumStaticMember(const ASR::EnumStaticMember_t& x) {
if (compiler_options.fast && x.m_value != nullptr) {
visit_expr(*x.m_value);
return;
}
ASR::Variable_t* enum_var = ASR::down_cast<ASR::Variable_t>(x.m_m);
src = std::string(enum_var->m_name);
}

void visit_EnumValue(const ASR::EnumValue_t& x) {
if (compiler_options.fast && x.m_value != nullptr) {
visit_expr(*x.m_value);
return;
}
visit_expr(*x.m_v);
}

void visit_EnumName(const ASR::EnumName_t& x) {
if (compiler_options.fast && x.m_value != nullptr) {
visit_expr(*x.m_value);
return;
}
int64_t min_value = INT64_MAX;
ASR::Enum_t* enum_t = ASR::down_cast<ASR::Enum_t>(x.m_enum_type);
ASR::EnumType_t* enum_type = ASR::down_cast<ASR::EnumType_t>(enum_t->m_enum_type);
Expand Down Expand Up @@ -1127,6 +1139,10 @@ R"(
}

void visit_ArraySize(const ASR::ArraySize_t& x) {
if (compiler_options.fast && x.m_value != nullptr) {
visit_expr(*x.m_value);
return;
}
visit_expr(*x.m_v);
std::string var_name = src;
std::string args = "";
Expand All @@ -1144,6 +1160,10 @@ R"(
}

void visit_ArrayReshape(const ASR::ArrayReshape_t& x) {
if (compiler_options.fast && x.m_value != nullptr) {
visit_expr(*x.m_value);
return;
}
visit_expr(*x.m_array);
std::string array = src;
visit_expr(*x.m_shape);
Expand All @@ -1166,6 +1186,10 @@ R"(
}

void visit_ArrayBound(const ASR::ArrayBound_t& x) {
if (compiler_options.fast && x.m_value != nullptr) {
visit_expr(*x.m_value);
return;
}
visit_expr(*x.m_v);
std::string var_name = src;
std::string args = "";
Expand Down Expand Up @@ -1203,6 +1227,10 @@ R"(
}

void visit_ArrayItem(const ASR::ArrayItem_t &x) {
if (compiler_options.fast && x.m_value != nullptr) {
visit_expr(*x.m_value);
return;
}
this->visit_expr(*x.m_v);
std::string array = src;
std::string out = array;
Expand Down Expand Up @@ -1253,6 +1281,10 @@ R"(
}

void visit_StringItem(const ASR::StringItem_t& x) {
if (compiler_options.fast && x.m_value != nullptr) {
visit_expr(*x.m_value);
return;
}
this->visit_expr(*x.m_idx);
std::string idx = std::move(src);
this->visit_expr(*x.m_arg);
Expand All @@ -1261,6 +1293,10 @@ R"(
}

void visit_StringLen(const ASR::StringLen_t &x) {
if (compiler_options.fast && x.m_value != nullptr) {
visit_expr(*x.m_value);
return;
}
this->visit_expr(*x.m_arg);
src = "strlen(" + src + ")";
}
Expand All @@ -1276,7 +1312,7 @@ R"(
};

Result<std::string> asr_to_c(Allocator &al, ASR::TranslationUnit_t &asr,
diag::Diagnostics &diagnostics, Platform &platform,
diag::Diagnostics &diagnostics, CompilerOptions &co,
int64_t default_lower_bound)
{

Expand All @@ -1286,7 +1322,7 @@ Result<std::string> asr_to_c(Allocator &al, ASR::TranslationUnit_t &asr,
pass_replace_array_op(al, asr, pass_options);
pass_unused_functions(al, asr, pass_options);
pass_replace_class_constructor(al, asr, pass_options);
ASRToCVisitor v(diagnostics, platform, default_lower_bound);
ASRToCVisitor v(diagnostics, co, default_lower_bound);
try {
v.visit_asr((ASR::asr_t &)asr);
} catch (const CodeGenError &e) {
Expand Down
Loading

0 comments on commit 4dba0b6

Please sign in to comment.