text stringlengths 0 601k |
|---|
let mut_from_env env ptr = match env . environment_param with | None -> Asttypes . Mutable | Some environment_param -> match ptr with | Cvar ptr -> if V . same environment_param ptr then Asttypes . Immutable else Asttypes . Mutable | _ -> Asttypes . Mutable |
let get_field env ptr n dbg = let mut = mut_from_env env ptr in get_field_gen mut ptr n dbg |
type rhs_kind = | RHS_block of int | RHS_infix of { blocksize : int ; offset : int } | RHS_floatblock of int | RHS_nonrec ; ; |
let rec expr_size env = function | Uvar id -> begin try V . find_same id env with Not_found -> RHS_nonrec end | Uclosure ( fundecls , clos_vars ) -> RHS_block ( fundecls_size fundecls + List . length clos_vars ) | Ulet ( _str , _kind , id , exp , body ) -> expr_size ( V . add ( VP . var id ) ( expr_size env exp ) env )... |
let transl_constant dbg = function | Uconst_int n -> int_const dbg n | Uconst_ref ( label , def_opt ) -> Option . iter ( fun def -> Cmmgen_state . add_structured_constant label def ) def_opt ; Cconst_symbol ( label , dbg ) |
let emit_constant cst cont = match cst with | Uconst_int n -> cint_const n :: cont | Uconst_ref ( sym , _ ) -> Csymbol_address sym :: cont |
let emit_structured_constant ( ( _sym , is_global ) as symb ) cst cont = match cst with | Uconst_float s -> emit_float_constant symb s cont | Uconst_string s -> emit_string_constant symb s cont | Uconst_int32 n -> emit_int32_constant symb n cont | Uconst_int64 n -> emit_int64_constant symb n cont | Uconst_nativeint n -... |
let box_int_constant sym bi n = match bi with Pnativeint -> emit_nativeint_constant ( sym , Local ) n [ ] | Pint32 -> let n = Nativeint . to_int32 n in emit_int32_constant ( sym , Local ) n [ ] | Pint64 -> let n = Int64 . of_nativeint n in emit_int64_constant ( sym , Local ) n [ ] |
let box_int dbg bi mode arg = match arg with | Cconst_int ( n , _ ) -> let sym = Compilenv . new_const_symbol ( ) in let data_items = box_int_constant sym bi ( Nativeint . of_int n ) in Cmmgen_state . add_data_items data_items ; Cconst_symbol ( sym , dbg ) | Cconst_natint ( n , _ ) -> let sym = Compilenv . new_const_sy... |
let typ_of_boxed_number = function | Boxed_float _ -> Cmm . typ_float | Boxed_integer ( Pint64 , _ , _ ) when size_int = 4 -> [ | Int ; Int ] | | Boxed_integer _ -> Cmm . typ_int |
let equal_unboxed_integer ui1 ui2 = match ui1 , ui2 with | Pnativeint , Pnativeint -> true | Pint32 , Pint32 -> true | Pint64 , Pint64 -> true | _ , _ -> false |
let equal_boxed_number bn1 bn2 = match bn1 , bn2 with | Boxed_float _ , Boxed_float _ -> true | Boxed_integer ( ui1 , m , _ ) , Boxed_integer ( ui2 , m ' , _ ) -> equal_unboxed_integer ui1 ui2 && Lambda . eq_mode m m ' | _ , _ -> false |
let box_number bn arg = match bn with | Boxed_float ( m , dbg ) -> box_float dbg m arg | Boxed_integer ( bi , m , dbg ) -> box_int dbg bi m arg |
let unbox_number dbg bn arg = match bn with | Boxed_float ( _ , dbg ) -> unbox_float dbg arg | Boxed_integer ( Pint32 , _ , _ ) -> low_32 dbg ( unbox_int dbg Pint32 arg ) | Boxed_integer ( bi , _ , _ ) -> unbox_int dbg bi arg |
type unboxed_number_kind = No_unboxing | Boxed of boxed_number * bool | No_result |
let join_unboxed_number_kind ~ strict k1 k2 = match k1 , k2 with | Boxed ( b1 , c1 ) , Boxed ( b2 , c2 ) when equal_boxed_number b1 b2 -> Boxed ( b1 , c1 && c2 ) | No_result , k | k , No_result -> k | No_unboxing , k | k , No_unboxing when not strict -> k | _ , _ -> No_unboxing |
let is_unboxed_number_cmm ~ strict cmm = let r = ref No_result in let notify k = r := join_unboxed_number_kind ~ strict ! r k in let rec aux = function | Cop ( Calloc mode , [ Cconst_natint ( hdr , _ ) ; _ ] , dbg ) when Nativeint . equal hdr float_header -> notify ( Boxed ( Boxed_float ( mode , dbg ) , false ) ) | Cop... |
let rec transl env e = match e with Uvar id -> begin match is_unboxed_id id env with | None -> Cvar id | Some ( unboxed_id , bn ) -> box_number bn ( Cvar unboxed_id ) end | Uconst sc -> transl_constant Debuginfo . none sc | Uclosure ( fundecls , [ ] ) -> let sym = Compilenv . new_const_symbol ( ) in Cmmgen_state . add_... |
let transl_function f = let body = f . body in let cmm_body = let env = create_env ~ environment_param : f . env in if ! Clflags . afl_instrument then Afl_instrument . instrument_function ( transl env body ) f . dbg else transl env body in let fun_codegen_options = if ! Clflags . optimize_for_speed then [ ] else [ Redu... |
let rec transl_all_functions already_translated cont = match Cmmgen_state . next_function ( ) with | None -> cont , already_translated | Some f -> let sym = f . label in if String . Set . mem sym already_translated then transl_all_functions already_translated cont else begin transl_all_functions ( String . Set . add sy... |
let emit_constant_table symb elems = cdefine_symbol symb @ elems |
let transl_clambda_constants ( constants : Clambda . preallocated_constant list ) cont = let c = ref cont in let emit_clambda_constant symbol global cst = let cst = emit_structured_constant ( symbol , global ) cst [ ] in c := ( Cdata cst ) :: ! c in List . iter ( fun { symbol ; exported ; definition = cst ; provenance ... |
let emit_cmm_data_items_for_constants cont = let c = ref cont in String . Map . iter ( fun symbol ( cst : Cmmgen_state . constant ) -> match cst with | Const_closure ( global , fundecls , clos_vars ) -> let cmm = emit_constant_closure ( symbol , global ) fundecls ( List . fold_right emit_constant clos_vars [ ] ) [ ] in... |
let transl_all_functions cont = let rec aux already_translated cont translated_functions = if Cmmgen_state . no_more_functions ( ) then cont , translated_functions else let translated_functions , already_translated = transl_all_functions already_translated translated_functions in aux already_translated cont translated_... |
let compunit ( ulam , preallocated_blocks , constants ) = assert ( Cmmgen_state . no_more_functions ( ) ) ; let dbg = Debuginfo . none in Cmmgen_state . set_structured_constants constants ; let init_code = if ! Clflags . afl_instrument then Afl_instrument . instrument_initialiser ( transl empty_env ulam ) ( fun ( ) -> ... |
type is_global = Global | Local |
type constant = | Const_closure of is_global * Clambda . ufunction list * Clambda . uconstant list | Const_table of is_global * Cmm . data_item list |
type t = { mutable constants : constant S . Map . t ; mutable data_items : Cmm . data_item list list ; structured_constants : ( string , Clambda . ustructured_constant ) Hashtbl . t ; functions : Clambda . ufunction Queue . t ; } |
let empty = { constants = S . Map . empty ; data_items = [ ] ; functions = Queue . create ( ) ; structured_constants = Hashtbl . create 16 ; } |
let add_constant sym cst = state . constants <- S . Map . add sym cst state . constants |
let add_data_items items = state . data_items <- items :: state . data_items |
let add_function func = Queue . add func state . functions |
let get_and_clear_constants ( ) = let constants = state . constants in state . constants <- S . Map . empty ; constants |
let get_and_clear_data_items ( ) = let data_items = List . concat ( List . rev state . data_items ) in state . data_items <- [ ] ; data_items |
let next_function ( ) = match Queue . take state . functions with | exception Queue . Empty -> None | func -> Some func |
let no_more_functions ( ) = Queue . is_empty state . functions |
let set_structured_constants l = Hashtbl . clear state . structured_constants ; List . iter ( fun ( c : Clambda . preallocated_constant ) -> Hashtbl . add state . structured_constants c . symbol c . definition ) l |
let add_structured_constant sym cst = Hashtbl . replace state . structured_constants sym cst |
let get_structured_constant s = Hashtbl . find_opt state . structured_constants s |
let structured_constant_of_sym s = match Compilenv . structured_constant_of_symbol s with | None -> get_structured_constant s | Some _ as r -> r |
let bind name arg fn = match arg with Cvar _ | Cconst_int _ | Cconst_natint _ | Cconst_symbol _ -> fn arg | _ -> let id = V . create_local name in Clet ( VP . create id , arg , fn ( Cvar id ) ) |
let bind_load name arg fn = match arg with | Cop ( Cload _ , [ Cvar _ ] , _ ) -> fn arg | _ -> bind name arg fn |
let bind_nonvar name arg fn = match arg with Cconst_int _ | Cconst_natint _ | Cconst_symbol _ -> fn arg | _ -> let id = V . create_local name in Clet ( VP . create id , arg , fn ( Cvar id ) ) |
let caml_black = Nativeint . shift_left ( Nativeint . of_int 3 ) 8 |
let caml_local = Nativeint . shift_left ( Nativeint . of_int 2 ) 8 |
let floatarray_tag dbg = Cconst_int ( Obj . double_array_tag , dbg ) |
let block_header tag sz = Nativeint . add ( Nativeint . shift_left ( Nativeint . of_int sz ) 10 ) ( Nativeint . of_int tag ) |
let black_block_header tag sz = Nativeint . logor ( block_header tag sz ) caml_black |
let local_block_header tag sz = Nativeint . logor ( block_header tag sz ) caml_local |
let white_closure_header sz = block_header Obj . closure_tag sz |
let black_closure_header sz = black_block_header Obj . closure_tag sz |
let local_closure_header sz = local_block_header Obj . closure_tag sz |
let infix_header ofs = block_header Obj . infix_tag ofs |
let float_header = block_header Obj . double_tag ( size_float / size_addr ) |
let float_local_header = local_block_header Obj . double_tag ( size_float / size_addr ) |
let floatarray_header len = assert ( len >= 0 ) ; if len = 0 then block_header 0 0 else block_header Obj . double_array_tag ( len * size_float / size_addr ) |
let string_header len = block_header Obj . string_tag ( ( len + size_addr ) / size_addr ) |
let boxedint32_header = block_header Obj . custom_tag 2 |
let boxedint64_header = block_header Obj . custom_tag ( 1 + 8 / size_addr ) |
let boxedintnat_header = block_header Obj . custom_tag 2 |
let boxedint32_local_header = local_block_header Obj . custom_tag 2 |
let boxedint64_local_header = local_block_header Obj . custom_tag ( 1 + 8 / size_addr ) |
let boxedintnat_local_header = local_block_header Obj . custom_tag 2 |
let pos_arity_in_closinfo = 8 * size_addr - 8 |
let closure_info ~ arity ~ startenv = let arity = match arity with | Lambda . Tupled , n -> - n | Lambda . Curried _ , n -> n in assert ( - 128 <= arity && arity <= 127 ) ; assert ( 0 <= startenv && startenv < 1 lsl ( pos_arity_in_closinfo - 1 ) ) ; Nativeint . ( add ( shift_left ( of_int arity ) pos_arity_in_closinfo ... |
let alloc_float_header mode dbg = match mode with | Lambda . Alloc_heap -> Cconst_natint ( float_header , dbg ) | Lambda . Alloc_local -> Cconst_natint ( float_local_header , dbg ) |
let alloc_floatarray_header len dbg = Cconst_natint ( floatarray_header len , dbg ) |
let alloc_closure_header ~ mode sz dbg = match ( mode : Lambda . alloc_mode ) with | Alloc_heap -> Cconst_natint ( white_closure_header sz , dbg ) | Alloc_local -> Cconst_natint ( local_closure_header sz , dbg ) |
let alloc_infix_header ofs dbg = Cconst_natint ( infix_header ofs , dbg ) |
let alloc_closure_info ~ arity ~ startenv dbg = Cconst_natint ( closure_info ~ arity ~ startenv , dbg ) |
let alloc_boxedint32_header mode dbg = match mode with | Lambda . Alloc_heap -> Cconst_natint ( boxedint32_header , dbg ) | Lambda . Alloc_local -> Cconst_natint ( boxedint32_local_header , dbg ) |
let alloc_boxedint64_header mode dbg = match mode with | Lambda . Alloc_heap -> Cconst_natint ( boxedint64_header , dbg ) | Lambda . Alloc_local -> Cconst_natint ( boxedint64_local_header , dbg ) |
let alloc_boxedintnat_header mode dbg = match mode with | Lambda . Alloc_heap -> Cconst_natint ( boxedintnat_header , dbg ) | Lambda . Alloc_local -> Cconst_natint ( boxedintnat_local_header , dbg ) |
let max_repr_int = max_int asr 1 |
let min_repr_int = min_int asr 1 |
let int_const dbg n = if n <= max_repr_int && n >= min_repr_int then Cconst_int ( ( n lsl 1 ) + 1 , dbg ) else Cconst_natint ( Nativeint . add ( Nativeint . shift_left ( Nativeint . of_int n ) 1 ) 1n , dbg ) |
let natint_const_untagged dbg n = if n > Nativeint . of_int max_int || n < Nativeint . of_int min_int then Cconst_natint ( n , dbg ) else Cconst_int ( Nativeint . to_int n , dbg ) |
let cint_const n = Cint ( Nativeint . add ( Nativeint . shift_left ( Nativeint . of_int n ) 1 ) 1n ) |
let targetint_const n = Targetint . add ( Targetint . shift_left ( Targetint . of_int n ) 1 ) Targetint . one |
let add_no_overflow n x c dbg = let d = n + x in if d = 0 then c else Cop ( Caddi , [ c ; Cconst_int ( d , dbg ) ] , dbg ) |
let rec add_const c n dbg = if n = 0 then c else match c with | Cconst_int ( x , _ ) when Misc . no_overflow_add x n -> Cconst_int ( x + n , dbg ) | Cop ( Caddi , [ Cconst_int ( x , _ ) ; c ] , _ ) when Misc . no_overflow_add n x -> add_no_overflow n x c dbg | Cop ( Caddi , [ c ; Cconst_int ( x , _ ) ] , _ ) when Misc ... |
let incr_int c dbg = add_const c 1 dbg |
let decr_int c dbg = add_const c ( - 1 ) dbg |
let rec add_int c1 c2 dbg = match ( c1 , c2 ) with | ( Cconst_int ( n , _ ) , c ) | ( c , Cconst_int ( n , _ ) ) -> add_const c n dbg | ( Cop ( Caddi , [ c1 ; Cconst_int ( n1 , _ ) ] , _ ) , c2 ) -> add_const ( add_int c1 c2 dbg ) n1 dbg | ( c1 , Cop ( Caddi , [ c2 ; Cconst_int ( n2 , _ ) ] , _ ) ) -> add_const ( add_i... |
let rec sub_int c1 c2 dbg = match ( c1 , c2 ) with | ( c1 , Cconst_int ( n2 , _ ) ) when n2 <> min_int -> add_const c1 ( - n2 ) dbg | ( c1 , Cop ( Caddi , [ c2 ; Cconst_int ( n2 , _ ) ] , _ ) ) when n2 <> min_int -> add_const ( sub_int c1 c2 dbg ) ( - n2 ) dbg | ( Cop ( Caddi , [ c1 ; Cconst_int ( n1 , _ ) ] , _ ) , c2... |
let rec lsl_int c1 c2 dbg = match ( c1 , c2 ) with | ( Cop ( Clsl , [ c ; Cconst_int ( n1 , _ ) ] , _ ) , Cconst_int ( n2 , _ ) ) when n1 > 0 && n2 > 0 && n1 + n2 < size_int * 8 -> Cop ( Clsl , [ c ; Cconst_int ( n1 + n2 , dbg ) ] , dbg ) | ( Cop ( Caddi , [ c1 ; Cconst_int ( n1 , _ ) ] , _ ) , Cconst_int ( n2 , _ ) ) ... |
let is_power2 n = n = 1 lsl Misc . log2 n |
let rec mul_int c1 c2 dbg = match ( c1 , c2 ) with | ( c , Cconst_int ( 0 , _ ) ) | ( Cconst_int ( 0 , _ ) , c ) -> Csequence ( c , Cconst_int ( 0 , dbg ) ) | ( c , Cconst_int ( 1 , _ ) ) | ( Cconst_int ( 1 , _ ) , c ) -> c | ( c , Cconst_int ( - 1 , _ ) ) | ( Cconst_int ( - 1 , _ ) , c ) -> sub_int ( Cconst_int ( 0 , ... |
let ignore_low_bit_int = function Cop ( Caddi , [ ( Cop ( Clsl , [ _ ; Cconst_int ( n , _ ) ] , _ ) as c ) ; Cconst_int ( 1 , _ ) ] , _ ) when n > 0 -> c | Cop ( Cor , [ c ; Cconst_int ( 1 , _ ) ] , _ ) -> c | c -> c |
let ignore_high_bit_int = function Cop ( Casr , [ Cop ( Clsl , [ c ; Cconst_int ( 1 , _ ) ] , _ ) ; Cconst_int ( 1 , _ ) ] , _ ) -> c | c -> c |
let lsr_int c1 c2 dbg = match c2 with Cconst_int ( 0 , _ ) -> c1 | Cconst_int ( n , _ ) when n > 0 -> Cop ( Clsr , [ ignore_low_bit_int c1 ; c2 ] , dbg ) | _ -> Cop ( Clsr , [ c1 ; c2 ] , dbg ) |
let asr_int c1 c2 dbg = match c2 with Cconst_int ( 0 , _ ) -> c1 | Cconst_int ( n , _ ) when n > 0 -> Cop ( Casr , [ ignore_low_bit_int c1 ; c2 ] , dbg ) | _ -> Cop ( Casr , [ c1 ; c2 ] , dbg ) |
let tag_int i dbg = match i with Cconst_int ( n , _ ) -> int_const dbg n | Cop ( Casr , [ c ; Cconst_int ( n , _ ) ] , _ ) when n > 0 -> Cop ( Cor , [ asr_int c ( Cconst_int ( n - 1 , dbg ) ) dbg ; Cconst_int ( 1 , dbg ) ] , dbg ) | c -> incr_int ( lsl_int c ( Cconst_int ( 1 , dbg ) ) dbg ) dbg |
let untag_int i dbg = match i with Cconst_int ( n , _ ) -> Cconst_int ( n asr 1 , dbg ) | Cop ( Cor , [ Cop ( Casr , [ c ; Cconst_int ( n , _ ) ] , _ ) ; Cconst_int ( 1 , _ ) ] , _ ) when n > 0 && n < size_int * 8 - 1 -> Cop ( Casr , [ c ; Cconst_int ( n + 1 , dbg ) ] , dbg ) | Cop ( Cor , [ Cop ( Clsr , [ c ; Cconst_i... |
let mk_if_then_else dbg cond ifso_dbg ifso ifnot_dbg ifnot = match cond with | Cconst_int ( 0 , _ ) -> ifnot | Cconst_int ( 1 , _ ) -> ifso | _ -> Cifthenelse ( cond , ifso_dbg , ifso , ifnot_dbg , ifnot , dbg ) |
let mk_not dbg cmm = match cmm with | Cop ( Caddi , [ Cop ( Clsl , [ c ; Cconst_int ( 1 , _ ) ] , _ ) ; Cconst_int ( 1 , _ ) ] , dbg ' ) -> begin match c with | Cop ( Ccmpi cmp , [ c1 ; c2 ] , dbg ' ' ) -> tag_int ( Cop ( Ccmpi ( negate_integer_comparison cmp ) , [ c1 ; c2 ] , dbg ' ' ) ) dbg ' | Cop ( Ccmpa cmp , [ c1... |
let mk_compare_ints dbg a1 a2 = match ( a1 , a2 ) with | Cconst_int ( c1 , _ ) , Cconst_int ( c2 , _ ) -> int_const dbg ( Int . compare c1 c2 ) | Cconst_natint ( c1 , _ ) , Cconst_natint ( c2 , _ ) -> int_const dbg ( Nativeint . compare c1 c2 ) | Cconst_int ( c1 , _ ) , Cconst_natint ( c2 , _ ) -> int_const dbg Nativei... |
let mk_compare_floats dbg a1 a2 = bind " float_cmp " a2 ( fun a2 -> bind " float_cmp " a1 ( fun a1 -> let op1 = Cop ( Ccmpf ( CFgt ) , [ a1 ; a2 ] , dbg ) in let op2 = Cop ( Ccmpf ( CFlt ) , [ a1 ; a2 ] , dbg ) in let op3 = Cop ( Ccmpf ( CFeq ) , [ a1 ; a1 ] , dbg ) in let op4 = Cop ( Ccmpf ( CFeq ) , [ a2 ; a2 ] , dbg... |
let create_loop body dbg = let cont = Lambda . next_raise_count ( ) in let call_cont = Cexit ( cont , [ ] ) in let body = Csequence ( body , call_cont ) in Ccatch ( Recursive , [ cont , [ ] , body , dbg ] , call_cont ) |
let ucompare x y = Nativeint . ( compare ( add x min_int ) ( add y min_int ) ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.