text
stringlengths
12
786k
type fuzzstat = { unique_set : ( string , crash_id ) Hashtbl . t ; num_crashes : int ; num_runs : int ; time_spent : float ; start_time : float ; finish_time : float ; }
let null_stat ( ) = let set = Hashtbl . create 101 in { unique_set = set ; num_crashes = 0 ; num_runs = 0 ; time_spent = 0 . 0 ; start_time = 0 . 0 ; finish_time = 0 . 0 ; }
type schedule = | RoundRobin | WeightedRoundRobin | UniformTime
let schedule_to_string = function | RoundRobin -> " round - robin " | WeightedRoundRobin -> " weighted - rr " | UniformTime -> " uniform - time "
ktype cell = | Alive | Dead
let step = kern field next_field width height -> let max = fun a b -> if a > b then a else b in let min = fun a b -> if a < b then a else b in let open Std in let i = thread_idx_x + block_dim_x * block_idx_x in let y = i / height in let x = i - ( y * width ) in if y < height && x < width then beg...
let cpt = ref 0
let tot_time = ref 0 .
let measure_time f s = let t0 = Unix . gettimeofday ( ) in let a = f ( ) in let t1 = Unix . gettimeofday ( ) in Printf . printf " % s : time % d : % Fs \ n " %! s ! cpt ( t1 . - t0 ) ; tot_time := ! tot_time . + ( t1 . - t0 ) ; incr cpt ; a ; ;
let couleur n r = match n with | Alive -> Sdl . set_render_draw_color r 255 0 0 255 | Dead -> Sdl . set_render_draw_color r 0 0 255 255
let init id h w bench = let devs = Spoc . Devices . init ~ only : Devices . OpenCL ( ) in let dev = devs . ( id ) in let x1 = Vector . create ( Custom customCell ) ( h * w ) and x2 = Vector . create ( Custom customCell ) ( h * w ) and x1_cpu = Array . create ( h * w ) ...
let gpu_compute x1 x2 dev h w nb_iter bench win = Printf . printf " Will use device : % s \ n " %! dev . Spoc . Devices . general_info . Spoc . Devices . name ; ignore ( Kirc . gen ~ only : Devices . OpenCL step ) ; let threadsPerBlock = match dev . Devices . specific_info with...
let cpu_compute x1 x2 h w nb_iter = let compute t1 t2 = let cpt = ref 0 in for y = 0 to h - 1 do for x = 0 to w - 1 do let i = y * w + x in begin let left = max 0 ( x - 1 ) in let right = min ( w - 1 ) ( x + 1 ) in let top = max 0 ( y - 1 ) in let bottom = min ( h - 1 ) ...
let _ = Random . self_init ( ) ; let devid = ref 0 and w = ref 512 and h = ref 512 and nb_iter = ref 10_000 and bench = ref false and cpu = ref false in let parse_args ( ) = Arg . parse [ ( " - device " , Arg . Int ( fun i -> devid := i ) , " number of the device [ 0 ...
type stat = { minor_words : float ; promoted_words : float ; major_words : float ; minor_collections : int ; major_collections : int ; heap_words : int ; heap_chunks : int ; live_words : int ; live_blocks : int ; free_words : int ; free_blocks : int ; largest_free : int ; fragment...
type control = { mutable minor_heap_size : int ; mutable major_heap_increment : int ; mutable space_overhead : int ; mutable verbose : int ; mutable max_overhead : int ; mutable stack_limit : int ; mutable allocation_policy : int ; window_size : int ; custom_major_ratio : int ; custom_mino...
let print_stat c = let st = stat ( ) in fprintf c " minor_collections : % d \ n " st . minor_collections ; fprintf c " major_collections : % d \ n " st . major_collections ; fprintf c " compactions : % d \ n " st . compactions ; fprintf c " forced_major_collections : % d \ n ...
let allocated_bytes ( ) = let ( mi , pro , ma ) = counters ( ) in ( mi . + ma . - pro ) . * float_of_int ( Sys . word_size / 8 ) " caml_final_register_called_without_value "
type alarm = bool ref
type alarm_rec = { active : alarm ; f : unit -> unit }
let rec call_alarm arec = if ( ! arec . active ) then begin finalise call_alarm arec ; arec . f ( ) ; end
let [ @ inline never ] create_alarm f = let arec = { active = ref true ; f = f } in finalise call_alarm arec ; arec . active
let delete_alarm a = a := false
module Memprof = struct type allocation_source = Normal | Marshal | Custom type allocation = { n_samples : int ; size : int ; source : allocation_source ; callstack : Printexc . raw_backtrace } type ( ' minor , ' major ) tracker = { alloc_minor : allocation -> ' minor option ; al...
type verbosity_t = Silent | Report | Verbose | Debug | DebugPlus
type t = { mutable verbosity : verbosity_t ; mutable strict : bool ; mutable parallel_jobs : int ; mutable dump_dot : bool ; mutable color : bool ; mutable bin_annot : bool ; mutable short_path : bool ; mutable ocamlmklib : bool ; mutable ocaml_extra_args : string list ; }
let env_variables = [ " ocamlopt " ; " ocamlc " ; " ocaml " ; " ocamldep " ; " ocamldoc " ; " ocamlyacc " ; " ocamllex " ; " ocamlmklib " ; " ocamlmktop " ; " cc " ; " ranlib " ; " ar " ; " ld " ; " pkg - config " ; " camlp4 " ;...
let env_ = let h : ( string , string option ) Hashtbl . t = Hashtbl . create ( List . length env_variables ) in List . iter ( fun v -> Hashtbl . add h v None ) env_variables ; h
let get_env field = try Hashtbl . find env_ field with Not_found -> raise ( UnknownOption field )
let set_env field value = if not ( Hashtbl . mem env_ field ) then raise ( UnknownOption field ) ; Hashtbl . replace env_ field ( Some value )
let target_options_defaults = [ ( " executable - profiling " , false ) ; ( " executable - debugging " , false ) ; ( " executable - native " , true ) ; ( " executable - bytecode " , false ) ; ( " executable - as - obj " , false ) ; ( " library - p...
let target_options_ = let h = Hashtbl . create ( List . length target_options_defaults ) in List . iter ( fun ( k , v ) -> Hashtbl . add h k v ) target_options_defaults ; h
let rec set_target_options field value = if not ( Hashtbl . mem target_options_ field ) then raise ( UnknownOption field ) ; Hashtbl . replace target_options_ field value ; ( match field , value with | " executable - profiling " , true -> set_target_options " library - profiling " tru...
let get_target_options_keys ( ) = hashtbl_keys target_options_
let get_target_options ( ) = hashtbl_toList target_options_
let get_target_option field = try Hashtbl . find target_options_ field with Not_found -> raise ( UnknownOption field )
let defaults = { verbosity = Report ; strict = false ; parallel_jobs = 2 ; dump_dot = false ; color = false ; bin_annot = true ; short_path = false ; ocamlmklib = true ; ocaml_extra_args = [ ] ; }
let default z = function | Some x -> x | None -> z
module StringSet = Set . Make ( struct type t = string let compare = compare end )
type parameter_or_reference = [ ` Parameter of Swagger_j . parameter | ` Reference of Swagger_j . reference ]
type response_or_reference = [ ` Response of Swagger_j . response | ` Reference of Swagger_j . reference ] [ @@@ end ]
let merge_params ( ps1 : Swagger_j . parameter list ) ( ps2 : Swagger_j . parameter list ) = let rec merge acc = function | [ ] -> acc | ( p : Swagger_j . parameter ) :: ps -> let same_name ( q : Swagger_j . parameter ) = let open Swagger_j in p . name = q . name in if List ...
let reference_module_and_type ~ reference_base ~ reference_root r = let ref_module = Mod . reference_module ~ reference_base ~ reference_root r in let ref_type = sprintf " % s . t " ref_module in ( Some ref_module , ref_type )
let parse_or_reference f json = let open Yojson . Basic . Util in let str = Yojson . Safe . to_string json in match json |> Yojson . Safe . to_basic |> member " $ ref " with | ` Null -> f str | _ -> failwith " reference not supported "
let parse_parameters = function | Some ps -> List . map ( parse_or_reference Swagger_j . parameter_of_string ) ps | None -> [ ]
let parse_response r = parse_or_reference Swagger_j . response_of_string r
let parse_responses = List . map ( fun ( s , r ) -> ( s , parse_response r ) )
let resp_type ~ reference_base ~ reference_root ( resp : Swagger_j . response ) = match resp . schema with | None -> ( None , " unit " ) | Some s -> let s = Schema . create ~ reference_base ~ reference_root s in match Schema . reference s with | Some r -> reference_module_and_type ~ ...
let rec return_type ~ reference_root ~ reference_base ( resps : Swagger_j . responses ) = let is_error code = if String . lowercase_ascii code = " default " then true else let code = int_of_string code in code < 200 || code >= 300 in let responses_match ( r1 : Swagger_j . response ) ( r...
let make_dups params = List . fold_left ( fun dups ( p : Swagger_j . parameter ) -> match StringMap . find_opt p . name dups with | Some count -> StringMap . add p . name ( count + 1 ) dups | None -> StringMap . add p . name 1 dups ) StringMap . empty params
let operation_val ~ root : _ ~ reference_base ~ reference_root name ( params : Swagger_j . parameter list ) = function | Some ( op : Swagger_j . operation ) -> let op_params = parse_parameters op . parameters in let params = merge_params params op_params in let dups = make_dups params in let ...
let path_val path = Val . create ( Val . Sig . constant " request_path_template " ) ( Val . Impl . constant " request_path_template " path )
let path_item_vals ~ root ~ reference_base ~ reference_root ~ path ( item : Swagger_j . path_item ) : Val . t list = let params = parse_parameters item . parameters in let operation_val name = operation_val ~ root ~ reference_base ~ reference_root name params in let get = operation_val " get " ...
let definition_module ( ? path = [ ] ) ~ root ~ reference_base ~ name ( schema : Swagger_j . schema ) = let required = default [ ] schema . required in let properties = default [ ] schema . properties in let create_param name type_ required_params = let n = Param . name name in if...
let rec insert_module m root = function | [ ] -> Mod . add_mod m root | p :: ps -> match Mod . find_submodule p root with | Some subm -> Mod . add_mod ( insert_module m subm ps ) root | None -> let subm = Mod . empty p ~ path ( : Mod . qualified_path root ) ( ) in Mod . add_mod ...
let remove_base base segments = match base , segments with | Some base , s :: ss when base = s -> ss | _ -> segments [ @@@ end ]
let rec build_paths ~ root ~ path_base ~ reference_base ~ reference_root = function | [ ] -> root | ( path , item ) :: paths -> let parents_and_child = path |> Mod . strip_base path_base |> String . split_on_char ' ' / |> List . filter ( ( ) " " ) <> |> unsnoc in match p...
let rec build_definitions ~ root ~ definition_base ~ reference_base l = match l with | [ ] -> root | ( name , ( schema : Swagger_j . schema ) ) :: defs when schema . ref = None -> let parents_and_child = name |> Mod . strip_base definition_base |> Mod . split_ref |> unsnoc in ( ma...
let of_swagger ( ? path_base = " " ) ( ? definition_base = " " ) ( ? reference_base = " " ) ~ reference_root s = let open Swagger_j in let definitions = default [ ] s . definitions in let title = s . info . title in let defs = build_definitions ~ root ( : Mod . empty r...
let object_module = String . trim { |
module Object = struct module type Value = sig type value val value_of_yojson : Yojson . Safe . t -> ( value , string ) result val value_to_yojson : value -> Yojson . Safe . t end module type S = sig type value type t = ( string * value ) list [ @@ deriving yojson ] end module Make ( V...
let to_string m = sprintf " % s \ n \ n % s " object_module ( Mod . to_string m )
let clock = input " clock " 1
let reset_sig = input " reset " 1
let gen_bits_string width = let % map w = Generator . list_with_length width Generator . bool in List . map w ~ f ( : fun b -> if b then ' 1 ' else ' 0 ' ) |> String . of_char_list ; ;
let gen_const width = let % map s = gen_bits_string width in of_bit_string s ; ;
let gen_bits width = let % map s = gen_bits_string width in Bits . of_string s ; ;
let gen_width = let % map w = Generator . of_list [ 1 ; 2 ; 3 ; 64 ; 100 ] in Int . min max_width w ; ;
let rec gen_op2 width depth inputs = let % bind op = Generator . of_list [ ( +: ) ; ( -: ) ; ( &: ) ; ( |: ) ] in let % bind arg1 = gen_signal width ( depth - 1 ) inputs in let % map arg2 = gen_signal width ( depth - 1 ) inputs in op arg1 arg2 if width = 1 then gen_c...
let gen ~ width ~ depth ~ inputs = gen_signal width depth inputs
let gen_circuit ~ allow_inputs ~ depth = let % bind width = gen_width in let % bind input_widths = if allow_inputs then Generator . list gen_width else Generator . return [ ] in let inputs = List . mapi input_widths ~ f ( : fun i width -> Signal . input ( sprintf " input % d " i ) widt...
let rec gen_bits_list = function | width :: rest -> let % map b = gen_bits width and rest_b = gen_bits_list rest in b :: rest_b | [ ] -> Generator . return [ ] ; ;
let gen_input_data circuit = let inputs = Circuit . inputs circuit |> List . filter ~ f ( : fun signal -> match List . hd_exn ( Signal . names signal ) with | " reset " | " clock " -> false | _ -> true ) in let names = List . map inputs ~ f ( : fun signal -> List . hd_exn (...
type t = { suffix : string ; modname : ( Modname . t -> Modname . t ) ; commands : ( filepath -> filepath -> string -> string list list ) ; generated_files : ( filename -> string -> filename ) ; }
let generators = ref [ { suffix = " mll " ; modname = ( fun m -> m ) ; commands = ( fun src dest_root _ -> [ [ Prog . getOcamlLex ( ) ; " - o " ; ( fp_to_string dest_root ) ^ " . ml " ; fp_to_string src ] ] ) ; generated_files = ( fun f _ -> ( chop...
let is_generator_ext ext = List . exists ( fun gen -> gen . suffix = ext ) ! generators
let get_generator fp = let ext = Filetype . of_filepath fp in let s = match ext with Filetype . FileOther s -> s | _ -> raise ( GeneratorNotFound ( fp_to_string fp ) ) in List . find ( fun gen -> gen . suffix = s ) ! generators
let run dest src modName = verbose Debug " generator dest = % s src = % s \ n " %! ( fp_to_string dest ) ( fp_to_string src ) ; let gen = get_generator src in let args = gen . commands src dest modName in List . iter ( fun arg -> match Process . run arg with | Process . Success ( _ ...
type token = Kwd of string | Ident of string | Int of int | Float of float | String of string | Char of char
let initial_buffer = Bytes . create 32
let buffer = ref initial_buffer
let bufpos = ref 0
let reset_buffer ( ) = buffer := initial_buffer ; bufpos := 0
let store c = if ! bufpos >= Bytes . length ! buffer then begin let newbuffer = Bytes . create ( 2 * ! bufpos ) in Bytes . blit ! buffer 0 newbuffer 0 ! bufpos ; buffer := newbuffer end ; Bytes . set ! buffer ! bufpos c ; incr bufpos
let get_string ( ) = let s = Bytes . sub_string ! buffer 0 ! bufpos in buffer := initial_buffer ; s
let make_lexer keywords = let kwd_table = Hashtbl . create 17 in List . iter ( fun s -> Hashtbl . add kwd_table s ( Kwd s ) ) keywords ; let ident_or_keyword id = try Hashtbl . find kwd_table id with Not_found -> Ident id and keyword_or_error c = let s = String . make 1 c in try Hashtbl . ...
module type OBJ = sig type t val obj : t -> ' a val is_block : t -> bool val tag : t -> int val size : t -> int val field : t -> int -> t end
module type EVALPATH = sig type value val eval_path : Path . t -> value exception Error val same_value : value -> value -> bool end
module type S = sig type t val install_printer : Path . t -> Types . type_expr -> ( formatter -> t -> unit ) -> unit val remove_printer : Path . t -> unit val outval_of_untyped_exception : t -> Outcometree . out_value val outval_of_value : int -> int -> ( int -> t -> Types . type_expr -...
module Make ( O : OBJ ) ( EVP : EVALPATH with type value = O . t ) = struct type t = O . t let outval_of_untyped_exception_args obj start_offset = if O . size obj > start_offset then begin let list = ref [ ] in for i = start_offset to O . size obj - 1 do let arg = O . field obj i in if...
let rec parse_int i t = match i . e with | Id ( _loc , s ) -> ( let is_mutable = ref false in ( try let var = Hashtbl . find ! current_args ( string_of_ident s ) in ( is_mutable := var . is_mutable ; match var . var_type with | TUnknown -> var . var_type <- t | x when x = t -> ...
let remove_int_var var = match var . e with | Id ( _loc , s ) -> Hashtbl . remove ! current_args ( string_of_ident s ) ; | _ -> failwith " error new_var "
let rec parse_int2 i t = match i . e with | Id ( _loc , s ) -> ( try let var = ( Hashtbl . find ! current_args ( string_of_ident s ) ) in if var . is_global then <: expr < global_int_var $ ExId ( _loc , s ) $>> else <: expr < var $ ExInt ( _loc , string_of_int var . n ) ...
type src = | C1 of int | C2 of int
type dst = | A1 | A2 | A3 | A4 | A5 | A6 | A7 | A8 | A9 | A10 | A11 | A12 | A13 | A14 | A15 | A16 | A17 | A18 | A19 | A20 | A21 | A22 | A23 | A24 | A25 | A26 | A27 | A28 | A29 | A30 | A31 | A32 | A33 | A34 | A35 | A36 | A37 | A38 | A39 | A40 | A41 | A42 | A43 | A44 | A45 |...
let test src f g = let dst = if f ( ) then of_src src else A300 in g dst
type arg = { n : string ; type ' : string ; optional : bool }
type func = { name : string ; args : arg list ; ret : string ; version : int ; }
type funcs = func list String . Map . t
let cleanup_funcs funcs = let find_dupes = function | [ f ; f ' ] as funcs -> if f . version <> f ' . version && f . args = f ' . args then ( if f . version < f ' . version then [ f ] else [ f ' ] ) else funcs | funcs -> funcs in String . Map . map find_dupes funcs