text
stringlengths
0
601k
let length buf = buf . len
let add_char buf c = set buf buf . len c
let add_bytes buf b = let len = Bytes . length b in Lwt_bytes . blit_from_bytes b 0 buf . bytes buf . len len ; buf . len <- buf . len + len
let sub buf off len = let b = Lwt_bytes . proxy buf . bytes off len in { bytes = b ; len = len }
let blit buf1 off1 buf2 off2 len = Lwt_bytes . blit buf1 . bytes off1 buf2 . bytes off2 len ; buf2 . len <- max buf2 . len ( off2 + len )
let contents buf = Lwt_bytes . to_string buf . bytes
let to_string buf = contents ( sub buf 0 ( length buf ) )
let of_string s = { bytes = Lwt_bytes . of_string s ; len = String . length s }
let add_buffer buf1 buf2 = blit buf2 0 buf1 buf1 . len buf2 . len
let index_from buf base c = if base >= 0 && base < buf . len then let rec index i = if i < buf . len then if get buf i = c then Some i else index ( i + 1 ) else None in index base else None
let index buf c = index_from buf 0 c
let read fd buf off len = Lwt_bytes . read fd buf . bytes off len >>= fun k -> buf . len <- max buf . len ( off + k ) ; Lwt . return k
let write fd buf off len = Lwt_bytes . write fd buf . bytes off len
let read_byte_at i buf = int_of_char ( B . get buf i )
let read_byte = read_byte_at 0
let write_byte b buf = B . add_char buf ( char_of_int ( b land 255 ) )
module type Integer = sig type t val bytes : int val zero : t val byte_max : t val shift_left : t -> int -> t val shift_right_logical : t -> int -> t val logor : t -> t -> t val logand : t -> t -> t val of_int : int -> t val to_int : t -> int end
module type ByteOps = sig type t val read_at : int -> B . t -> t val write_byte : t -> B . t -> unit val write : t -> B . t -> unit end
module MakeBig ( I : Integer ) : ByteOps with type t = I . t = struct type t = I . t let bits = 8 * I . bytes let read_at i buf = let res = ref I . zero in for b = 1 to I . bytes do let pos = i + b - 1 in let byte = I . of_int ( read_byte_at pos buf ) in res := I . logor ! res ( I . shift_left byte ( bits - 8 * b ) ) d...
module MakeLittle ( I : Integer ) : ByteOps with type t = I . t = struct type t = I . t let bits = 8 * I . bytes let read_at i buf = let res = ref I . zero in for b = I . bytes downto 1 do let pos = i + b - 1 in let byte = I . of_int ( read_byte_at pos buf ) in res := I . logor ! res ( I . shift_left byte ( 8 * ( b - 1...
let id x = x
module Int16 = struct type t = int let bytes = 2 let zero = 0 let byte_max = 255 let shift_left = ( lsl ) let shift_right_logical = ( lsr ) let logor = ( lor ) let logand = ( land ) let of_int = id let to_int = id end
module Int = struct type t = int let bytes = 4 let zero = 0 let byte_max = 255 let shift_left = ( lsl ) let shift_right_logical = ( lsr ) let logor = ( lor ) let logand = ( land ) let of_int = id let to_int = id end
module Int32 = struct type t = Int32 . t let bytes = 4 let zero = Int32 . zero let byte_max = Int32 . of_int 255 let shift_left = Int32 . shift_left let shift_right_logical = Int32 . shift_right_logical let logor = Int32 . logor let logand = Int32 . logand let of_int = Int32 . of_int let to_int = Int32 . to_int end
module Uint32 = struct type t = Uint32 . t let bytes = 4 let zero = Uint32 . zero let byte_max = Uint32 . of_int 255 let shift_left = Uint32 . shift_left let shift_right_logical = Uint32 . shift_right let logor = Uint32 . logor let logand = Uint32 . logand let of_int = Uint32 . of_int let to_int = Uint32 . to_int end
module Int64 = struct type t = Int64 . t let bytes = 8 let zero = Int64 . zero let byte_max = Int64 . of_int 255 let shift_left = Int64 . shift_left let shift_right_logical = Int64 . shift_right_logical let logor = Int64 . logor let logand = Int64 . logand let of_int = Int64 . of_int let to_int = Int64 . to_int end
module Uint64 = struct type t = Uint64 . t let bytes = 8 let zero = Uint64 . zero let byte_max = Uint64 . of_int 255 let shift_left = Uint64 . shift_left let shift_right_logical = Uint64 . shift_right let logor = Uint64 . logor let logand = Uint64 . logand let of_int = Uint64 . of_int let to_int = Uint64 . to_int end
module Uint128 = struct type t = Uint128 . t let bytes = 32 let zero = Uint128 . zero let byte_max = Uint128 . of_int 255 let shift_left = Uint128 . shift_left let shift_right_logical = Uint128 . shift_right let logor = Uint128 . logor let logand = Uint128 . logand let of_int = Uint128 . of_int let to_int = Uint128 . t...
module type IntegerOps = sig module Make ( I : Integer ) : ByteOps with type t = I . t val read_int16_at : int -> B . t -> int val read_int16 : B . t -> int val write_int16_byte : int -> B . t -> unit val write_int16 : int -> B . t -> unit val read_int_at : int -> B . t -> int val read_int : B . t -> int val write_int_...
module Big_endian = struct module Make = MakeBig let read_int16_at = Int16BigOps . read_at let read_int16 = read_int16_at 0 let write_int16_byte = Int16BigOps . write_byte let write_int16 = Int16BigOps . write let read_int_at = IntBigOps . read_at let read_int = read_int_at 0 let write_int_byte = IntBigOps . write_byte...
module Little_endian = struct module Make = MakeLittle let read_int16_at = Int16LittleOps . read_at let read_int16 = read_int16_at 0 let write_int16_byte = Int16LittleOps . write_byte let write_int16 = Int16LittleOps . write let read_int_at = IntLittleOps . read_at let read_int = read_int_at 0 let write_int_byte = IntL...
match op with | Iintop ( Iadd | Isub | Imul | Iand | Ior | Ixor ) | Iaddf | Isubf | Imulf | Idivf -> let res = self # makereg res . ( 0 ) in ( [ | res ; self # makereg arg . ( 1 ) ] , | [ | res ] ) | | Ispecific ( Imultaddf | Imultsubf ) -> let res = self # makereg res . ( 0 ) in ( [ | self # makereg arg . ( 0 ) ; self...
let fundecl f num_stack_slots = ( new reload ) # fundecl f num_stack_slots
let insert_move src dst next = if src . loc = dst . loc then next else instr_cons ( Iop Imove ) [ | src ] | [ | dst ] | next
let insert_moves src dst next = let rec insmoves i = if i >= Array . length src then next else insert_move src . ( i ) dst . ( i ) ( insmoves ( i + 1 ) ) in insmoves 0 match r . loc with Unknown -> fatal_error " Reload . makereg " | Reg _ -> r | Stack _ -> redo_regalloc <- true ; let newr = Reg . clone r in newr . spil...
let option_map f = function Some x -> Some ( f x ) | None -> None ; ;
let vala_map f x = f x ; ;
let class_infos_map floc sh ~ attributes f x = { ciLoc = floc x . ciLoc ; ciVir = x . ciVir ; ciPrm = ( let ( x1 , x2 ) = x . ciPrm in floc x1 , x2 ) ; ciNam = x . ciNam ; ciExp = f x . ciExp ; ciAttributes = attributes floc sh x . ciAttributes } ; ;
let anti_loc qloc sh loc loc1 = let sh1 = Ploc . first_pos qloc + sh in let sh2 = sh1 + Ploc . first_pos loc in let line_nb_qloc = Ploc . line_nb qloc in let line_nb_loc = Ploc . line_nb loc in let line_nb_loc1 = Ploc . line_nb loc1 in if line_nb_qloc < 0 || line_nb_loc < 0 || line_nb_loc1 < 0 then Ploc . make_unlined ...
let rec ctyp floc sh = let rec self = function TyAtt ( loc , ct , attr ) -> let loc = floc loc in TyAtt ( loc , self ct , attribute_body floc sh attr ) | TyAcc ( loc , x1 , x2 ) -> let loc = floc loc in TyAcc ( loc , longid floc sh x1 , x2 ) | TyAli ( loc , x1 , x2 ) -> let loc = floc loc in TyAli ( loc , self x1 , sel...
let eq_longid x y = longid ( fun _ -> Ploc . dummy ) 0 x = longid ( fun _ -> Ploc . dummy ) 0 y ; ;
let eq_longid_lident x y = longid_lident ( fun _ -> Ploc . dummy ) 0 x = longid_lident ( fun _ -> Ploc . dummy ) 0 y ; ;
let eq_expr x y = expr ( fun _ -> Ploc . dummy ) 0 x = expr ( fun _ -> Ploc . dummy ) 0 y ; ;
let eq_patt x y = patt ( fun _ -> Ploc . dummy ) 0 x = patt ( fun _ -> Ploc . dummy ) 0 y ; ;
let eq_ctyp x y = ctyp ( fun _ -> Ploc . dummy ) 0 x = ctyp ( fun _ -> Ploc . dummy ) 0 y ; ;
let eq_str_item x y = str_item ( fun _ -> Ploc . dummy ) 0 x = str_item ( fun _ -> Ploc . dummy ) 0 y ; ;
let eq_sig_item x y = sig_item ( fun _ -> Ploc . dummy ) 0 x = sig_item ( fun _ -> Ploc . dummy ) 0 y ; ;
let eq_module_expr x y = module_expr ( fun _ -> Ploc . dummy ) 0 x = module_expr ( fun _ -> Ploc . dummy ) 0 y ; ;
let eq_module_type x y = module_type ( fun _ -> Ploc . dummy ) 0 x = module_type ( fun _ -> Ploc . dummy ) 0 y ; ;
let eq_class_sig_item x y = class_sig_item ( fun _ -> Ploc . dummy ) 0 x = class_sig_item ( fun _ -> Ploc . dummy ) 0 y ; ;
let eq_class_str_item x y = class_str_item ( fun _ -> Ploc . dummy ) 0 x = class_str_item ( fun _ -> Ploc . dummy ) 0 y ; ;
let eq_class_type x y = class_type ( fun _ -> Ploc . dummy ) 0 x = class_type ( fun _ -> Ploc . dummy ) 0 y ; ;
let eq_class_expr x y = class_expr ( fun _ -> Ploc . dummy ) 0 x = class_expr ( fun _ -> Ploc . dummy ) 0 y ; ;
let out_of_text_error ~ got_or_plt ~ section_name = errorf " Relocation through % s in section % S . Such relocations should not be found \ outside . text section " got_or_plt section_name
let unauthorized_absolute_reloc ~ got_or_plt ~ section_name = errorf " Absolute % s relocation in section % s , such relocations should always be \ relative " got_or_plt section_name
let lookup_symbol symbols name = match Symbols . find symbols name with | Some addr -> Ok addr | None -> errorf " Cannot proceed with relocation % s , symbol is unknown " name
let lookup_got got symbol = match Jit_got . symbol_address got symbol with | Some addr -> Ok addr | None -> errorf " Symbol % s should be in the GOT but it is missing from there " symbol
let lookup_plt plt symbol = match Jit_plt . symbol_address plt symbol with | Some addr -> Ok addr | None -> errorf " Symbol % s should be in the GOT but it is missing from there " symbol
let one ~ symbols ~ got ~ plt ~ section_name binary_section t = let open Result . Op in let + target_symbol_address = match ( t , got , plt ) with | { target = Direct name ; _ } , _ , _ -> lookup_symbol symbols name | { target = Got name ; kind = Relative ; _ } , Some got , _ -> lookup_got got name | { target = Got _ ;...
let all_gen ~ symbols ~ got ~ plt ~ section_name binary_section = let open Result . Op in let raw_relocations = X86_emitter . relocations binary_section . value in let * relocations = Result . List . map_all ~ f : from_x86_relocation_err raw_relocations in Result . List . iter_all relocations ~ f ( : one ~ symbols ~ go...
let all_text ~ symbols ~ got ~ plt binary_section = let got = Some got in let plt = Some plt in let section_name = " . text " in all_gen ~ symbols ~ got ~ plt ~ section_name binary_section
let all ~ symbols ~ section_name binary_section = let got = None in let plt = None in all_gen ~ symbols ~ got ~ plt ~ section_name binary_section
module Target = struct type t = Direct of string | Got of string | Plt of string let from_label label = match String . split_on_char ~ sep ' ' :@ label with | [ label ] -> Some ( Direct label ) | [ label ; " GOTPCREL " ] -> Some ( Got label ) | [ label ; " PLT " ] -> Some ( Plt label ) | _ -> None let from_label_err la...
module Size = struct type t = S64 | S32 let to_data_size = function S64 -> X86_emitter . B64 | S32 -> X86_emitter . B32 let to_int = function S32 -> 4 | S64 -> 8 end
module Kind = struct type t = Absolute | Relative end
type t = { offset_from_section_beginning : int ; size : Size . t ; kind : Kind . t ; target : Target . t ; addend : int64 ; }
let size_from_reloc_kind ( kind : X86_emitter . Relocation . Kind . t ) = match kind with REL32 _ | DIR32 _ -> Size . S32 | DIR64 _ -> Size . S64
let kind_from_reloc_kind ( kind : X86_emitter . Relocation . Kind . t ) = match kind with | DIR32 _ | DIR64 _ -> Kind . Absolute | REL32 _ -> Kind . Relative
let label_from_reloc_kind ( kind : X86_emitter . Relocation . Kind . t ) = match kind with | REL32 ( label , _ ) | DIR32 ( label , _ ) | DIR64 ( label , _ ) -> label
let addend_from_reloc_kind ( kind : X86_emitter . Relocation . Kind . t ) = match kind with | REL32 ( _ , addend ) | DIR32 ( _ , addend ) | DIR64 ( _ , addend ) -> addend
let from_x86_relocation relocation = let open Option . Op in let ( { offset_from_section_beginning ; kind } : X86_emitter . Relocation . t ) = relocation in let label = label_from_reloc_kind kind in let addend = addend_from_reloc_kind kind in let size = size_from_reloc_kind kind in let kind = kind_from_reloc_kind kind ...
let from_x86_relocation_err relocation = let open Result . Op in let ( { offset_from_section_beginning ; kind } : X86_emitter . Relocation . t ) = relocation in let label = label_from_reloc_kind kind in let addend = addend_from_reloc_kind kind in let size = size_from_reloc_kind kind in let kind = kind_from_reloc_kind k...
let add_extension_if_not_already_mentioned a ext = let size_a = String . length a in let size_ext = String . length ext in try if size_a < size_ext || ( String . sub a ( size_a - size_ext ) size_ext = ext ) then a else a ^ ext with | _ -> a ^ ext
let open_out a ext = let a = add_extension_if_not_already_mentioned a ext in let d = Filename . dirname a in let ( ) = try if not ( Sys . is_directory d ) then ( Format . eprintf " ' % s ' is not a directory . " @ d ; exit 1 ) with Sys_error _ -> Kappa_files . mk_dir_r d in open_out a
let open_append a ext = let a = add_extension_if_not_already_mentioned a ext in let d = Filename . dirname a in let ( ) = try if not ( Sys . is_directory d ) then ( Format . eprintf " ' % s ' is not a directory . " @ d ; exit 1 ) with Sys_error _ -> Kappa_files . mk_dir_r d in try open_out_gen [ Open_append ] 511 a wit...
let compose f g = fun x -> f ( g x )
let ext_format x = match x with | Remanent_parameters_sig . DOT -> " . dot " | Remanent_parameters_sig . HTML -> " . html " | Remanent_parameters_sig . DIM -> " . dim . json " | Remanent_parameters_sig . GEPHI -> " . gexf "
let fetch_level_gen s r = match Tools . lowercase ! r with | " mute " | " none " -> Remanent_parameters_sig . None | " low " -> Remanent_parameters_sig . Low | " medium " -> Remanent_parameters_sig . Medium | " high " -> Remanent_parameters_sig . High | " complete " | " full " -> Remanent_parameters_sig . Full | x -> l...
let fetch_graph_format f = match Tools . lowercase ! f with | " dot " -> Remanent_parameters_sig . DOT | " html " -> Remanent_parameters_sig . HTML | " dim " -> Remanent_parameters_sig . DIM | " gephi " -> Remanent_parameters_sig . GEPHI | x -> let ( ) = Printf . eprintf " % s is not a valid graph format " !!! x in rai...
let fetch_accuracy_level r = fetch_level_gen " an accuracy " r
let fetch_verbosity_level r = fetch_level_gen " a verbosity " r
let fetch_rate_convention f = match Tools . lowercase ! f with | " kasim " -> Remanent_parameters_sig . No_correction | " divide_by_nbr_of_autos_in_lhs " -> Remanent_parameters_sig . Divide_by_nbr_of_autos_in_lhs | " biochemist " -> Remanent_parameters_sig . Biochemist | x -> let ( ) = Printf . eprintf " % s is not a v...
let get_syntax_version ( ) = match ! Config . syntax_version with | " 4 " | " v4 " | " V4 " -> Ast . V4 | " 3 " | " v3 " | " V3 " -> Ast . V3 | _ -> failwith " Syntax version should be either V3 or V4 "
let get_symbols ( ) = match get_syntax_version ( ) with | Ast . V3 -> Symbol_table . symbol_table_V3 | Ast . V4 -> Symbol_table . symbol_table_V4
let get_influence_map ( ) = { Remanent_parameters_sig . im_format = fetch_graph_format Config . influence_map_format ; Remanent_parameters_sig . im_file = ( match ! Config . influence_map_file with | " " -> None | x -> Some x ) ; Remanent_parameters_sig . im_directory = ( match ! Config . output_im_directory with | " "...
let get_contact_map ( ) = { Remanent_parameters_sig . cm_format = fetch_graph_format Config . contact_map_format ; Remanent_parameters_sig . cm_file = ( match ! Config . contact_map_file with | " " -> None | x -> Some x ) ; Remanent_parameters_sig . cm_directory = ( match ! Config . output_cm_directory with | " " -> So...
let reachability_map_0 = { Remanent_parameters_sig . dump_reachability_analysis_result = false ; Remanent_parameters_sig . dump_reachability_analysis_iteration = false ; Remanent_parameters_sig . dump_reachability_analysis_diff = false ; Remanent_parameters_sig . dump_reachability_analysis_wl = false ; Remanent_paramet...
let reachability_map_1 = { reachability_map_0 with Remanent_parameters_sig . dump_reachability_analysis_result = true }
let reachability_map_2 = { reachability_map_1 with Remanent_parameters_sig . dump_reachability_analysis_iteration = true }
let reachability_map_3 = { reachability_map_2 with Remanent_parameters_sig . dump_reachability_analysis_diff = true }
let reachability_map_4 = { reachability_map_3 with Remanent_parameters_sig . dump_reachability_analysis_wl = true ; }
let add_debugging_parameters_to_reachability_map reachability = let trace = ! Config . trace in let reachability = { reachability with Remanent_parameters_sig . hide_reverse_rule_without_label_from_dead_rules = ! Config . hide_reverse_rule_without_label_from_dead_rules ; Remanent_parameters_sig . hide_one_d_relations_f...
let get_reachability_map ( ) = add_debugging_parameters_to_reachability_map begin match fetch_verbosity_level Config . verbosity_level_for_reachability_analysis with | Remanent_parameters_sig . None -> reachability_map_0 | Remanent_parameters_sig . Low -> reachability_map_1 | Remanent_parameters_sig . Medium -> reachab...
let get_reachability_parameters ( ) = { Remanent_parameters_sig . views = ! Config . with_views_analysis ; Remanent_parameters_sig . site_across_bonds = ! Config . with_site_across_bonds_analysis ; Remanent_parameters_sig . parallel_bonds = ! Config . with_parallel_bonds_analysis ; Remanent_parameters_sig . counters = ...
let open_tasks_profiling = let cache = ref None in fun ( ) -> match ! cache with | None -> let channel = Kappa_files . open_tasks_profiling ( ) in let ( ) = cache := Some channel in channel | Some channel -> channel
let fetch_backdoors ( ) = { Remanent_parameters_sig . backdoor_nbr_of_scc = ! Config . backdoor_nbr_of_scc ; Remanent_parameters_sig . backdoor_average_size_of_scc = ! Config . backdoor_average_size_of_scc ; Remanent_parameters_sig . backdoor_nbr_of_constraints = ! Config . backdoor_nbr_of_constraints ; Remanent_parame...
let get_parameters ? html_mode ( : html_mode = true ) ~ called_from ( ) = let channel , channel_err , channel_backdoor , html_mode , command = match called_from with | Remanent_parameters_sig . Server -> None , None , None , false || html_mode , [ " | KaSa " ; " ( Interractive mode ) " ] | | Remanent_parameters_sig . I...
let dummy_parameters ~ called_from = let cache = ref None in fun ( ) -> match ! cache with | None -> let p = get_parameters ~ called_from ( ) in let ( ) = cache := Some p in p | Some p -> p
let get_bound_symbol_1 symbol = symbol . Symbol_table . bound
let get_open_binding_state_1 symbol = symbol . Symbol_table . open_binding_state