Skip to content

Commit

Permalink
Merge pull request #2438 from anutosh491/main
Browse files Browse the repository at this point in the history
Fixed ASR for test_gruntz.py
  • Loading branch information
certik authored Dec 6, 2023
2 parents 4150db6 + 085d66f commit 0a79bf5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/libasr/pass/pass_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -831,13 +831,15 @@ namespace LCompilers {
s_func_type->n_arg_types = arg_types.n;
s_func_type->m_return_var_type = nullptr;

Vec<ASR::stmt_t*> func_body;
func_body.reserve(al, x->n_body - 1);
for (size_t i=0; i< x->n_body - 1; i++) {
func_body.push_back(al, x->m_body[i]);
if (ASR::is_a<ASR::Return_t>(*x->m_body[x->n_body - 1])) {
Vec<ASR::stmt_t*> func_body;
func_body.reserve(al, x->n_body - 1);
for (size_t i=0; i< x->n_body - 1; i++) {
func_body.push_back(al, x->m_body[i]);
}
x->m_body = func_body.p;
x->n_body = func_body.n;
}
x->m_body = func_body.p;
x->n_body = func_body.n;
}
}
for (auto &item : x->m_symtab->get_scope()) {
Expand Down
21 changes: 19 additions & 2 deletions src/libasr/pass/replace_symbolic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,16 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor<ReplaceSymbolicVisi

ASR::ttype_t* f_signature= xx.m_function_signature;
ASR::FunctionType_t *f_type = ASR::down_cast<ASR::FunctionType_t>(f_signature);
ASR::ttype_t *type1 = ASRUtils::TYPE(ASR::make_CPtr_t(al, xx.base.base.loc));
ASR::ttype_t *CPtr_type = ASRUtils::TYPE(ASR::make_CPtr_t(al, xx.base.base.loc));
for (size_t i = 0; i < f_type->n_arg_types; ++i) {
if (f_type->m_arg_types[i]->type == ASR::ttypeType::SymbolicExpression) {
f_type->m_arg_types[i] = type1;
f_type->m_arg_types[i] = CPtr_type;
} else if (f_type->m_arg_types[i]->type == ASR::ttypeType::List) {
ASR::List_t* list = ASR::down_cast<ASR::List_t>(f_type->m_arg_types[i]);
if (list->m_type->type == ASR::ttypeType::SymbolicExpression){
ASR::ttype_t* list_type = ASRUtils::TYPE(ASR::make_List_t(al, xx.base.base.loc, CPtr_type));
f_type->m_arg_types[i] = list_type;
}
}
}

Expand Down Expand Up @@ -592,6 +598,17 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor<ReplaceSymbolicVisi
ASR::expr_t* function_call = process_attributes(xx.base.base.loc, xx.m_test);
xx.m_test = function_call;
}
} else if (ASR::is_a<ASR::LogicalNot_t>(*xx.m_test)) {
ASR::LogicalNot_t* logical_not = ASR::down_cast<ASR::LogicalNot_t>(xx.m_test);
if (ASR::is_a<ASR::IntrinsicScalarFunction_t>(*logical_not->m_arg)) {
ASR::IntrinsicScalarFunction_t* intrinsic_func = ASR::down_cast<ASR::IntrinsicScalarFunction_t>(logical_not->m_arg);
if (intrinsic_func->m_type->type == ASR::ttypeType::Logical) {
ASR::expr_t* function_call = process_attributes(xx.base.base.loc, logical_not->m_arg);
ASR::expr_t* new_logical_not = ASRUtils::EXPR(ASR::make_LogicalNot_t(al, xx.base.base.loc, function_call,
logical_not->m_type, logical_not->m_value));
xx.m_test = new_logical_not;
}
}
}
}

Expand Down

0 comments on commit 0a79bf5

Please sign in to comment.