Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh : Create physical string descriptor to be used with allocatable strings #4918

Merged
merged 26 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
61fdde4
create character type of descriptor type when type is allocatable and…
assem2002 Sep 25, 2024
716d8a0
Create return type of character with correct physical type
assem2002 Sep 25, 2024
9e25ff5
Change runtime function signature to utilize size and capacity member…
assem2002 Oct 8, 2024
1c6c2cf
Add stringPhysicalCast node to cast from DescriptorString to PointerS…
assem2002 Oct 8, 2024
c78a5ed
Create cast_string functions to check if the expr really needs to be …
assem2002 Oct 8, 2024
eb63d2b
Create the physical descriptorString + start utilizing its size and c…
assem2002 Oct 8, 2024
784bf86
Minor : use ndim initialized to 0 + add conditions if the string is p…
assem2002 Oct 8, 2024
f62b589
Deallocate string that's descriptorString
assem2002 Oct 8, 2024
41be24d
Create stringPhysicalCast visitor to cast between the 2 physicalStrin…
assem2002 Oct 8, 2024
be01e31
Always use stringDescriptor variable in the code base as pointer and …
assem2002 Oct 8, 2024
93f1f38
Add documentation for stringPhysicalType + stringPhysicalCast
assem2002 Oct 9, 2024
386e487
minor change in documentation
assem2002 Oct 9, 2024
8099c61
minor change in stringPhysicalType.md
assem2002 Oct 9, 2024
2a3431f
make sure to fetch internal character_t type
assem2002 Oct 9, 2024
e7c3937
check and Cast in associate node
assem2002 Oct 9, 2024
6a61294
minor comment removal
assem2002 Oct 9, 2024
7c0281c
Add associate test for testing descriptorString to be RHS
assem2002 Oct 9, 2024
688f01a
minor in stringPhysicalCast.md
assem2002 Oct 9, 2024
24fb6fc
Modify the docs : some examples and minor typos
assem2002 Oct 14, 2024
1c766c3
Use cast functions direclty (it doesn't check - we should check befor…
assem2002 Oct 14, 2024
e0a1371
minor : add assertions when passing an expression node to cast_string…
assem2002 Oct 14, 2024
0b8bd1f
Changes in documentation
assem2002 Oct 15, 2024
777edb2
Remove if condition (if you want to use cast node, you've to check it…
assem2002 Oct 15, 2024
7c0a6e5
Update reference tests
assem2002 Oct 15, 2024
5e64d08
don't cast string if it's an arg for 'present' intrinsic
assem2002 Oct 15, 2024
b20f84b
Merge branch 'main' into descriptor_string_FEEDBACK
certik Oct 31, 2024
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
Prev Previous commit
Next Next commit
Minor : use ndim initialized to 0 + add conditions if the string is p…
…hysical descriptor string
  • Loading branch information
assem2002 committed Oct 28, 2024
commit 784bf86b18f544c55786c8fd1511f08d326e124d
2 changes: 1 addition & 1 deletion src/libasr/asr_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2608,7 +2608,7 @@ static inline ASR::ttype_t* duplicate_type(Allocator& al, const ASR::ttype_t* t,
case ASR::ttypeType::Character: {
ASR::Character_t* tnew = ASR::down_cast<ASR::Character_t>(t);
t_ = ASRUtils::TYPE(ASR::make_Character_t(al, t->base.loc,
tnew->m_kind, tnew->m_len, tnew->m_len_expr, ASR::string_physical_typeType::PointerString));
tnew->m_kind, tnew->m_len, tnew->m_len_expr, tnew->m_physical_type));
break;
}
case ASR::ttypeType::StructType: {
Expand Down
6 changes: 6 additions & 0 deletions src/libasr/codegen/asr_to_fortran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,12 @@ class ASRToFortranVisitor : public ASR::BaseVisitor<ASRToFortranVisitor>
src = r;
}

void visit_StringPhysicalCast(const ASR::StringPhysicalCast_t &x) {
visit_expr(*x.m_arg);
}



// void visit_CPtrCompare(const ASR::CPtrCompare_t &x) {}

// void visit_SymbolicCompare(const ASR::SymbolicCompare_t &x) {}
Expand Down
11 changes: 6 additions & 5 deletions src/libasr/codegen/asr_to_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
ASR::ttype_t* curr_arg_m_a_type = ASRUtils::type_get_past_pointer(
ASRUtils::type_get_past_allocatable(
ASRUtils::expr_type(tmp_expr)));
llvm::Type* llvm_arg_type = llvm_utils->get_type_from_ttype_t_util(curr_arg_m_a_type, module.get());
size_t n_dims = ASRUtils::extract_n_dims_from_ttype(curr_arg_m_a_type);
curr_arg_m_a_type = ASRUtils::type_get_past_array(curr_arg_m_a_type);
if( n_dims == 0 ) {
Expand Down Expand Up @@ -2886,7 +2885,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
} else if(x.m_type->type == ASR::ttypeType::Pointer ||
x.m_type->type == ASR::ttypeType::Allocatable) {
ASR::dimension_t* m_dims = nullptr;
int n_dims = -1, a_kind = -1;
int n_dims = 0, a_kind = -1;
bool is_array_type = false, is_malloc_array_type = false, is_list = false;
llvm::Type* x_ptr = llvm_utils->get_type_from_ttype_t(
x.m_type, nullptr, x.m_storage, is_array_type,
Expand Down Expand Up @@ -3690,7 +3689,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
bool is_llvm_ptr = false;
if ( LLVM::is_llvm_pointer(*v->m_type) &&
!ASR::is_a<ASR::ClassType_t>(*ASRUtils::type_get_past_pointer(
ASRUtils::type_get_past_allocatable(v->m_type))) ) {
ASRUtils::type_get_past_allocatable(v->m_type))) &&
!ASRUtils::is_physical_descriptorString(v->m_type) ) {
is_llvm_ptr = true;
}
ptr = llvm_utils->CreateAlloca(*builder, type_, array_size,
Expand Down Expand Up @@ -8934,8 +8934,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
}
if( !ASR::is_a<ASR::CPtr_t>(*arg_type) &&
!(orig_arg && !LLVM::is_llvm_pointer(*orig_arg->m_type) &&
LLVM::is_llvm_pointer(*arg_type) &&
!ASRUtils::is_character(*orig_arg->m_type)) && !ASR::is_a<ASR::StructInstanceMember_t>(*x.m_args[i].m_value) ) {
LLVM::is_llvm_pointer(*arg_type) &&
!ASRUtils::is_character(*orig_arg->m_type) &&
ASRUtils::is_physical_descriptorString(arg_type)) && !ASR::is_a<ASR::StructInstanceMember_t>(*x.m_args[i].m_value) ) {
llvm::AllocaInst *target = llvm_utils->CreateAlloca(
target_type, nullptr, "call_arg_value");
if( ASR::is_a<ASR::Tuple_t>(*arg_type) ||
Expand Down
2 changes: 1 addition & 1 deletion src/libasr/codegen/c_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,7 @@ namespace BindPyUtils {
util_func_decls += indent + signature + ";\n";
std::string body = indent + signature + " {\n";
body += indent + tab + "char *s = (char*)PyUnicode_AsUTF8(pValue);\n";
body += indent + tab + "return _lfortran_str_copy(s, 1, 0);\n";
body += indent + tab + "return _lfortran_str_copy(s, 1, 0, -1, -1);\n";
body += indent + "}\n\n";
util_funcs += body;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libasr/codegen/llvm_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ namespace LCompilers {
bool is_array_type_local, is_malloc_array_type_local;
bool is_list_local;
ASR::dimension_t* m_dims_local;
int n_dims_local, a_kind_local;
int n_dims_local = 0, a_kind_local = 0;
return get_type_from_ttype_t(asr_type, nullptr, m_storage_local, is_array_type_local,
is_malloc_array_type_local, is_list_local,
m_dims_local, n_dims_local, a_kind_local, module, asr_abi);
Expand Down