text
stringlengths
12
786k
let help_action ( ) = raise ( Stop ( Unknown " - help " ) )
let add_help speclist = let add1 = try ignore ( assoc3 " - help " speclist ) ; [ ] with Not_found -> [ " - help " , Unit help_action , " Display this list of options " ] and add2 = try ignore ( assoc3 " -- help " speclist ) ; [ ] with Not_found -> [ " -- help " ...
let usage_b buf speclist errmsg = bprintf buf " % s \ n " errmsg ; List . iter ( print_spec buf ) ( add_help speclist )
let usage_string speclist errmsg = let b = Buffer . create 200 in usage_b b speclist errmsg ; Buffer . contents b
let usage speclist errmsg = eprintf " % s " ( usage_string speclist errmsg )
let current = ref 0
let bool_of_string_opt x = try Some ( bool_of_string x ) with Invalid_argument _ -> None
let int_of_string_opt x = try Some ( int_of_string x ) with Failure _ -> None
let float_of_string_opt x = try Some ( float_of_string x ) with Failure _ -> None
let parse_and_expand_argv_dynamic_aux allow_expand current argv speclist anonfun errmsg = let initpos = ! current in let convert_error error = let b = Buffer . create 200 in let progname = if initpos < ( Array . length ! argv ) then ! argv . ( initpos ) else " ( ) " ? in begin match err...
let parse_and_expand_argv_dynamic current argv speclist anonfun errmsg = parse_and_expand_argv_dynamic_aux true current argv speclist anonfun errmsg
let parse_argv_dynamic ( ? current = current ) argv speclist anonfun errmsg = parse_and_expand_argv_dynamic_aux false current ( ref argv ) speclist anonfun errmsg
let parse_argv ( ? current = current ) argv speclist anonfun errmsg = parse_argv_dynamic ~ current : current argv ( ref speclist ) anonfun errmsg
let parse l f msg = try parse_argv Sys . argv l f msg with | Bad msg -> eprintf " % s " msg ; exit 2 | Help msg -> printf " % s " msg ; exit 0
let parse_dynamic l f msg = try parse_argv_dynamic Sys . argv l f msg with | Bad msg -> eprintf " % s " msg ; exit 2 | Help msg -> printf " % s " msg ; exit 0
let parse_expand l f msg = try let argv = ref Sys . argv in let spec = ref l in let current = ref ( ! current ) in parse_and_expand_argv_dynamic current argv spec f msg with | Bad msg -> eprintf " % s " msg ; exit 2 | Help msg -> printf " % s " msg ; exit 0
let second_word s = let len = String . length s in let rec loop n = if n >= len then len else if s . [ n ] = ' ' then loop ( n + 1 ) else n in match String . index s ' \ t ' with | n -> loop ( n + 1 ) | exception Not_found -> begin match String . index s ' ' with | n -> l...
let max_arg_len cur ( kwd , spec , doc ) = match spec with | Symbol _ -> max cur ( String . length kwd ) | _ -> max cur ( String . length kwd + second_word doc )
let replace_leading_tab s = let seen = ref false in String . map ( function ' \ t ' when not ! seen -> seen := true ; ' ' | c -> c ) s
let add_padding len ksd = match ksd with | ( _ , _ , " " ) -> ksd | ( kwd , ( Symbol _ as spec ) , msg ) -> let cutcol = second_word msg in let spaces = String . make ( ( max 0 ( len - cutcol ) ) + 3 ) ' ' in ( kwd , spec , " \ n " ^ spaces ^ replace_...
let align ( ? limit = max_int ) speclist = let completed = add_help speclist in let len = List . fold_left max_arg_len 0 completed in let len = min len limit in List . map ( add_padding len ) completed
let trim_cr s = let len = String . length s in if len > 0 && String . get s ( len - 1 ) = ' \ r ' then String . sub s 0 ( len - 1 ) else s
let read_aux trim sep file = let ic = open_in_bin file in let buf = Buffer . create 200 in let words = ref [ ] in let stash ( ) = let word = Buffer . contents buf in let word = if trim then trim_cr word else word in words := word :: ! words ; Buffer . clear buf in begin try while true do let ...
let read_arg = read_aux true ' \ n '
let read_arg0 = read_aux false ' \ x00 '
let write_aux sep file args = let oc = open_out_bin file in Array . iter ( fun s -> fprintf oc " % s % c " s sep ) args ; close_out oc
let write_arg = write_aux ' \ n '
let write_arg0 = write_aux ' \ x00 '
let get_error_when_null_denominator ( ) = ! error_when_null_denominator_flag error_when_null_denominator_flag := choice ; ;
let get_normalize_ratio ( ) = ! normalize_ratio_flag
let get_normalize_ratio_when_printing ( ) = ! normalize_ratio_when_printing_flag normalize_ratio_when_printing_flag := choice ; ;
let get_floating_precision ( ) = ! floating_precision
let get_approx_printing ( ) = ! approx_printing_flag
let arith_print_string s = print_string s ; print_string " --> " ; ;
let arith_print_bool = function true -> print_string " ON " ; ;
let arith_status ( ) = print_newline ( ) ; arith_print_string " Normalization during computation " ; arith_print_bool ( get_normalize_ratio ( ) ) ; print_newline ( ) ; print_string " ( returned by get_normalize_ratio ( ) ) " ; print_newline ( ) ; print_string " ( ...
type ' a t = ' a array ' a array -> int -> ' a array -> int -> int -> unit = " caml_array_blit " ' a array -> int -> int -> ' a -> unit = " caml_array_fill "
module Floatarray = struct external create : int -> floatarray = " caml_floatarray_create " external length : floatarray -> int = " % floatarray_length " external get : floatarray -> int -> float = " % floatarray_safe_get " external set : floatarray -> int -> float -> unit = " % floatar...
let init l f = if l = 0 then [ ] || else if l < 0 then invalid_arg " Array . init " else let res = create l ( f 0 ) in for i = 1 to pred l do unsafe_set res i ( f i ) done ; res
let make_matrix sx sy init = let res = create sx [ ] || in for x = 0 to pred sx do unsafe_set res x ( create sy init ) done ; res
let copy a = let l = length a in if l = 0 then [ ] || else unsafe_sub a 0 l
let append a1 a2 = let l1 = length a1 in if l1 = 0 then copy a2 else if length a2 = 0 then unsafe_sub a1 0 l1 else append_prim a1 a2
let sub a ofs len = if ofs < 0 || len < 0 || ofs > length a - len then invalid_arg " Array . sub " else unsafe_sub a ofs len
let fill a ofs len v = if ofs < 0 || len < 0 || ofs > length a - len then invalid_arg " Array . fill " else unsafe_fill a ofs len v
let blit a1 ofs1 a2 ofs2 len = if len < 0 || ofs1 < 0 || ofs1 > length a1 - len || ofs2 < 0 || ofs2 > length a2 - len then invalid_arg " Array . blit " else unsafe_blit a1 ofs1 a2 ofs2 len
let iter f a = for i = 0 to length a - 1 do f ( unsafe_get a i ) done
let iter2 f a b = if length a <> length b then invalid_arg " Array . iter2 : arrays must have the same length " else for i = 0 to length a - 1 do f ( unsafe_get a i ) ( unsafe_get b i ) done
let map f a = let l = length a in if l = 0 then [ ] || else begin let r = create l ( f ( unsafe_get a 0 ) ) in for i = 1 to l - 1 do unsafe_set r i ( f ( unsafe_get a i ) ) done ; r end
let map2 f a b = let la = length a in let lb = length b in if la <> lb then invalid_arg " Array . map2 : arrays must have the same length " else begin if la = 0 then [ ] || else begin let r = create la ( f ( unsafe_get a 0 ) ( unsafe_get b 0 ) ) in for i = 1 to la - 1 do unsafe_set ...
let iteri f a = for i = 0 to length a - 1 do f i ( unsafe_get a i ) done
let mapi f a = let l = length a in if l = 0 then [ ] || else begin let r = create l ( f 0 ( unsafe_get a 0 ) ) in for i = 1 to l - 1 do unsafe_set r i ( f i ( unsafe_get a i ) ) done ; r end
let to_list a = let rec tolist i res = if i < 0 then res else tolist ( i - 1 ) ( unsafe_get a i :: res ) in tolist ( length a - 1 ) [ ]
let rec list_length accu = function | [ ] -> accu | _ :: t -> list_length ( succ accu ) t
let of_list = function [ ] -> [ ] || | hd :: tl as l -> let a = create ( list_length 0 l ) hd in let rec fill i = function [ ] -> a | hd :: tl -> unsafe_set a i hd ; fill ( i + 1 ) tl in fill 1 tl
let fold_left f x a = let r = ref x in for i = 0 to length a - 1 do r := f ! r ( unsafe_get a i ) done ; ! r
let fold_right f a x = let r = ref x in for i = length a - 1 downto 0 do r := f ( unsafe_get a i ) ! r done ; ! r
let exists p a = let n = length a in let rec loop i = if i = n then false else if p ( unsafe_get a i ) then true else loop ( succ i ) in loop 0
let for_all p a = let n = length a in let rec loop i = if i = n then true else if p ( unsafe_get a i ) then loop ( succ i ) else false in loop 0
let for_all2 p l1 l2 = let n1 = length l1 and n2 = length l2 in if n1 <> n2 then invalid_arg " Array . for_all2 " else let rec loop i = if i = n1 then true else if p ( unsafe_get l1 i ) ( unsafe_get l2 i ) then loop ( succ i ) else false in loop 0
let exists2 p l1 l2 = let n1 = length l1 and n2 = length l2 in if n1 <> n2 then invalid_arg " Array . exists2 " else let rec loop i = if i = n1 then false else if p ( unsafe_get l1 i ) ( unsafe_get l2 i ) then true else loop ( succ i ) in loop 0
let mem x a = let n = length a in let rec loop i = if i = n then false else if compare ( unsafe_get a i ) x = 0 then true else loop ( succ i ) in loop 0
let memq x a = let n = length a in let rec loop i = if i = n then false else if x == ( unsafe_get a i ) then true else loop ( succ i ) in loop 0
let sort cmp a = let maxson l i = let i31 = i + i + i + 1 in let x = ref i31 in if i31 + 2 < l then begin if cmp ( get a i31 ) ( get a ( i31 + 1 ) ) < 0 then x := i31 + 1 ; if cmp ( get a ! x ) ( get a ( i31 + 2 ) ) < 0 then x := i31 + 2 ; ! x end else if i31 + 1 ...
let stable_sort cmp a = let merge src1ofs src1len src2 src2ofs src2len dst dstofs = let src1r = src1ofs + src1len and src2r = src2ofs + src2len in let rec loop i1 s1 i2 s2 d = if cmp s1 s2 <= 0 then begin set dst d s1 ; let i1 = i1 + 1 in if i1 < src1r then loop i1 ( get a i1 ) i2 s2 ( d + 1 ) ...
let to_seq a = let rec aux i ( ) = if i < length a then let x = unsafe_get a i in Seq . Cons ( x , aux ( i + 1 ) ) else Seq . Nil in aux 0
let to_seqi a = let rec aux i ( ) = if i < length a then let x = unsafe_get a i in Seq . Cons ( ( i , x ) , aux ( i + 1 ) ) else Seq . Nil in aux 0
let of_rev_list = function [ ] -> [ ] || | hd :: tl as l -> let len = list_length 0 l in let a = create len hd in let rec fill i = function [ ] -> a | hd :: tl -> unsafe_set a i hd ; fill ( i - 1 ) tl in fill ( len - 2 ) tl
let of_seq i = let l = Seq . fold_left ( fun acc x -> x :: acc ) [ ] i in of_rev_list l
let bigarray n = [ | ] |
let test1 ( ) = let a = bigarray 12345 in Gc . full_major ( ) ; for i = 0 to Array . length a - 1 do if a . ( i ) <> 12345 + i then print_string " Test1 : error \ n " done
let testcopy a = Array . copy a = a
let test2 ( ) = if not ( testcopy [ | 1 ; 2 ; 3 ; 4 ; 5 ] ) | then print_string " Test2 : failed on int array \ n " ; if not ( testcopy [ | 1 . 2 ; 2 . 3 ; 3 . 4 ; 4 . 5 ] ) | then print_string " Test2 : failed on float array \ n " ; if not ( ...
module AbstractFloat = ( struct type t = float let to_float x = x let from_float x = x end : sig type t val to_float : t -> float val from_float : float -> t end )
let test3 ( ) = let t1 = AbstractFloat . from_float 1 . 0 and t2 = AbstractFloat . from_float 2 . 0 and t3 = AbstractFloat . from_float 3 . 0 in let v = [ | t1 ; t2 ; t3 ] | in let w = Array . make 2 t1 in let u = Array . copy v in if not ( AbstractFloat . to_float v . ...
let test4 ( ) = let a = bigarray 0 in let b = Array . sub a 50 10 in if b <> [ | 50 ; 51 ; 52 ; 53 ; 54 ; 55 ; 56 ; 57 ; 58 ; 59 ] | then print_string " Test4 : failed \ n "
let test5 ( ) = if Array . append [ | 1 ; 2 ; 3 ] | [ | 4 ; 5 ] | <> [ | 1 ; 2 ; 3 ; 4 ; 5 ] | then print_string " Test5 : failed on int arrays \ n " ; if Array . append [ | 1 . 0 ; 2 . 0 ; 3 . 0 ] | [ | 4 . 0 ; 5 . 0 ] | ...
let test6 ( ) = let a = [ | 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ] | in let b = Array . concat [ a ; a ; a ; a ; a ; a ; a ; a ; a ; a ] in if not ( Array . length b = 100 && b . ( 6 ) = 6 && b . ( 42 ) = 2 && b . ( 99 ) ...
let test7 ( ) = let a = Array . make 10 " a " in let b = [ | " b1 " ; " b2 " ; " b3 " ] | in Array . blit b 0 a 5 3 ; if a <> [ " | a " ; " a " ; " a " ; " a " ; " a " ; " b1 " ; " b2 " ; " b3 " ; " a " ; " a " ] ...
let test8 ( ) = ( try ignore ( Array . sub [ ] || 0 1 ) ; print_string " Test 8 . 1 : failed \ n " with Invalid_argument _ -> ( ) ) ; ( try ignore ( Array . sub [ | 3 ; 4 ] | 1 ( - 1 ) ) ; print_string " Test 8 . 2 : failed \ n " with Invali...
let _ = test1 ( ) ; test2 ( ) ; test3 ( ) ; test4 ( ) ; test5 ( ) ; test6 ( ) ; test7 ( ) ; test8 ( ) ; exit 0
type error = | Assembler_error of string | Mismatched_for_pack of string option | Asm_generation of string * Emitaux . error
let cmm_invariants ppf fd_cmm = let print_fundecl = if ! Clflags . dump_cmm then Printcmm . fundecl else fun ppf fdecl -> Format . fprintf ppf " % s " fdecl . fun_name in if ! Clflags . cmm_invariants && Cmm_invariants . run ppf fd_cmm then Misc . fatal_errorf " Cmm invariants failed on follo...
let liveness phrase = Liveness . fundecl phrase ; phrase
let dump_if ppf flag message phrase = if ! flag then Printmach . phase message ppf phrase
let pass_dump_if ppf flag message phrase = dump_if ppf flag message phrase ; phrase
let pass_dump_linear_if ppf flag message phrase = if ! flag then fprintf ppf " *** % s . @% a . " @ message Printlinear . fundecl phrase ; phrase
let start_from_emit = ref true
let should_save_before_emit ( ) = should_save_ir_after Compiler_pass . Scheduling && ( not ! start_from_emit )
let linear_unit_info = { Linear_format . unit_name = " " ; items = [ ] ; for_pack = None ; }
let reset ( ) = start_from_emit := false ; if should_save_before_emit ( ) then begin linear_unit_info . unit_name <- Compilenv . current_unit_name ( ) ; linear_unit_info . items <- [ ] ; linear_unit_info . for_pack <- ! Clflags . for_package ; end
let save_data dl = if should_save_before_emit ( ) then begin linear_unit_info . items <- Linear_format . ( Data dl ) :: linear_unit_info . items end ; dl
let save_linear f = if should_save_before_emit ( ) then begin linear_unit_info . items <- Linear_format . ( Func f ) :: linear_unit_info . items end ; f
let write_linear prefix = if should_save_before_emit ( ) then begin let filename = Compiler_pass . ( to_output_filename Scheduling ~ prefix ) in linear_unit_info . items <- List . rev linear_unit_info . items ; Linear_format . save filename linear_unit_info end
let should_emit ( ) = not ( should_stop_after Compiler_pass . Scheduling )
let if_emit_do f x = if should_emit ( ) then f x else ( )
let emit_begin_assembly = if_emit_do Emit . begin_assembly
let emit_end_assembly = if_emit_do Emit . end_assembly
let emit_data = if_emit_do Emit . data
let emit_fundecl fd = if should_emit ( ) then begin try Profile . record ~ accumulate : true " emit " Emit . fundecl fd with Emitaux . Error e -> raise ( Error ( Asm_generation ( fd . Linear . fun_name , e ) ) ) end
let rec regalloc ~ ppf_dump round fd = if round > 50 then fatal_error ( fd . Mach . fun_name ^ " : function too complex , cannot complete register allocation " ) ; dump_if ppf_dump dump_live " Liveness analysis " fd ; let num_stack_slots = if ! use_linscan then begin Interval . build_int...