SHARE
TWEET

Untitled

a guest Dec 17th, 2018 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     let list_slice_ty m typ =
  2.        let ltype = (ltype_of_typ typ) in
  3.        let defName = (type_str typ) in
  4.        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
  5.        let build = L.builder_at_end context (L.entry_block def) in
  6.        let listPtrPtr = L.build_alloca (ptr_list_t ltype) "list_ptr_alloc" build in
  7.        let _ = L.build_store (L.param def 0) listPtrPtr build in
  8.        let idxPtr = L.build_alloca i32_t "idx_alloc" build in
  9.        let idx = L.build_load idxPtr "idx_load" build in
  10.        let _ = L.build_store (L.param def 1) idxPtr build in
  11.        let listPtr = L.build_load listPtrPtr "list_ptr_ptr" build in
  12.        let listArrayPtrPtr = L.build_struct_gep listPtr 2 "list_array_ptr" build in
  13.        let listArrayPtr = L.build_load listArrayPtrPtr "array_load" build in
  14.        let new_list_ptr_ptr = L.build_malloc (ptr_list_t ltype) n build in
  15.        let _ = init_list build new_list_ptr_ptr ltype in
  16.        let new_list_ptr = L.build_load new_list_ptr "new_list_ptr" build in
  17.        
  18.        (* loop counter init: 0 *)
  19.        let loop_cnt_ptr = L.build_alloca i32_t "loop_cnt" build in
  20.        let _ = L.build_store (L.const_int i32_t 0) loop_cnt_ptr build in
  21.        (* loop upper bound: j-i *)
  22.        let loop_upper_bound = L.build_sub (L.param def 1) (L.param def 0) "loop_upper_bound" build in
  23.        (* loop condition: cnt <= j-i *)
  24.        let loop_cond = L.build_icmp L.Icmp.Sle loop_cnt_ptr loop_upper_bound "cond" build in
  25.        (* loop iteration: cnt = cnt + 1 *)
  26.        let loop_itr = L.build_add loop_cnt_ptr (L.const_int i32_t 1) "loop_itr" build in
  27.        (* assignment: b[cnt] = a[cnt + i] *)
  28.        let loop_body = (* assign b[loop_cnt] = a[loop_cnt + i] *) in
  29.        construct_for_loop;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top