Skip to content

Commit 1610c7e

Browse files
committed
Added interface and inline implementations for following use cases,
1. Generalised equality check for two values 2. Generalised deepcopy support from source to destination
1 parent 98556df commit 1610c7e

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

src/libasr/codegen/llvm_utils.h

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,17 @@ namespace LFortran {
4949
llvm::IRBuilder<> &builder, llvm::Value* arg_size);
5050
llvm::Value* lfortran_realloc(llvm::LLVMContext &context, llvm::Module &module,
5151
llvm::IRBuilder<> &builder, llvm::Value* ptr, llvm::Value* arg_size);
52+
static inline bool is_llvm_struct(ASR::ttype_t* asr_type) {
53+
return ASR::is_a<ASR::Tuple_t>(*asr_type) ||
54+
ASR::is_a<ASR::List_t>(*asr_type) ||
55+
ASR::is_a<ASR::Derived_t>(*asr_type) ||
56+
ASR::is_a<ASR::Class_t>(*asr_type);
57+
}
5258
}
5359

60+
class LLVMList;
61+
class LLVMTuple;
62+
5463
class LLVMUtils {
5564

5665
private:
@@ -60,6 +69,9 @@ namespace LFortran {
6069

6170
public:
6271

72+
LLVMTuple* tuple_api;
73+
LLVMList* list_api;
74+
6375
LLVMUtils(llvm::LLVMContext& context,
6476
llvm::IRBuilder<>* _builder);
6577

@@ -78,6 +90,12 @@ namespace LFortran {
7890
llvm::Value* lfortran_str_cmp(llvm::Value* left_arg, llvm::Value* right_arg,
7991
std::string runtime_func_name, llvm::Module& module);
8092

93+
llvm::Value* is_equal_by_value(llvm::Value* left, llvm::Value* right,
94+
llvm::Module& module, ASR::ttype_t* asr_type);
95+
96+
void deepcopy(llvm::Value* src, llvm::Value* dest,
97+
ASR::ttype_t* asr_type, llvm::Module& module);
98+
8199
}; // LLVMUtils
82100

83101
class LLVMList {
@@ -98,7 +116,7 @@ namespace LFortran {
98116
public:
99117

100118
LLVMList(llvm::LLVMContext& context_, LLVMUtils* llvm_utils,
101-
llvm::IRBuilder<>* builder);
119+
llvm::IRBuilder<>* builder);
102120

103121
llvm::Type* get_list_type(llvm::Type* el_type, std::string& type_code,
104122
int32_t type_size);
@@ -114,29 +132,35 @@ namespace LFortran {
114132
llvm::Value* get_pointer_to_current_capacity(llvm::Value* list);
115133

116134
void list_deepcopy(llvm::Value* src, llvm::Value* dest,
117-
std::string& src_type_code,
135+
ASR::List_t* list_type,
118136
llvm::Module& module);
119137

120138
llvm::Value* read_item(llvm::Value* list, llvm::Value* pos,
121139
bool get_pointer=false);
122140

123141
llvm::Value* len(llvm::Value* list);
124142

143+
void write_item(llvm::Value* list, llvm::Value* pos,
144+
llvm::Value* item, ASR::ttype_t* asr_type,
145+
llvm::Module& module);
146+
125147
void write_item(llvm::Value* list, llvm::Value* pos,
126148
llvm::Value* item);
127149

128150
void append(llvm::Value* list, llvm::Value* item,
129-
llvm::Module& module, std::string& type_code);
151+
ASR::ttype_t* asr_type, llvm::Module& module);
130152

131153
void insert_item(llvm::Value* list, llvm::Value* pos,
132-
llvm::Value* item, llvm::Module& module,
133-
std::string& type_code);
154+
llvm::Value* item, ASR::ttype_t* asr_type,
155+
llvm::Module& module);
134156

135157
void remove(llvm::Value* list, llvm::Value* item,
136-
ASR::ttypeType item_type, llvm::Module& module);
158+
ASR::ttype_t* item_type, llvm::Module& module);
159+
160+
void list_clear(llvm::Value* list);
137161

138162
llvm::Value* find_item_position(llvm::Value* list,
139-
llvm::Value* item, ASR::ttypeType item_type,
163+
llvm::Value* item, ASR::ttype_t* item_type,
140164
llvm::Module& module);
141165
};
142166

@@ -167,7 +191,11 @@ namespace LFortran {
167191
bool get_pointer=false);
168192

169193
void tuple_deepcopy(llvm::Value* src, llvm::Value* dest,
170-
std::string& type_code);
194+
ASR::Tuple_t* type_code, llvm::Module& module);
195+
196+
llvm::Value* check_tuple_equality(llvm::Value* t1, llvm::Value* t2,
197+
ASR::Tuple_t* tuple_type, llvm::LLVMContext& context,
198+
llvm::IRBuilder<>* builder, llvm::Module& module);
171199
};
172200

173201
} // LFortran

0 commit comments

Comments
 (0)