Skip to content
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
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