Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
LLVM 1.65 KB | None | 0 0
  1.   let list_slice : L.llvalue StringMap.t =
  2.     let list_slice_ty m typ =
  3.        let ltype = (ltype_of_typ typ) in
  4.        let defName = (type_str typ) in
  5.        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
  6.        let build = L.builder_at_end context (L.entry_block def) in
  7.        let listPtrPtr = L.build_alloca (ptr_list_t ltype) "list_ptr_alloc" build in
  8.        let _ = L.build_store (L.param def 0) listPtrPtr build in
  9.        let idxPtr = L.build_alloca i32_t "idx_alloc" build in
  10.        let idx = L.build_load idxPtr "idx_load" build in
  11.        let _ = L.build_store (L.param def 1) idxPtr build in
  12.        let listPtr = L.build_load listPtrPtr "list_ptr_ptr" build in
  13.        let listArrayPtrPtr = L.build_struct_gep listPtr 2 "list_array_ptr" build in
  14.        let listArrayPtr = L.build_load listArrayPtrPtr "array_load" build in
  15.        let new_list_ptr_ptr = L.build_malloc (ptr_list_t ltype) n build in
  16.        let _ = init_list build new_list_ptr_ptr ltype in
  17.        let new_list_ptr = L.build_load new_list_ptr "new_list_ptr" build in
  18.        
  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.        let loop_upper_bound = L.build_sub (L.param def 1) (L.param def 0) "loop_upper_bound" build in
  22.        let loop_cond = L.build_icmp L.Icmp.Sle loop_cnt_ptr loop_upper_bound "cond" build in
  23.        let loop_itr = L.build_add loop_cnt_ptr (L.const_int i32_t 1) "loop_itr" build in
  24.        let loop_body = (* assign b[loop_cnt] = a[loop_cnt + i] *) in
  25.        construct_for_loop;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement