text stringlengths 0 601k |
|---|
let cache_public_method meths tag cache dbg = let raise_num = Lambda . next_raise_count ( ) in let cconst_int i = Cconst_int ( i , dbg ) in let li = V . create_local " * li " * and hi = V . create_local " * hi " * and mi = V . create_local " * mi " * and tagged = V . create_local " * tagged " * in Clet_mut ( VP . creat... |
let has_local_allocs e = let rec loop = function | Cregion e -> loop_until_tail e | Cop ( Calloc Alloc_local , _ , _ ) | Cop ( ( Cextcall _ | Capply _ ) , _ , _ ) -> raise Exit | e -> iter_shallow loop e and loop_until_tail = function | Ctail e -> loop e | Cregion _ -> ( ) | e -> ignore ( iter_shallow_tail loop_until_t... |
let remove_region_tail e = let rec has_tail = function | Ctail _ | Cop ( Capply ( _ , Rc_close_at_apply ) , _ , _ ) -> raise Exit | Cregion _ -> ( ) | e -> ignore ( iter_shallow_tail has_tail e ) in let rec remove_tail = function | Ctail e -> e | Cop ( Capply ( mach , Rc_close_at_apply ) , args , dbg ) -> Cop ( Capply ... |
let region e = if has_local_allocs e then Cregion e else remove_region_tail e |
let placeholder_dbg ( ) = Debuginfo . none |
let placeholder_fun_dbg ~ human_name : _ = Debuginfo . none |
let apply_function_body ( arity , ( mode : Lambda . alloc_mode ) ) = let dbg = placeholder_dbg in let arg = Array . make arity ( V . create_local " arg " ) in for i = 1 to arity - 1 do arg . ( i ) <- V . create_local " arg " done ; let clos = V . create_local " clos " in let region = if not Config . stack_allocation th... |
let send_function ( arity , mode ) = let dbg = placeholder_dbg in let cconst_int i = Cconst_int ( i , dbg ( ) ) in let ( args , clos ' , body ) = apply_function_body ( 1 + arity , mode ) in let cache = V . create_local " cache " and obj = List . hd args and tag = V . create_local " tag " in let clos = let cache = Cvar ... |
let apply_function arity = let ( args , clos , body ) = apply_function_body arity in let all_args = args @ [ clos ] in let fun_name = apply_function_name arity in let fun_dbg = placeholder_fun_dbg ~ human_name : fun_name in Cfunction { fun_name ; fun_args = List . map ( fun arg -> ( VP . create arg , typ_val ) ) all_ar... |
let tuplify_function arity = let dbg = placeholder_dbg in let arg = V . create_local " arg " in let clos = V . create_local " clos " in let rec access_components i = if i >= arity then [ ] else get_field_gen Asttypes . Mutable ( Cvar arg ) i ( dbg ( ) ) :: access_components ( i + 1 ) in let fun_name = " caml_tuplify " ... |
let final_curry_function ~ nlocal ~ arity = let dbg = placeholder_dbg in let last_arg = V . create_local " arg " in let last_clos = V . create_local " clos " in let rec curry_fun args clos n = if n = 0 then Cop ( Capply ( typ_val , Rc_normal ) , get_field_gen Asttypes . Mutable ( Cvar clos ) 2 ( dbg ( ) ) :: args @ [ C... |
let rec intermediate_curry_functions ~ nlocal ~ arity num = let dbg = placeholder_dbg in if num = arity - 1 then [ final_curry_function ~ nlocal ~ arity ] else begin let name1 = " caml_curry " ^ Int . to_string arity ^ ( if nlocal > 0 then " L " ^ Int . to_string nlocal else " " ) in let name2 = if num = 0 then name1 e... |
let curry_function = function | Lambda . Tupled , n -> assert ( n > 0 ) ; [ tuplify_function n ] | Lambda . Curried { nlocal } , n -> assert ( n > 0 ) ; intermediate_curry_functions ~ nlocal ~ arity : n 0 |
module ApplyFnSet = Set . Make ( struct type t = int * Lambda . alloc_mode let compare = compare end ) |
module AritySet = Set . Make ( struct type t = Clambda . arity let compare = compare end ) |
let default_apply = ApplyFnSet . of_list [ 2 , Lambda . alloc_heap ; 3 , Lambda . alloc_heap ] |
let generic_functions shared units = let ( apply , send , curry ) = List . fold_left ( fun ( apply , send , curry ) ( ui : Cmx_format . unit_infos ) -> List . fold_right ApplyFnSet . add ui . ui_apply_fun apply , List . fold_right ApplyFnSet . add ui . ui_send_fun send , List . fold_right AritySet . add ui . ui_curry_f... |
type unary_primitive = expression -> Debuginfo . t -> expression |
let floatfield n ptr dbg = Cop ( Cload ( Double , Mutable ) , [ if n = 0 then ptr else Cop ( Cadda , [ ptr ; Cconst_int ( n * size_float , dbg ) ] , dbg ) ] , dbg ) |
let int_as_pointer arg dbg = Cop ( Caddi , [ arg ; Cconst_int ( - 1 , dbg ) ] , dbg ) |
let raise_prim raise_kind arg dbg = if ! Clflags . debug then Cop ( Craise raise_kind , [ arg ] , dbg ) else Cop ( Craise Lambda . Raise_notrace , [ arg ] , dbg ) |
let negint arg dbg = Cop ( Csubi , [ Cconst_int ( 2 , dbg ) ; arg ] , dbg ) |
let offsetref n arg dbg = return_unit dbg ( bind " ref " arg ( fun arg -> Cop ( Cstore ( Word_int , Assignment ) , [ arg ; add_const ( Cop ( Cload ( Word_int , Mutable ) , [ arg ] , dbg ) ) ( n lsl 1 ) dbg ] , dbg ) ) ) |
let arraylength kind arg dbg = let hdr = get_header_without_profinfo arg dbg in match ( kind : Lambda . array_kind ) with Pgenarray -> let len = if wordsize_shift = numfloat_shift then Cop ( Clsr , [ hdr ; Cconst_int ( wordsize_shift , dbg ) ] , dbg ) else bind " header " hdr ( fun hdr -> Cifthenelse ( is_addr_array_hd... |
let bbswap bi arg dbg = let prim , tyarg = match ( bi : Primitive . boxed_integer ) with | Pnativeint -> " nativeint " , XInt | Pint32 -> " int32 " , XInt32 | Pint64 -> " int64 " , XInt64 in Cop ( Cextcall ( Printf . sprintf " caml_ % s_direct_bswap " prim , typ_int , [ tyarg ] , false ) , [ arg ] , dbg ) |
let bswap16 arg dbg = ( Cop ( Cextcall ( " caml_bswap16_direct " , typ_int , [ ] , false ) , [ arg ] , dbg ) ) |
type binary_primitive = expression -> expression -> Debuginfo . t -> expression |
type assignment_kind = | Caml_modify | Caml_modify_local | Simple of initialization_or_assignment |
let assignment_kind ( ptr : Lambda . immediate_or_pointer ) ( init : Lambda . initialization_or_assignment ) = match init , ptr with | Assignment Alloc_heap , Pointer -> Caml_modify | Assignment Alloc_local , Pointer -> assert Config . stack_allocation ; Caml_modify_local | Heap_initialization , _ -> Misc . fatal_error... |
let setfield n ptr init arg1 arg2 dbg = match assignment_kind ptr init with | Caml_modify -> return_unit dbg ( Cop ( Cextcall ( " caml_modify " , typ_void , [ ] , false ) , [ field_address arg1 n dbg ; arg2 ] , dbg ) ) | Caml_modify_local -> return_unit dbg ( Cop ( Cextcall ( " caml_modify_local " , typ_void , [ ] , fa... |
let setfloatfield n init arg1 arg2 dbg = let init = match init with | Lambda . Assignment _ -> Assignment | Lambda . Heap_initialization | Lambda . Root_initialization -> Initialization in return_unit dbg ( Cop ( Cstore ( Double , init ) , [ if n = 0 then arg1 else Cop ( Cadda , [ arg1 ; Cconst_int ( n * size_float , d... |
let add_int_caml arg1 arg2 dbg = decr_int ( add_int arg1 arg2 dbg ) dbg |
let offsetint n arg dbg = if Misc . no_overflow_lsl n 1 then add_const arg ( n lsl 1 ) dbg else add_int_caml arg ( int_const dbg n ) dbg |
let sub_int_caml arg1 arg2 dbg = incr_int ( sub_int arg1 arg2 dbg ) dbg |
let mul_int_caml arg1 arg2 dbg = match arg1 , arg2 with | Cconst_int _ as c1 , c2 -> incr_int ( mul_int ( untag_int c1 dbg ) ( decr_int c2 dbg ) dbg ) dbg | c1 , c2 -> incr_int ( mul_int ( decr_int c1 dbg ) ( untag_int c2 dbg ) dbg ) dbg |
let div_int_caml is_safe arg1 arg2 dbg = tag_int ( div_int ( untag_int arg1 dbg ) ( untag_int arg2 dbg ) is_safe dbg ) dbg |
let mod_int_caml is_safe arg1 arg2 dbg = tag_int ( mod_int ( untag_int arg1 dbg ) ( untag_int arg2 dbg ) is_safe dbg ) dbg |
let and_int_caml arg1 arg2 dbg = Cop ( Cand , [ arg1 ; arg2 ] , dbg ) |
let or_int_caml arg1 arg2 dbg = Cop ( Cor , [ arg1 ; arg2 ] , dbg ) |
let xor_int_caml arg1 arg2 dbg = Cop ( Cor , [ Cop ( Cxor , [ ignore_low_bit_int arg1 ; ignore_low_bit_int arg2 ] , dbg ) ; Cconst_int ( 1 , dbg ) ] , dbg ) |
let lsl_int_caml arg1 arg2 dbg = incr_int ( lsl_int ( decr_int arg1 dbg ) ( untag_int arg2 dbg ) dbg ) dbg |
let lsr_int_caml arg1 arg2 dbg = Cop ( Cor , [ lsr_int arg1 ( untag_int arg2 dbg ) dbg ; Cconst_int ( 1 , dbg ) ] , dbg ) |
let asr_int_caml arg1 arg2 dbg = Cop ( Cor , [ asr_int arg1 ( untag_int arg2 dbg ) dbg ; Cconst_int ( 1 , dbg ) ] , dbg ) |
let int_comp_caml cmp arg1 arg2 dbg = tag_int ( Cop ( Ccmpi cmp , [ arg1 ; arg2 ] , dbg ) ) dbg |
let stringref_unsafe arg1 arg2 dbg = tag_int ( Cop ( Cload ( Byte_unsigned , Mutable ) , [ add_int arg1 ( untag_int arg2 dbg ) dbg ] , dbg ) ) dbg |
let stringref_safe arg1 arg2 dbg = tag_int ( bind " index " ( untag_int arg2 dbg ) ( fun idx -> bind " str " arg1 ( fun str -> Csequence ( make_checkbound dbg [ string_length str dbg ; idx ] , Cop ( Cload ( Byte_unsigned , Mutable ) , [ add_int str idx dbg ] , dbg ) ) ) ) ) dbg |
let string_load size unsafe mode arg1 arg2 dbg = box_sized size mode dbg ( bind " index " ( untag_int arg2 dbg ) ( fun idx -> bind " str " arg1 ( fun str -> check_bound unsafe size dbg ( string_length str dbg ) idx ( unaligned_load size str idx dbg ) ) ) ) |
let bigstring_load size unsafe mode arg1 arg2 dbg = box_sized size mode dbg ( bind " index " ( untag_int arg2 dbg ) ( fun idx -> bind " ba " arg1 ( fun ba -> bind " ba_data " ( Cop ( Cload ( Word_int , Mutable ) , [ field_address ba 1 dbg ] , dbg ) ) ( fun ba_data -> check_bound unsafe size dbg ( bigstring_length ba db... |
let arrayref_unsafe kind arg1 arg2 dbg = match ( kind : Lambda . array_kind ) with | Pgenarray -> bind " index " arg2 ( fun idx -> bind " arr " arg1 ( fun arr -> Cifthenelse ( is_addr_array_ptr arr dbg , dbg , addr_array_ref arr idx dbg , dbg , float_array_ref arr idx dbg , dbg ) ) ) | Paddrarray -> addr_array_ref arg1... |
let arrayref_safe kind arg1 arg2 dbg = match ( kind : Lambda . array_kind ) with | Pgenarray -> bind " index " arg2 ( fun idx -> bind " arr " arg1 ( fun arr -> bind " header " ( get_header_without_profinfo arr dbg ) ( fun hdr -> if wordsize_shift = numfloat_shift then Csequence ( make_checkbound dbg [ addr_array_length... |
type ternary_primitive = expression -> expression -> expression -> Debuginfo . t -> expression |
let setfield_computed ptr init arg1 arg2 arg3 dbg = match assignment_kind ptr init with | Caml_modify -> return_unit dbg ( addr_array_set arg1 arg2 arg3 dbg ) | Caml_modify_local -> return_unit dbg ( addr_array_set_local arg1 arg2 arg3 dbg ) | Simple _ -> return_unit dbg ( int_array_set arg1 arg2 arg3 dbg ) |
let bytesset_unsafe arg1 arg2 arg3 dbg = return_unit dbg ( Cop ( Cstore ( Byte_unsigned , Assignment ) , [ add_int arg1 ( untag_int arg2 dbg ) dbg ; ignore_high_bit_int ( untag_int arg3 dbg ) ] , dbg ) ) |
let bytesset_safe arg1 arg2 arg3 dbg = return_unit dbg ( bind " newval " ( untag_int arg3 dbg ) ( fun newval -> bind " index " ( untag_int arg2 dbg ) ( fun idx -> bind " str " arg1 ( fun str -> Csequence ( make_checkbound dbg [ string_length str dbg ; idx ] , Cop ( Cstore ( Byte_unsigned , Assignment ) , [ add_int str ... |
let arrayset_unsafe kind arg1 arg2 arg3 dbg = return_unit dbg ( match ( kind : Lambda . array_kind ) with | Pgenarray -> bind " newval " arg3 ( fun newval -> bind " index " arg2 ( fun index -> bind " arr " arg1 ( fun arr -> Cifthenelse ( is_addr_array_ptr arr dbg , dbg , addr_array_set arr index newval dbg , dbg , floa... |
let arrayset_safe kind arg1 arg2 arg3 dbg = return_unit dbg ( match ( kind : Lambda . array_kind ) with | Pgenarray -> bind " newval " arg3 ( fun newval -> bind " index " arg2 ( fun idx -> bind " arr " arg1 ( fun arr -> bind " header " ( get_header_without_profinfo arr dbg ) ( fun hdr -> if wordsize_shift = numfloat_sh... |
let bytes_set size unsafe arg1 arg2 arg3 dbg = return_unit dbg ( bind " newval " arg3 ( fun newval -> bind " index " ( untag_int arg2 dbg ) ( fun idx -> bind " str " arg1 ( fun str -> check_bound unsafe size dbg ( string_length str dbg ) idx ( unaligned_set size str idx newval dbg ) ) ) ) ) |
let bigstring_set size unsafe arg1 arg2 arg3 dbg = return_unit dbg ( bind " newval " arg3 ( fun newval -> bind " index " ( untag_int arg2 dbg ) ( fun idx -> bind " ba " arg1 ( fun ba -> bind " ba_data " ( Cop ( Cload ( Word_int , Mutable ) , [ field_address ba 1 dbg ] , dbg ) ) ( fun ba_data -> check_bound unsafe size ... |
let cdefine_symbol ( symb , ( global : Cmmgen_state . is_global ) ) = match global with | Global -> [ Cglobal_symbol symb ; Cdefine_symbol symb ] | Local -> [ Cdefine_symbol symb ] |
let emit_block symb white_header cont = let black_header = Nativeint . logor white_header caml_black in Cint black_header :: cdefine_symbol symb @ cont |
let emit_string_constant_fields s cont = let n = size_int - 1 - ( String . length s ) mod size_int in Cstring s :: Cskip n :: Cint8 n :: cont |
let emit_boxed_int32_constant_fields n cont = let n = Nativeint . of_int32 n in if size_int = 8 then Csymbol_address caml_int32_ops :: Cint32 n :: Cint32 0n :: cont else Csymbol_address caml_int32_ops :: Cint n :: cont |
let emit_boxed_int64_constant_fields n cont = let lo = Int64 . to_nativeint n in if size_int = 8 then Csymbol_address caml_int64_ops :: Cint lo :: cont else begin let hi = Int64 . to_nativeint ( Int64 . shift_right n 32 ) in if big_endian then Csymbol_address caml_int64_ops :: Cint hi :: Cint lo :: cont else Csymbol_ad... |
let emit_boxed_nativeint_constant_fields n cont = Csymbol_address caml_nativeint_ops :: Cint n :: cont |
let emit_float_constant symb f cont = emit_block symb float_header ( Cdouble f :: cont ) |
let emit_string_constant symb s cont = emit_block symb ( string_header ( String . length s ) ) ( emit_string_constant_fields s cont ) |
let emit_int32_constant symb n cont = emit_block symb boxedint32_header ( emit_boxed_int32_constant_fields n cont ) |
let emit_int64_constant symb n cont = emit_block symb boxedint64_header ( emit_boxed_int64_constant_fields n cont ) |
let emit_nativeint_constant symb n cont = emit_block symb boxedintnat_header ( emit_boxed_nativeint_constant_fields n cont ) |
let emit_float_array_constant symb fields cont = emit_block symb ( floatarray_header ( List . length fields ) ) ( Misc . map_end ( fun f -> Cdouble f ) fields cont ) |
let entry_point namelist = let dbg = placeholder_dbg in let cconst_int i = Cconst_int ( i , dbg ( ) ) in let cconst_symbol sym = Cconst_symbol ( sym , dbg ( ) ) in let incr_global_inited ( ) = Cop ( Cstore ( Word_int , Assignment ) , [ cconst_symbol " caml_globals_inited " ; Cop ( Caddi , [ Cop ( Cload ( Word_int , Mut... |
let cint_zero = Cint 0n |
let global_table namelist = let mksym name = Csymbol_address ( Compilenv . make_symbol ~ unitname : name ( Some " gc_roots " ) ) in Cdata ( Cglobal_symbol " caml_globals " :: Cdefine_symbol " caml_globals " :: List . map mksym namelist @ [ cint_zero ] ) |
let reference_symbols namelist = let mksym name = Csymbol_address name in Cdata ( List . map mksym namelist ) |
let global_data name v = Cdata ( emit_string_constant ( name , Global ) ( Marshal . to_string v [ ] ) [ ] ) |
let globals_map v = global_data " caml_globals_map " v |
let frame_table namelist = let mksym name = Csymbol_address ( Compilenv . make_symbol ~ unitname : name ( Some " frametable " ) ) in Cdata ( Cglobal_symbol " caml_frametable " :: Cdefine_symbol " caml_frametable " :: List . map mksym namelist @ [ cint_zero ] ) |
let segment_table namelist symbol begname endname = let addsyms name lst = Csymbol_address ( Compilenv . make_symbol ~ unitname : name ( Some begname ) ) :: Csymbol_address ( Compilenv . make_symbol ~ unitname : name ( Some endname ) ) :: lst in Cdata ( Cglobal_symbol symbol :: Cdefine_symbol symbol :: List . fold_righ... |
let data_segment_table namelist = segment_table namelist " caml_data_segments " " data_begin " " data_end " |
let code_segment_table namelist = segment_table namelist " caml_code_segments " " code_begin " " code_end " |
let predef_exception i name = let name_sym = Compilenv . new_const_symbol ( ) in let data_items = emit_string_constant ( name_sym , Local ) name [ ] in let exn_sym = " caml_exn_ " ^ name in let tag = Obj . object_tag in let size = 2 in let fields = ( Csymbol_address name_sym ) :: ( cint_const ( - i - 1 ) ) :: data_item... |
let plugin_header units = let mk ( ( ui : Cmx_format . unit_infos ) , crc ) : Cmxs_format . dynunit = { dynu_name = ui . ui_name ; dynu_crc = crc ; dynu_imports_cmi = ui . ui_imports_cmi ; dynu_imports_cmx = ui . ui_imports_cmx ; dynu_defines = ui . ui_defines } in global_data " caml_plugin_header " ( { dynu_magic = Co... |
let fundecls_size fundecls = let sz = ref ( - 1 ) in List . iter ( fun ( f : Clambda . ufunction ) -> let indirect_call_code_pointer_size = match f . arity with | Curried _ , ( 0 | 1 ) -> 0 | _ -> 1 in sz := ! sz + 1 + 2 + indirect_call_code_pointer_size ) fundecls ; ! sz |
let emit_constant_closure ( ( _ , global_symb ) as symb ) fundecls clos_vars cont = let closure_symbol ( f : Clambda . ufunction ) = if Config . flambda then cdefine_symbol ( f . label ^ " _closure " , global_symb ) else [ ] in match ( fundecls : Clambda . ufunction list ) with [ ] -> assert ( clos_vars = [ ] ) ; cdefi... |
let emit_gc_roots_table ~ symbols cont = let table_symbol = Compilenv . make_symbol ( Some " gc_roots " ) in Cdata ( Cglobal_symbol table_symbol :: Cdefine_symbol table_symbol :: List . map ( fun s -> Csymbol_address s ) symbols @ [ Cint 0n ] ) :: cont |
let preallocate_block cont { Clambda . symbol ; exported ; tag ; fields } = let space = List . map ( fun field -> match field with | None -> Cint ( Nativeint . of_int 1 ) | Some ( Clambda . Uconst_field_int n ) -> cint_const n | Some ( Clambda . Uconst_field_ref label ) -> Csymbol_address label ) fields in let global =... |
let emit_preallocated_blocks preallocated_blocks cont = let symbols = List . map ( fun ( { Clambda . symbol } : Clambda . preallocated_block ) -> symbol ) preallocated_blocks in let c1 = emit_gc_roots_table ~ symbols cont in List . fold_left preallocate_block c1 preallocated_blocks |
module Env : sig type t val init : unit -> t val handler : t -> cont : int -> arg_num : int -> t val jump : t -> cont : int -> arg_num : int -> unit val report : Format . formatter -> bool type t = { bound_handlers : int Int . Map . t ; } type error = | Unbound_handler of { cont : int } | Multiple_handlers of { cont : ... |
let rec check env ( expr : Cmm . expression ) = match expr with | Cconst_int _ | Cconst_natint _ | Cconst_float _ | Cconst_symbol _ | Cvar _ -> ( ) | Clet ( _ , expr , body ) | Clet_mut ( _ , _ , expr , body ) -> check env expr ; check env body | Cphantom_let ( _ , _ , expr ) -> check env expr | Cassign ( _ , expr ) ->... |
let run ppf ( fundecl : Cmm . fundecl ) = let env = Env . init ( ) in check env fundecl . fun_body ; Env . report ppf |
let read_magic_number ic = let len_magic_number = String . length Config . cmt_magic_number in really_input_string ic len_magic_number |
type binary_annots = | Packed of Types . signature * string list | Implementation of structure | Interface of signature | Partial_implementation of binary_part array | Partial_interface of binary_part array |
type cmt_infos = { cmt_modname : string ; cmt_annots : binary_annots ; cmt_value_dependencies : ( Types . value_description * Types . value_description ) list ; cmt_comments : ( string * Location . t ) list ; cmt_args : string array ; cmt_sourcefile : string option ; cmt_builddir : string ; cmt_loadpath : string list ;... |
type error = Not_a_typedtree of string |
let need_to_clear_env = try ignore ( Sys . getenv " OCAML_BINANNOT_WITHENV " ) ; false with Not_found -> true |
let cenv = { Tast_mapper . default with env = fun _sub env -> keep_only_summary env } |
let clear_part = function | Partial_structure s -> Partial_structure ( cenv . structure cenv s ) | Partial_structure_item s -> Partial_structure_item ( cenv . structure_item cenv s ) | Partial_expression e -> Partial_expression ( cenv . expr cenv e ) | Partial_pattern ( category , p ) -> Partial_pattern ( category , ce... |
let clear_env binary_annots = if need_to_clear_env then match binary_annots with | Implementation s -> Implementation ( cenv . structure cenv s ) | Interface s -> Interface ( cenv . signature cenv s ) | Packed _ -> binary_annots | Partial_implementation array -> Partial_implementation ( Array . map clear_part array ) |... |
let input_cmt ic = ( input_value ic : cmt_infos ) |
let output_cmt oc cmt = output_string oc Config . cmt_magic_number ; output_value oc ( cmt : cmt_infos ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.