text
stringlengths
0
601k
let arch32 = Targetint_32_64 . size = 32
let arch64 = Targetint_32_64 . size = 64
let unary_int_prim_size kind op = match ( ( kind : Flambda_kind . Standard_int . t ) , ( op : Flambda_primitive . unary_int_arith_op ) ) with | Tagged_immediate , Neg -> 1 | Tagged_immediate , Swap_byte_endianness -> 2 + nonalloc_extcall_size + 1 | Naked_immediate , Neg -> 1 | Naked_immediate , Swap_byte_endianness -> ...
let arith_conversion_size src dst = match ( ( src : Flambda_kind . Standard_int_or_float . t ) , ( dst : Flambda_kind . Standard_int_or_float . t ) ) with | Naked_int64 , Tagged_immediate | Naked_int64 , Naked_int32 | Naked_int64 , ( Naked_nativeint | Naked_immediate ) | Naked_int64 , Naked_float when arch32 -> nonallo...
let unbox_number kind = match ( kind : Flambda_kind . Boxable_number . t ) with | Naked_float -> 1 | Naked_int64 when arch32 -> 4 | Naked_int32 | Naked_int64 | Naked_nativeint -> 2
let box_number kind = match ( kind : Flambda_kind . Boxable_number . t ) with | Naked_float -> alloc_size | Naked_int32 when not arch32 -> 1 + alloc_size | Naked_int32 | Naked_int64 | Naked_nativeint -> alloc_size
let block_load ( kind : Flambda_primitive . Block_access_kind . t ) = match kind with Values _ | Naked_floats _ -> 1
let array_load ( kind : Flambda_primitive . Array_kind . t ) = match kind with | Immediates -> 1 | Naked_floats -> 1 | Values -> 1
let block_set ( kind : Flambda_primitive . Block_access_kind . t ) ( init : Flambda_primitive . Init_or_assign . t ) = match kind , init with | Values _ , ( Assignment _ | Initialization ) -> 1 | Naked_floats _ , ( Assignment _ | Initialization ) -> 1
let array_set ( kind : Flambda_primitive . Array_kind . t ) ( _init : Flambda_primitive . Init_or_assign . t ) = match kind with | Immediates -> 1 | Naked_floats -> 1 | Values -> 1
let string_or_bigstring_load kind width = let start_address_load = match ( kind : Flambda_primitive . string_like_value ) with | String | Bytes -> 0 | Bigstring -> 2 in let elt_load = match ( width : Flambda_primitive . string_accessor_width ) with | Eight -> 3 | Sixteen -> 2 | Thirty_two -> 2 | Sixty_four -> if arch32...
let bytes_like_set kind width = match ( kind : Flambda_primitive . bytes_like_value ) with | Bytes -> string_or_bigstring_load Bytes width | Bigstring -> string_or_bigstring_load Bigstring width
let binary_phys_comparison kind op = match ( kind : Flambda_kind . t ) , ( op : Flambda_primitive . equality_comparison ) with | ( Naked_number Naked_int64 , Eq | Naked_number Naked_int64 , Neq ) when arch32 -> 1 + alloc_extcall_size + 2 + ( 2 * box_number Naked_int64 ) | _ , Eq -> 2 | _ , Neq -> 2
let divmod_bi_check else_branch_size bi = if arch32 || bi <> Flambda_kind . Standard_int . Naked_int32 then 2 + else_branch_size else 0
let binary_int_arith_primitive kind op = match ( ( kind : Flambda_kind . Standard_int . t ) , ( op : Flambda_primitive . binary_int_arith_op ) ) with | ( Naked_int64 , Add | Naked_int64 , Sub | Naked_int64 , Mul ) when arch32 -> nonalloc_extcall_size + 2 | ( Naked_int64 , Div | Naked_int64 , Mod ) when arch32 -> alloc_...
let binary_int_shift_primitive kind op = match ( kind : Flambda_kind . Standard_int . t ) , ( op : Flambda_primitive . int_shift_op ) with | ( Naked_int64 , Lsl | Naked_int64 , Lsr | Naked_int64 , Asr ) when arch32 -> nonalloc_extcall_size + 2 | Naked_int32 , Lsr when arch64 -> 2 | Tagged_immediate , Lsl -> 3 | Tagged_...
let binary_int_comp_primitive kind signed cmp = match ( ( kind : Flambda_kind . Standard_int . t ) , ( signed : Flambda_primitive . signed_or_unsigned ) , ( cmp : Flambda_primitive . ordered_comparison ) ) with | Naked_int64 , Signed , Lt | Naked_int64 , Signed , Le | Naked_int64 , Signed , Gt | Naked_int64 , Signed , ...
let int_comparison_like_compare_functions ( kind : Flambda_kind . Standard_int . t ) = match kind with | Tagged_immediate | Naked_immediate | Naked_int32 | Naked_int64 | Naked_nativeint -> 4
let binary_float_arith_primitive _op = 2
let binary_float_comp_primitive _op = 2
let nullary_prim_size prim = match ( prim : Flambda_primitive . nullary_primitive ) with | Optimised_out _ -> 0 | Probe_is_enabled { name = _ } -> 4 | Begin_region -> 1
let unary_prim_size prim = match ( prim : Flambda_primitive . unary_primitive ) with | Duplicate_array _ | Duplicate_block _ -> alloc_extcall_size + 1 | Is_int -> 1 | Get_tag -> 2 | Array_length -> array_length_size | Bigarray_length _ -> 2 | String_length _ -> 5 | Int_as_pointer -> 1 | Opaque_identity -> 0 | Int_arith...
let binary_prim_size prim = match ( prim : Flambda_primitive . binary_primitive ) with | Block_load ( kind , _ ) -> block_load kind | Array_load ( kind , _mut ) -> array_load kind | String_or_bigstring_load ( kind , width ) -> string_or_bigstring_load kind width | Bigarray_load ( _dims , ( Complex32 | Complex64 ) , _la...
let ternary_prim_size prim = match ( prim : Flambda_primitive . ternary_primitive ) with | Block_set ( block_access , init ) -> block_set block_access init | Array_set ( kind , init ) -> array_set kind init | Bytes_or_bigstring_set ( kind , width ) -> bytes_like_set kind width | Bigarray_set ( _dims , ( Complex32 | Com...
let variadic_prim_size prim args = match ( prim : Flambda_primitive . variadic_primitive ) with | Make_block ( _ , _mut , _alloc_mode ) | Make_array ( _ , _mut , _alloc_mode ) -> alloc_size + List . length args
let prim ( prim : Flambda_primitive . t ) = match prim with | Nullary p -> nullary_prim_size p | Unary ( p , _ ) -> unary_prim_size p | Binary ( p , _ , _ ) -> binary_prim_size p | Ternary ( p , _ , _ , _ ) -> ternary_prim_size p | Variadic ( p , args ) -> variadic_prim_size p args
let simple simple = Simple . pattern_match simple ~ const ( : fun _ -> 1 ) ~ name ( : fun _ ~ coercion : _ -> 0 )
let static_consts _ = 0
let apply apply = match Apply_expr . call_kind apply with | Function { function_call = Direct _ ; _ } -> direct_call_size | Function { function_call = Indirect_unknown_arity ; alloc_mode = _ } -> indirect_call_size | Function { function_call = Indirect_known_arity _ ; alloc_mode = _ } -> indirect_call_size | C_call { a...
let apply_cont apply_cont = let size = match Apply_cont_expr . trap_action apply_cont with | None -> 0 | Some ( Push _ ) -> 4 | Some ( Pop _ ) -> 2 in size + 1
let switch switch = 0 + ( 5 * Switch_expr . num_arms switch )
let [ @ ocamlformat " disable " ] print ppf t = Format . fprintf ppf " % d " t
let of_int t = t
let to_int t = t
let evaluate ~ args : _ t = float_of_int t
let free_names t = match t with | Id -> Name_occurrences . empty | Change_depth { from ; to_ } -> Name_occurrences . union ( Rec_info_expr . free_names from ) ( Rec_info_expr . free_names to_ )
let free_names_in_types t = match t with | Id -> Name_occurrences . empty | Change_depth { from ; to_ } -> Name_occurrences . union ( Rec_info_expr . free_names_in_types from ) ( Rec_info_expr . free_names_in_types to_ )
let apply_renaming t renaming = match t with | Id -> t | Change_depth { from ; to_ } -> let new_from = Rec_info_expr . apply_renaming from renaming in let new_to_ = Rec_info_expr . apply_renaming to_ renaming in if new_from == from && new_to_ == to_ then t else change_depth ~ from : new_from ~ to_ : new_to_
let compose_exn t1 ~ then_ : t2 = match compose t1 ~ then_ : t2 with | Some t -> t | None -> Misc . fatal_errorf " Invalid composition : % a @ >>@ % a " print t1 print t2
let all_ids_for_export t = match t with | Id -> Ids_for_export . empty | Change_depth { from ; to_ } -> Ids_for_export . union ( Rec_info_expr . all_ids_for_export from ) ( Rec_info_expr . all_ids_for_export to_ )
module type S = sig type variable type rec_info_expr type t = private | Id | Change_depth of { from : rec_info_expr ; to_ : rec_info_expr } val change_depth : from : rec_info_expr -> to_ : rec_info_expr -> t val id : t val is_id : t -> bool val inverse : t -> t val compose : t -> then_ : t -> t option val print : Forma...
module Make ( Rec_info_expr : Rec_info_expr0 . S ) : S with type variable = Rec_info_expr . variable and type rec_info_expr = Rec_info_expr . t = struct type variable = Rec_info_expr . variable type rec_info_expr = Rec_info_expr . t type t = | Id | Change_depth of { from : rec_info_expr ; to_ : rec_info_expr } let id =...
type plain = [ ` black | ` blue | ` cyan | ` green | ` magenta | ` red | ` white | ` yellow ]
type t = Ansi of [ plain | ` bright of plain ] | Rgb of int * int * int
let pp_plain ppf x = Format . fprintf ppf ( match x with | ` black -> " black " | ` blue -> " blue " | ` cyan -> " cyan " | ` green -> " green " | ` magenta -> " magenta " | ` red -> " red " | ` white -> " white " | ` yellow -> " yellow " )
let pp_dump ppf = function | Rgb ( r , g , b ) -> Format . fprintf ppf " RGB ( % d , % d , % d ) " r g b | Ansi ( # plain as x ) -> Format . fprintf ppf " ANSI ( % a ) " pp_plain x | Ansi ( ` bright x ) -> Format . fprintf ppf " ANSI ( bright % a ) " pp_plain x
let ansi x = Ansi x
let rgb = let invalid_component typ n = Format . kasprintf invalid_arg " Color . rgb : invalid % s component % d " typ n in fun r g b -> if r < 0 || r > 255 then invalid_component " red " r ; if g < 0 || g > 255 then invalid_component " green " g ; if b < 0 || b > 255 then invalid_component " blue " b ; Rgb ( r , g , b...
let hex = let invalid_length = Format . kasprintf invalid_arg " Color . hex : invalid hexstring length % d " in let hex c = if c >= ' 0 ' && c <= ' 9 ' then Char . code c - Char . code ' 0 ' else if c >= ' a ' && c <= ' f ' then Char . code c - Char . code ' a ' + 10 else if c >= ' A ' && c <= ' F ' then Char . code c ...
module OrderedRegSet = Set . Make ( struct type t = Reg . t let compare r1 r2 = let open Reg in let c1 = r1 . spill_cost and d1 = r1 . degree in let c2 = r2 . spill_cost and d2 = r2 . degree in let n = c2 * d1 - c1 * d2 in if n <> 0 then n else let n = c2 - c1 in if n <> 0 then n else let n = d1 - d2 in if n <> 0 then ...
let allocate_registers ( ) = let constrained = ref OrderedRegSet . empty in let unconstrained = ref [ ] in let num_stack_slots = Array . make Proc . num_register_classes 0 in let remove_reg reg = let cl = Proc . register_class reg in if reg . spill then begin let nslots = num_stack_slots . ( cl ) in let conflict = Arra...
module type T = sig type row module Contents : Stringable val name : string val group : string option val get : row -> Contents . t val set : row -> Contents . t -> row val editable : bool val focus_on_edit : bool val sort_by : Contents . t -> Sort_key . t end
type ' a t = ( module T with type row = ' a )
let create ( type row contents ) ~ name ? group ? sort_by ? focus_on_edit ( module Contents : Stringable with type t = contents ) ~ editable ~ get ~ set = let sort_by = match sort_by with | Some f -> f | None -> fun x -> Sort_key . String ( Contents . to_string x ) in ( module struct type nonrec row = row module Conten...
let of_field ( type contents ) field ? group ? sort_by ? focus_on_edit ( module Contents : Stringable with type t = contents ) ~ editable = create ~ name ( : Field . name field ) ? group ? sort_by ? focus_on_edit ( module Contents ) ~ editable ~ get ( : Field . get field ) ~ set ( : Field . fset field ) ; ;
let name ( type row ) ( module T : T with type row = row ) = T . name
let group ( type row ) ( module T : T with type row = row ) = T . group
let editable ( type row ) ( module T : T with type row = row ) = T . editable
let focus_on_edit ( type row ) ( module T : T with type row = row ) = T . focus_on_edit
let get ( type row ) ( module T : T with type row = row ) row = T . Contents . to_string ( T . get row ) ; ;
let set ( type row ) ( module T : T with type row = row ) row string = let open Or_error . Let_syntax in let % map v = Or_error . try_with ( fun ( ) -> T . Contents . of_string string ) in T . set row v ; ;
let sort_by ( type row ) ( module T : T with type row = row ) row = T . sort_by ( T . get row )
let to_table_widget_column t = let name = name t in let group = group t in let sort_by _row_id row = sort_by t row in Ts_table . Column . create ~ header ( : Vdom . Node . text name ) ~ sort_by ? group ( ) ; ;
module Make_primitives ( Gates : Gates ) = struct include Gates let vdd = of_constant ( Constant . of_int ~ width : 1 1 ) let gnd = of_constant ( Constant . of_int ~ width : 1 0 ) let bits_lsb x = let w = width x in Array . to_list ( Array . init w ~ f ( : fun i -> select x i i ) ) ; ; let reduce_bits def op a = List ....
type nonrec ( ' a , ' b ) with_valid2 = ( ' a , ' b ) with_valid2 = { valid : ' a ; value : ' b }
type nonrec ' a with_valid = ' a with_valid
module Make ( Prims : Primitives ) = struct type t = Prims . t let equal = Prims . equal let empty = Prims . empty let is_empty = Prims . is_empty let ( -- ) a b = Prims . ( -- ) a b let width = Prims . width let [ @ cold ] raise_arg_greater_than_zero fn x = raise_s [ % message . omit_nil ( " arg to [ " ^ fn ^ " ] must...
type pending_alloc = { reg : Reg . t ; dbginfos : Debuginfo . alloc_dbginfo ; totalsz : int ; mode : Lambda . alloc_mode }
type allocation_state = No_alloc | Pending_alloc of pending_alloc
let rec combine i allocstate = match i . desc with Iend | Ireturn | Iexit _ | Iraise _ -> ( i , allocstate ) | Iop ( Ialloc { bytes = sz ; dbginfo ; mode } ) -> assert ( List . length dbginfo = 1 ) ; begin match allocstate with | Pending_alloc { reg ; dbginfos ; totalsz ; mode = prev_mode } when ( mode = prev_mode ) &&...
let fundecl f = { f with fun_body = combine_restart f . fun_body }
let get_random_partition r n k = let r = Random . State . float r 1 . 0 in let rec loop pos accratio = let accratio = accratio . + ( get_partition_ratio n k pos ) in if r <= accratio then pos else loop ( pos - 1 ) accratio in loop k 0 . 0
let set = Hashtbl . create 7901
let floyds_sampling r n k = Hashtbl . clear set ; for j = n - k + 1 to n do let t = ( Random . State . int r j ) + 1 in if Hashtbl . mem set t then ( Hashtbl . add set j true ) else ( Hashtbl . add set t true ) done ; set
type ' a optional_branching_factor = ? branching_factor : int -> ' a
type ' a with_valid = ( ' a , ' a ) with_valid2 { valid : ' a ; value : ' b }
module type TypedMath = sig type t type v val of_signal : t -> v val to_signal : v -> t val ( +: ) : v -> v -> v val ( -: ) : v -> v -> v val ( *: ) : v -> v -> v val ( <: ) : v -> v -> v val ( >: ) : v -> v -> v val ( <=: ) : v -> v -> v val ( >=: ) : v -> v -> v val ( ==: ) : v -> v -> v val ( <>: ) : v -> v -> v val...
module type Gates = sig type t [ @@ deriving sexp_of ] include Equal . S with type t := t val empty : t val is_empty : t -> bool val width : t -> int val of_constant : Constant . t -> t val to_constant : t -> Constant . t val concat_msb : t list -> t val select : t -> int -> int -> t val ( -- ) : t -> string -> t val (...
module type Primitives = sig include Gates val mux : t -> t list -> t val ( +: ) : t -> t -> t val ( -: ) : t -> t -> t val ( *: ) : t -> t -> t val ( *+ ) : t -> t -> t val ( ==: ) : t -> t -> t val ( <: ) : t -> t -> t end
module type S = sig type t [ @@ deriving sexp_of ] include Equal . S with type t := t val empty : t val is_empty : t -> bool val ( -- ) : t -> string -> t val width : t -> int val address_bits_for : int -> int val num_bits_to_represent : int -> int val of_constant : Constant . t -> t val to_constant : t -> Constant . t...
module type Comb = sig module type Gates = Gates module type Primitives = Primitives module type S = S type nonrec ' a optional_branching_factor = ' a optional_branching_factor type nonrec ( ' a , ' b ) with_valid2 = ( ' a , ' b ) with_valid2 = { valid : ' a ; value : ' b } type nonrec ' a with_valid = ( ' a , ' a ) wi...
let jobs = ref 1
let no_tag_handler _ = failwith " no_tag_handler "
let tag_handler = ref no_tag_handler
let atomize l = S ( List . map ( fun x -> A x ) l )
let atomize_paths l = S ( List . map ( fun x -> P x ) l )
let env_path = lazy begin let path_var = Sys . getenv " PATH " in let paths = try Lexers . parse_environment_path ( Lexing . from_string path_var ) with Lexers . Error msg -> raise ( Lexers . Error ( " $ PATH : " ^ msg ) ) in let norm_current_dir_name path = if path = " " then Filename . current_dir_name else path in L...
let virtual_solvers = Hashtbl . create 32
let setup_virtual_command_solver virtual_command solver = Hashtbl . replace virtual_solvers virtual_command solver
let virtual_solver virtual_command = let solver = try Hashtbl . find virtual_solvers virtual_command with Not_found -> failwith ( sbprintf " no solver for the virtual command % S \ ( setup one with Command . setup_virtual_command_solver ) " virtual_command ) in try solver ( ) with Not_found -> failwith ( Printf . sprin...
let search_in_path cmd = if Filename . is_implicit cmd then let path = List . find begin fun path -> if path = Filename . current_dir_name then sys_file_exists cmd else sys_file_exists ( filename_concat path cmd ) end !* env_path in filename_concat path cmd else cmd
let rec string_of_command_spec_with_calls call_with_tags call_with_target resolve_virtuals spec = let self = string_of_command_spec_with_calls call_with_tags call_with_target resolve_virtuals in let b = Buffer . create 256 in let first = ref true in let put_space ( ) = if ! first then first := false else Buffer . add_c...
let string_of_command_spec x = string_of_command_spec_with_calls ignore ignore false x
let string_target_and_tags_of_command_spec spec = let rtags = ref Tags . empty in let rtarget = ref " " in let union_rtags tags = rtags := Tags . union ! rtags tags in let s = string_of_command_spec_with_calls union_rtags ( ( ) := rtarget ) true spec in let target = if ! rtarget = " " then s else ! rtarget in s , targe...
let string_print_of_command_spec spec quiet pretend = let s , target , tags = string_target_and_tags_of_command_spec spec in fun ( ) -> if not quiet then Log . event ~ pretend s target tags ; s
let print_escaped_string f = Format . fprintf f " % S "
let rec print f = function | Cmd spec -> Format . pp_print_string f ( string_of_command_spec spec ) | Seq seq -> List . print print f seq | Nop -> Format . pp_print_string f " nop " | Echo ( texts , dest_path ) -> Format . fprintf f " [ @< 2 > Echo ( % a , @ % a ) ] " @ ( List . print print_escaped_string ) texts print...
let to_string x = sbprintf " % a " print x
let add_parallel_stat , dump_parallel_stats = let xmin = ref max_int in let xmax = ref 0 in let xsum = ref 0 in let xsumall = ref 0 in let xcount = ref 0 in let xcountall = ref 0 in let add_parallel_stat x = if x > 0 then begin incr xcountall ; xsumall := x + ! xsumall ; end ; if x > 1 then begin incr xcount ; xsum := ...
module Primitives = struct let do_echo texts dest_path = with_output_file dest_path begin fun oc -> List . iter ( output_string oc ) texts end let echo x y ( ) = do_echo x y ; " " end