@@ -1056,19 +1056,19 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
1056
1056
return builder->CreateCall (fn, {str});
1057
1057
}
1058
1058
1059
- llvm::Value* lfortran_str_copy (llvm::Value* str, llvm::Value* idx1, llvm::Value* idx2 )
1059
+ llvm::Value* lfortran_str_item (llvm::Value* str, llvm::Value* idx1)
1060
1060
{
1061
- std::string runtime_func_name = " _lfortran_str_copy " ;
1061
+ std::string runtime_func_name = " _lfortran_str_item " ;
1062
1062
llvm::Function *fn = module ->getFunction (runtime_func_name);
1063
1063
if (!fn) {
1064
1064
llvm::FunctionType *function_type = llvm::FunctionType::get (
1065
1065
character_type, {
1066
- character_type, llvm::Type::getInt32Ty (context), llvm::Type::getInt32Ty (context)
1066
+ character_type, llvm::Type::getInt32Ty (context)
1067
1067
}, false );
1068
1068
fn = llvm::Function::Create (function_type,
1069
1069
llvm::Function::ExternalLinkage, runtime_func_name, *module );
1070
1070
}
1071
- return builder->CreateCall (fn, {str, idx1, idx2 });
1071
+ return builder->CreateCall (fn, {str, idx1});
1072
1072
}
1073
1073
1074
1074
llvm::Value* lfortran_str_slice (llvm::Value* str, llvm::Value* idx1, llvm::Value* idx2,
@@ -1827,7 +1827,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
1827
1827
std::vector<llvm::Value*> idx_vec = {idx};
1828
1828
p = CreateGEP (str, idx_vec);
1829
1829
} else {
1830
- p = lfortran_str_copy (str, idx , idx);
1830
+ p = lfortran_str_item (str, idx);
1831
1831
}
1832
1832
// TODO: Currently the string starts at the right location, but goes to the end of the original string.
1833
1833
// We have to allocate a new string, copy it and add null termination.
@@ -1910,7 +1910,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
1910
1910
// llvm::Value *p = CreateGEP(str, idx_vec);
1911
1911
// TODO: Currently the string starts at the right location, but goes to the end of the original string.
1912
1912
// We have to allocate a new string, copy it and add null termination.
1913
- llvm::Value *p = lfortran_str_copy (str, idx1, idx2);
1913
+ llvm::Value *step = llvm::ConstantInt::get (context, llvm::APInt (32 , 1 ));
1914
+ llvm::Value *present = llvm::ConstantInt::get (context, llvm::APInt (1 , 1 ));
1915
+ llvm::Value *p = lfortran_str_slice (str, idx1, idx2, step, present, present);
1914
1916
1915
1917
tmp = builder->CreateAlloca (character_type, nullptr );
1916
1918
builder->CreateStore (p, tmp);
@@ -4784,7 +4786,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
4784
4786
llvm::Value *idx = tmp;
4785
4787
this ->visit_expr_wrapper (x.m_arg , true );
4786
4788
llvm::Value *str = tmp;
4787
- tmp = lfortran_str_copy (str, idx , idx);
4789
+ tmp = lfortran_str_item (str, idx);
4788
4790
}
4789
4791
4790
4792
void visit_StringSection (const ASR::StringSection_t& x) {
0 commit comments