Skip to content

Commit 20472f1

Browse files
committed
Implement list return in LLVM
1 parent a4443dc commit 20472f1

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/libasr/codegen/asr_to_llvm.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,6 +2603,22 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
26032603
return_type = tuple_api->get_tuple_type(type_code, llvm_el_types);
26042604
break;
26052605
}
2606+
case (ASR::ttypeType::List) : {
2607+
bool is_array_type = false, is_malloc_array_type = false;
2608+
bool is_list = true;
2609+
ASR::dimension_t *m_dims = nullptr;
2610+
ASR::storage_typeType m_storage = ASR::storage_typeType::Default;
2611+
int n_dims = 0, a_kind = -1;
2612+
ASR::List_t* asr_list = ASR::down_cast<ASR::List_t>(return_var_type0);
2613+
llvm::Type* el_llvm_type = get_type_from_ttype_t(asr_list->m_type, m_storage,
2614+
is_array_type,
2615+
is_malloc_array_type,
2616+
is_list, m_dims, n_dims,
2617+
a_kind);
2618+
std::string el_type_code = ASRUtils::get_type_code(asr_list->m_type);
2619+
return_type = list_api->get_list_type(el_llvm_type, el_type_code, a_kind);
2620+
break;
2621+
}
26062622
default :
26072623
LFORTRAN_ASSERT(false);
26082624
throw CodeGenError("Type not implemented");
@@ -2967,11 +2983,15 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
29672983
this->visit_expr(*x.m_value);
29682984
llvm::Value* value_list = tmp;
29692985
ptr_loads = ptr_loads_copy;
2970-
ASR::List_t* value_asr_list = ASR::down_cast<ASR::List_t>(
2971-
ASRUtils::expr_type(x.m_value));
2972-
std::string value_type_code = ASRUtils::get_type_code(value_asr_list->m_type);
2973-
list_api->list_deepcopy(value_list, target_list,
2974-
value_asr_list, *module);
2986+
if (ASR::is_a<ASR::FunctionCall_t>(*x.m_value)) {
2987+
builder->CreateStore(value_list, target_list);
2988+
} else {
2989+
ASR::List_t* value_asr_list = ASR::down_cast<ASR::List_t>(
2990+
ASRUtils::expr_type(x.m_value));
2991+
std::string value_type_code = ASRUtils::get_type_code(value_asr_list->m_type);
2992+
list_api->list_deepcopy(value_list, target_list,
2993+
value_asr_list, *module);
2994+
}
29752995
return ;
29762996
} else if( is_target_tuple && is_value_tuple ) {
29772997
uint64_t ptr_loads_copy = ptr_loads;

0 commit comments

Comments
 (0)