Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4dba0b6

Browse files
committed
Use value when fast is enable
1 parent 128270c commit 4dba0b6

File tree

3 files changed

+157
-24
lines changed

3 files changed

+157
-24
lines changed

src/libasr/codegen/asr_to_c.cpp

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class ASRToCVisitor : public BaseCCPPVisitor<ASRToCVisitor>
3030

3131
int counter;
3232

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

972972
void visit_EnumStaticMember(const ASR::EnumStaticMember_t& x) {
973+
if (compiler_options.fast && x.m_value != nullptr) {
974+
visit_expr(*x.m_value);
975+
return;
976+
}
973977
ASR::Variable_t* enum_var = ASR::down_cast<ASR::Variable_t>(x.m_m);
974978
src = std::string(enum_var->m_name);
975979
}
976980

977981
void visit_EnumValue(const ASR::EnumValue_t& x) {
982+
if (compiler_options.fast && x.m_value != nullptr) {
983+
visit_expr(*x.m_value);
984+
return;
985+
}
978986
visit_expr(*x.m_v);
979987
}
980988

981989
void visit_EnumName(const ASR::EnumName_t& x) {
990+
if (compiler_options.fast && x.m_value != nullptr) {
991+
visit_expr(*x.m_value);
992+
return;
993+
}
982994
int64_t min_value = INT64_MAX;
983995
ASR::Enum_t* enum_t = ASR::down_cast<ASR::Enum_t>(x.m_enum_type);
984996
ASR::EnumType_t* enum_type = ASR::down_cast<ASR::EnumType_t>(enum_t->m_enum_type);
@@ -1127,6 +1139,10 @@ R"(
11271139
}
11281140

11291141
void visit_ArraySize(const ASR::ArraySize_t& x) {
1142+
if (compiler_options.fast && x.m_value != nullptr) {
1143+
visit_expr(*x.m_value);
1144+
return;
1145+
}
11301146
visit_expr(*x.m_v);
11311147
std::string var_name = src;
11321148
std::string args = "";
@@ -1144,6 +1160,10 @@ R"(
11441160
}
11451161

11461162
void visit_ArrayReshape(const ASR::ArrayReshape_t& x) {
1163+
if (compiler_options.fast && x.m_value != nullptr) {
1164+
visit_expr(*x.m_value);
1165+
return;
1166+
}
11471167
visit_expr(*x.m_array);
11481168
std::string array = src;
11491169
visit_expr(*x.m_shape);
@@ -1166,6 +1186,10 @@ R"(
11661186
}
11671187

11681188
void visit_ArrayBound(const ASR::ArrayBound_t& x) {
1189+
if (compiler_options.fast && x.m_value != nullptr) {
1190+
visit_expr(*x.m_value);
1191+
return;
1192+
}
11691193
visit_expr(*x.m_v);
11701194
std::string var_name = src;
11711195
std::string args = "";
@@ -1203,6 +1227,10 @@ R"(
12031227
}
12041228

12051229
void visit_ArrayItem(const ASR::ArrayItem_t &x) {
1230+
if (compiler_options.fast && x.m_value != nullptr) {
1231+
visit_expr(*x.m_value);
1232+
return;
1233+
}
12061234
this->visit_expr(*x.m_v);
12071235
std::string array = src;
12081236
std::string out = array;
@@ -1253,6 +1281,10 @@ R"(
12531281
}
12541282

12551283
void visit_StringItem(const ASR::StringItem_t& x) {
1284+
if (compiler_options.fast && x.m_value != nullptr) {
1285+
visit_expr(*x.m_value);
1286+
return;
1287+
}
12561288
this->visit_expr(*x.m_idx);
12571289
std::string idx = std::move(src);
12581290
this->visit_expr(*x.m_arg);
@@ -1261,6 +1293,10 @@ R"(
12611293
}
12621294

12631295
void visit_StringLen(const ASR::StringLen_t &x) {
1296+
if (compiler_options.fast && x.m_value != nullptr) {
1297+
visit_expr(*x.m_value);
1298+
return;
1299+
}
12641300
this->visit_expr(*x.m_arg);
12651301
src = "strlen(" + src + ")";
12661302
}
@@ -1276,7 +1312,7 @@ R"(
12761312
};
12771313

12781314
Result<std::string> asr_to_c(Allocator &al, ASR::TranslationUnit_t &asr,
1279-
diag::Diagnostics &diagnostics, Platform &platform,
1315+
diag::Diagnostics &diagnostics, CompilerOptions &co,
12801316
int64_t default_lower_bound)
12811317
{
12821318

@@ -1286,7 +1322,7 @@ Result<std::string> asr_to_c(Allocator &al, ASR::TranslationUnit_t &asr,
12861322
pass_replace_array_op(al, asr, pass_options);
12871323
pass_unused_functions(al, asr, pass_options);
12881324
pass_replace_class_constructor(al, asr, pass_options);
1289-
ASRToCVisitor v(diagnostics, platform, default_lower_bound);
1325+
ASRToCVisitor v(diagnostics, co, default_lower_bound);
12901326
try {
12911327
v.visit_asr((ASR::asr_t &)asr);
12921328
} catch (const CodeGenError &e) {

0 commit comments

Comments
 (0)