Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let list_slice : L.llvalue StringMap.t =
- let list_slice_ty m typ =
- let ltype = (ltype_of_typ typ) in
- let defName = (type_str typ) in
- let def = L.define_function ("list_slice" ^ defName) (L.function_type (ptr_list_t ltype) [| ptr_list_t ltype; i32_t; i32_t |]) the_module in
- let build = L.builder_at_end context (L.entry_block def) in
- let listPtrPtr = L.build_alloca (ptr_list_t ltype) "list_ptr_alloc" build in
- let _ = L.build_store (L.param def 0) listPtrPtr build in
- let idxPtr = L.build_alloca i32_t "idx_alloc" build in
- let idx = L.build_load idxPtr "idx_load" build in
- let _ = L.build_store (L.param def 1) idxPtr build in
- let listPtr = L.build_load listPtrPtr "list_ptr_ptr" build in
- let listArrayPtrPtr = L.build_struct_gep listPtr 2 "list_array_ptr" build in
- let listArrayPtr = L.build_load listArrayPtrPtr "array_load" build in
- let new_list_ptr_ptr = L.build_malloc (ptr_list_t ltype) n build in
- let _ = init_list build new_list_ptr_ptr ltype in
- let new_list_ptr = L.build_load new_list_ptr "new_list_ptr" build in
- let loop_cnt_ptr = L.build_alloca i32_t "loop_cnt" build in
- let _ = L.build_store (L.const_int i32_t 0) loop_cnt_ptr build in
- let loop_upper_bound = L.build_sub (L.param def 1) (L.param def 0) "loop_upper_bound" build in
- let loop_cond = L.build_icmp L.Icmp.Sle loop_cnt_ptr loop_upper_bound "cond" build in
- let loop_itr = L.build_add loop_cnt_ptr (L.const_int i32_t 1) "loop_itr" build in
- let loop_body = (* assign b[loop_cnt] = a[loop_cnt + i] *) in
- construct_for_loop;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement