text
stringlengths
0
601k
let bound = Node ( String . Set . empty , String . Map . empty )
let get_map ( Node ( _s , m ) ) = m
let make_leaf s = Node ( String . Set . singleton s , String . Map . empty )
let make_node m = Node ( String . Set . empty , m )
let rec weaken_map s ( Node ( s0 , m0 ) ) = Node ( String . Set . union s s0 , String . Map . map ( weaken_map s ) m0 )
let rec collect_free ( Node ( s , m ) ) = String . Map . fold ( fun _ n -> String . Set . union ( collect_free n ) ) m s
let rec lookup_free p m = match p with [ ] -> raise Not_found | s :: p -> let Node ( f , m ' ) = String . Map . find s m in try lookup_free p m ' with Not_found -> f
let rec lookup_map lid m = match lid with Lident s -> String . Map . find s m | Ldot ( l , s ) -> String . Map . find s ( get_map ( lookup_map l m ) ) | Lapply _ -> raise Not_found
let free_structure_names = ref String . Set . empty
let add_names s = free_structure_names := String . Set . union s ! free_structure_names
let rec add_path bv ( ? p [ ] ) = = function | Lident s -> let free = try lookup_free ( s :: p ) bv with Not_found -> String . Set . singleton s in add_names free | Ldot ( l , s ) -> add_path bv ~ p ( : s :: p ) l | Lapply ( l1 , l2 ) -> add_path bv l1 ; add_path bv l2
let open_module bv lid = match lookup_map lid bv with | Node ( s , m ) -> add_names s ; String . Map . fold String . Map . add m bv | exception Not_found -> add_path bv lid ; bv
let add_parent bv lid = match lid . txt with Ldot ( l , _s ) -> add_path bv l | _ -> ( )
let add_module_path bv lid = add_path bv lid . txt
let handle_extension ext = match ( fst ext ) . txt with | " error " | " ocaml . error " -> raise ( Location . Error ( Builtin_attributes . error_of_extension ext ) ) | _ -> ( )
let rec add_type bv ty = match ty . ptyp_desc with Ptyp_any -> ( ) | Ptyp_var _ -> ( ) | Ptyp_arrow ( _ , t1 , t2 ) -> add_type bv t1 ; add_type bv t2 | Ptyp_tuple tl -> List . iter ( add_type bv ) tl | Ptyp_constr ( c , tl ) -> add bv c ; List . iter ( add_type bv ) tl | Ptyp_object ( fl , _ ) -> List . iter ( fun { p...
let add_opt add_fn bv = function None -> ( ) | Some x -> add_fn bv x
let add_constructor_arguments bv = function | Pcstr_tuple l -> List . iter ( add_type bv ) l | Pcstr_record l -> List . iter ( fun l -> add_type bv l . pld_type ) l
let add_constructor_decl bv pcd = add_constructor_arguments bv pcd . pcd_args ; Option . iter ( add_type bv ) pcd . pcd_res
let add_type_declaration bv td = List . iter ( fun ( ty1 , ty2 , _ ) -> add_type bv ty1 ; add_type bv ty2 ) td . ptype_cstrs ; add_opt add_type bv td . ptype_manifest ; let add_tkind = function Ptype_abstract -> ( ) | Ptype_variant cstrs -> List . iter ( add_constructor_decl bv ) cstrs | Ptype_record lbls -> List . ite...
let add_extension_constructor bv ext = match ext . pext_kind with Pext_decl ( args , rty ) -> add_constructor_arguments bv args ; Option . iter ( add_type bv ) rty | Pext_rebind lid -> add bv lid
let add_type_extension bv te = add bv te . ptyext_path ; List . iter ( add_extension_constructor bv ) te . ptyext_constructors
let add_type_exception bv te = add_extension_constructor bv te . ptyexn_constructor
let pattern_bv = ref String . Map . empty
let rec add_pattern bv pat = match pat . ppat_desc with Ppat_any -> ( ) | Ppat_var _ -> ( ) | Ppat_alias ( p , _ ) -> add_pattern bv p | Ppat_interval _ | Ppat_constant _ -> ( ) | Ppat_tuple pl -> List . iter ( add_pattern bv ) pl | Ppat_construct ( c , op ) -> add bv c ; add_opt add_pattern bv op | Ppat_record ( pl , ...
let add_pattern bv pat = pattern_bv := bv ; add_pattern bv pat ; ! pattern_bv
let rec add_expr bv exp = match exp . pexp_desc with Pexp_ident l -> add bv l | Pexp_constant _ -> ( ) | Pexp_let ( rf , pel , e ) -> let bv = add_bindings rf bv pel in add_expr bv e | Pexp_fun ( _ , opte , p , e ) -> add_opt add_expr bv opte ; add_expr ( add_pattern bv p ) e | Pexp_function pel -> add_cases bv pel | P...
type dependency = Libname . t * ( Expr . t option )
type cdependency = string * ( Expr . t option )
type dep_opt = { dep_includes : filepath list ; dep_pp : Pp . t }
let parse_output_KsemiVs onNonKV mapFstTy mapSndTys out = List . map ( fun ( k , mv ) -> match mv with | None -> onNonKV k | Some v -> ( mapFstTy k , List . map mapSndTys ( string_words_noempty v ) ) ) ( List . map Utils . toKV ( string_lines_noempty out ) )
let runOcamldep dopt srcFile = let wrap_module_safe f = try Modname . wrap f with _ -> raise ( BuildDepAnalyzeFailed ( " ocamldep returned a bad module name " ^ f ) ) in let fileType = Filetype . of_filepath srcFile in let baseFile = fp_to_string srcFile in let files = if fileType = Filetype . FileML then [ baseFile ; ...
let joinLines s = let s = bytes_of_string s in let s_end = bytes_length s in let rec replace start = try let index = bytes_index_from s start ' ' \\ in if index < s_end - 1 then if ( bytes_get s ( index + 1 ) ) = ' \ n ' then begin bytes_set s index ' ' ; bytes_set s ( index + 1 ) ' ' ; replace ( index + 2 ) end else r...
let runCCdep srcDir files : ( filename * filepath list ) list = let args = [ Prog . getCC ( ) ; " - MM " ] @ List . map ( fun fn -> fp_to_string ( srcDir </> fn ) ) files in match Process . run args with | Process . Failure err -> raise ( BuildCDepAnalyzeFailed err ) | Process . Success ( out , _ , _ ) -> parse_output_...
module Google = struct module Protobuf = struct module rec FileDescriptorSet : sig val name ' : unit -> string type t = FileDescriptorProto . t list val make : ? file : FileDescriptorProto . t list -> unit -> t val to_proto : t -> Runtime ' . Writer . t val from_proto : Runtime ' . Reader . t -> ( t , [ > Runtime ' . R...
type ' a sentinal = unit -> ' a Result . t
type ' a decoder = Field . t -> ' a Result . t
type ( _ , _ ) sentinal_list = | SNil : ( ' a , ' a ) sentinal_list | SCons : ( ' a sentinal ) * ( ' b , ' c ) sentinal_list -> ( ' a -> ' b , ' c ) sentinal_list
let error_wrong_field str field : _ Result . t = ` Wrong_field_type ( str , field ) |> Result . fail
let error_illegal_value str field : _ Result . t = ` Illegal_value ( str , field ) |> Result . fail
let error_required_field_missing : _ Result . t = ` Required_field_missing |> Result . fail
let read_varint ~ signed ~ type_name = let open ! Infix . Int64 in function | Field . Varint v -> begin let v = match signed with | true when v land 0x01L = 0L -> v / 2L | true -> ( v / 2L * - 1L ) - 1L | false -> v in return v end | field -> error_wrong_field type_name field
let read_varint32 ~ signed ~ type_name field = read_varint ~ signed ~ type_name field >>| Int64 . to_int32
let rec type_of_spec : type a . a spec -> ' b * a decoder = let int_of_int32 spec = let ( tpe , f ) = type_of_spec spec in let f field = f field >>| Int32 . to_int in ( tpe , f ) in let int_of_uint32 spec = let ( tpe , f ) = type_of_spec spec in let f field = f field >>| ( fun v -> match Sys . word_size with | 32 -> In...
let default_of_field_type = function | ` Fixed_32_bit -> Field . fixed_32_bit Int32 . zero | ` Fixed_64_bit -> Field . fixed_64_bit Int64 . zero | ` Length_delimited -> Field . length_delimited " " | ` Varint -> Field . varint 0L
let sentinal : type a . a compound -> ( int * unit decoder ) list * a sentinal = function | Basic ( index , ( Message deser ) , _ ) -> let v = ref None in let get ( ) = match ! v with | None -> error_required_field_missing | Some v -> return v in let read = function | Field . Length_delimited { offset ; length ; data }...
module Map = struct include Map . Make ( struct type t = int let compare = compare end ) let of_alist_exn l = List . fold_left ~ init : empty ~ f ( : fun acc ( k , v ) -> if mem k acc then invalid_arg " Duplicate keys in list " else add k v acc ) l end
let in_extension_ranges extension_ranges index = List . exists ~ f ( : fun ( start , end ' ) -> index >= start && index <= end ' ) extension_ranges
let read_fields_map extension_ranges reader_list = let extensions = ref [ ] in let map = Map . of_alist_exn reader_list in let rec read reader = match Reader . has_more reader with | false -> return ( List . rev ! extensions ) | true -> begin match Reader . read_field reader with | Ok ( index , field ) -> begin match M...
let read_fields_array extension_ranges max_index reader_list = let extensions = ref [ ] in let default index field = match in_extension_ranges extension_ranges index with | true -> extensions := ( index , field ) :: ! extensions ; return ( ) | false -> return ( ) in let readers = Array . init ( max_index + 1 ) ~ f ( : ...
let deserialize : type constr t . ( int * int ) list -> ( constr , t ) compound_list -> ( ( int * Field . t ) list -> constr ) -> Reader . t -> t Result . t = fun extension_ranges spec constr -> let max_index = let rec inner : type a b . int -> ( a , b ) compound_list -> int = fun acc -> function | Cons ( Oneof oneofs ...
let verify_clock_pins ~ expected_clock_pins ( t : Circuit . t ) = let rec transitively_resolve ( signal : Signal . t ) = match signal with | Empty -> assert false | Wire { signal_id ; driver } -> ( match ! driver with | Empty -> signal_id | otherwise -> transitively_resolve otherwise ) | Op2 _ | Not _ | Cat _ | Mux _ |...
let devices = Spoc . Devices . init ( ) in ( Printf . printf " DeviceQuery \ nThis application prints information about every \ ndevice compatible with Spoc found on your computer . \ n " ; Printf . printf " Found % d devices : \ n " ( Spoc . Devices . gpgpu_devices ( ) ) ; Printf . printf " ** % d Cuda devices \ n " (...
type dim3 = { x : int ; y : int ; z : int }
type specificLibrary = | Cuda | OpenCL | Both
type generalInfo = { name : string ; totalGlobalMem : int ; localMemSize : int ; clockRate : int ; totalConstMem : int ; multiProcessorCount : int ; eccEnabled : bool ; id : int ; ctx : context ; }
type cudaInfo = { major : int ; minor : int ; regsPerBlock : int ; warpSize : int ; memPitch : int ; maxThreadsPerBlock : int ; maxThreadsDim : dim3 ; maxGridSize : dim3 ; textureAlignment : int ; deviceOverlap : bool ; kernelExecTimeoutEnabled : bool ; integrated : bool ; canMapHostMemory : bool ; computeMode : int ; ...
type platformInfo = { platform_profile : string ; platform_version : string ; platform_name : string ; platform_vendor : string ; platform_extensions : string ; num_devices : int ; }
type deviceType = CL_DEVICE_TYPE_CPU | CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_ACCELERATOR | CL_DEVICE_TYPE_DEFAULT
type clDeviceFPConfig = | CL_FP_DENORM | CL_FP_INF_NAN | CL_FP_ROUND_TO_NEAREST | CL_FP_ROUND_TO_ZERO | CL_FP_ROUND_TO_INF | CL_FP_FMA | CL_FP_NONE
type clDeviceQueueProperties = | CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_PROFILING_ENABLE
type clDeviceGlobalMemCacheType = | CL_READ_WRITE_CACHE | CL_READ_ONLY_CACHE | CL_NONE
type clDeviceLocalMemType = | CL_LOCAL | CL_GLOBAL
type clDeviceExecutionCapabilities = | CL_EXEC_KERNEL | CL_EXEC_NATIVE_KERNEL
type openCLInfo = { platform_info : platformInfo ; device_type : deviceType ; profile : string ; version : string ; vendor : string ; extensions : string ; vendor_id : int ; max_work_item_dimensions : int ; address_bits : int ; max_mem_alloc_size : int ; image_support : bool ; max_read_image_args : int ; max_write_imag...
type specificInfo = CudaInfo of cudaInfo | OpenCLInfo of openCLInfo
type device = { general_info : generalInfo ; specific_info : specificInfo ; gc_info : gcInfo ; events : events ; }
let cuda_compatible_devices = ref 0
let opencl_compatible_devices = ref 0
let total_num_devices = ref 0
let openOutput ( ) = ( )
let beginEvent _s = 0
let endEvent _s _i = ( )
let emitDeviceList _ = ( )
let emitDevice dev printComma = let devType = begin match dev . specific_info with | CudaInfo inf -> " Cuda " | OpenCLInfo inf -> " OpenCL " end in let genInf = dev . general_info in printInfo genInf . name genInf . totalGlobalMem genInf . localMemSize genInf . clockRate genInf . totalConstMem genInf . multiProcessorCo...
let emitDeviceList devList = let nb = List . length devList in prePrint nb ; List . iteri ( fun i dev -> emitDevice dev ( i != nb - 1 ) ) devList ; # endif
let init ? only : ( s = Both ) ( ) = openOutput ( ) ; let idEvent = beginEvent " initialisation des devices " in begin match s with | Both -> ( cuda_init ( ) ; cuda_compatible_devices := get_cuda_compatible_devices ( ) ; cl_init ( ) ; opencl_compatible_devices := get_opencl_compatible_devices ( ) ; ) | Cuda -> ( cuda_i...
let flush dev ? queue_id ( ) = match dev . specific_info , queue_id with | CudaInfo _ , None -> cuda_flush_all dev . general_info dev | CudaInfo _ , Some q -> cuda_flush dev . general_info dev q | OpenCLInfo _ , None -> opencl_flush dev . general_info 0 | OpenCLInfo _ , Some q -> opencl_flush dev . general_info q
let hasCLExtension dev ext = match dev . specific_info with | OpenCLInfo cli -> begin try ignore ( Str . search_forward ( Str . regexp ext ) cli . extensions 0 ) ; true with | _ -> false end | _ -> false
let allowDouble dev = match dev . specific_info with | OpenCLInfo _cli -> hasCLExtension dev " cl_khr_fp64 " || hasCLExtension dev " cl_amd_fp64 " | CudaInfo ci -> ci . major > 1 || ci . minor >= 3
let sum ( a , b , f ) = ( f a ) + ( f b )
let test ( x , y ) = ( sum ( x , y , fun z -> z * y ) ) * ( sum ( x , y , fun w -> ( w * x ) + y ) )
type funs = FUN1 of int | FUN2 of int * int
let apply_funs = function | ( FUN1 y , z ) -> z * y | ( FUN2 ( x , y ) , w ) -> ( w * x ) + y
let sum_dfc ( a , b , f ) = apply_funs ( f , a ) + apply_funs ( f , b )
let test_dfc ( x , y ) = ( sum_dfc ( x , y , FUN1 y ) ) * ( sum_dfc ( x , y , FUN2 ( x , y ) ) )
type state = | Selecting of Dhcp_wire . pkt | Requesting of ( Dhcp_wire . pkt * Dhcp_wire . pkt ) | Bound of Dhcp_wire . pkt | Renewing of ( Dhcp_wire . pkt * Dhcp_wire . pkt )
type t = { srcmac : Macaddr . t ; request_options : Dhcp_wire . option_code list ; state : state ; }
module Constants = struct open Dhcp_wire let htype = Ethernet_10mb let hlen = 6 let hops = 0 let sname = " " let file = " " end
let default_requests = Dhcp_wire . ( [ SUBNET_MASK ; ROUTERS ; DNS_SERVERS ; DOMAIN_NAME ; PERFORM_ROUTER_DISC ; STATIC_ROUTES ; VENDOR_SPECIFIC ; NETBIOS_NAME_SERVERS ; NETBIOS_NODE ; NETBIOS_SCOPE ; CLASSLESS_STATIC_ROUTE ; PRIVATE_CLASSLESS_STATIC_ROUTE ; WEB_PROXY_AUTO_DISC ; ] )
let pp fmt p = let pr = Dhcp_wire . pkt_to_string in let pp_state fmt = function | Selecting pkt -> Format . fprintf fmt " SELECTING . Generated % s " @@ pr pkt | Requesting ( received , sent ) -> Format . fprintf fmt " REQUESTING . Received % s , and generated response % s " ( pr received ) ( pr sent ) | Bound pkt -> ...
let lease { state ; _ } = match state with | Bound dhcpack | Renewing ( dhcpack , _ ) -> Some dhcpack | Requesting _ | Selecting _ -> None
let xid { state ; _ } = let open Dhcp_wire in match state with | Selecting p -> p . xid | Requesting ( _i , o ) -> o . xid | Bound a -> a . xid | Renewing ( _i , o ) -> o . xid
let make_request ( ? ciaddr = Ipaddr . V4 . any ) ~ xid ~ chaddr ~ srcmac ~ siaddr ~ options ( ) = let open Dhcp_wire in Constants . ( { htype ; hlen ; hops ; sname ; file ; xid ; chaddr ; srcport = Dhcp_wire . client_port ; dstport = Dhcp_wire . server_port ; srcmac ; srcip = Ipaddr . V4 . any ; dstmac = Macaddr . bro...
let offer t ~ xid ~ chaddr ~ server_ip ~ request_ip ~ offer_options : _ = let open Dhcp_wire in let options = [ Message_type DHCPREQUEST ; Request_ip request_ip ; Server_identifier server_ip ; ] in let options = match t . request_options with | [ ] -> options | _ :: _ -> ( Parameter_requests t . request_options ) :: op...
let create ? requests xid srcmac = let open Constants in let open Dhcp_wire in let requests = match requests with | None | Some [ ] -> default_requests | Some requests -> requests in let pkt = { htype ; hlen ; hops ; sname ; file ; srcmac ; dstmac = Macaddr . broadcast ; srcip = Ipaddr . V4 . any ; dstip = Ipaddr . V4 ...
let input t buf = let open Dhcp_wire in match pkt_of_buf buf ( Cstruct . length buf ) with | Error _ -> ` Noop | Ok incoming -> if compare incoming . xid ( xid t ) = 0 then begin match find_message_type incoming . options , t . state with | None , _ -> ` Noop | Some DHCPOFFER , Selecting dhcpdiscover -> let dhcprequest...
let renew t = match t . state with | Selecting _ | Requesting _ -> ` Noop | Renewing ( _lease , request ) -> ` Response ( t , request ) | Bound lease -> let open Dhcp_wire in let request = offer t ~ xid : lease . xid ~ chaddr : lease . chaddr ~ server_ip : lease . siaddr ~ request_ip : lease . yiaddr ~ offer_options : ...
let src = Logs . Src . create " dhcp_client_lwt "
module Log = ( val Logs . src_log src : Logs . LOG )