text
stringlengths
12
786k
let create_with_interface ( type i o ) ( module I : Interface . S_Of_signal with type Of_signal . t = i ) ( module O : Interface . S_Of_signal with type Of_signal . t = o ) = let module I = With_interface ( I ) ( O ) in I . create ; ;
type compilation_env = Debug_event . compilation_env = { ce_stack : int Ident . tbl ; ce_heap : int Ident . tbl ; ce_rec : int Ident . tbl }
type debug_event = Debug_event . debug_event = { mutable ev_pos : int ; ev_module : string ; ev_loc : Location . t ; ev_kind : debug_event_kind ; ev_defname : string ; ev_info : debug_event_info ; ev_typenv : Env . summary ; ev_typsubst : Subst . t ; ev_compenv : compilation_env ; ...
type instruction = Klabel of label | Kacc of int | Kenvacc of int | Kpush | Kpop of int | Kassign of int | Kpush_retaddr of label | Kapply of int | Kappterm of int * int | Kreturn of int | Krestart | Kgrab of int | Kclosure of label * int | Kclosurerec of label list * int | Koffsetclosure of int | Kg...
let abs x = if x >= 0 then x else - x
let max_int = ( - 1 ) lsr 1
let min_int = max_int + 1
let lognot x = logxor x ( - 1 )
let equal : int -> int -> bool = ( = )
let compare : int -> int -> int = Stdlib . compare
let to_string x = format_int " % d " x
[ @@@ ocaml . flambda_o3 ] = " caml_int32_of_float " " caml_int32_of_float_unboxed " [ @@ unboxed ] [ @@ noalloc ] = " caml_int32_to_float " " caml_int32_to_float_unboxed " [ @@ unboxed ] [ @@ noalloc ] = " caml_int32_bits_of_float " " caml_int32_bits_of_float_unboxed...
let succ n = add n 1l
let pred n = sub n 1l
let abs n = if n >= 0l then n else neg n
let lognot n = logxor n ( - 1l )
let unsigned_to_int = match Sys . word_size with | 32 -> let max_int = of_int Stdlib . max_int in fun n -> if compare zero n <= 0 && compare n max_int <= 0 then Some ( to_int n ) else None | 64 -> let move = int_of_string " 0x1_0000_0000 " in fun n -> let i = to_int n in Some ( if i < 0...
let to_string n = format " % d " n
let of_string_opt s = try Some ( of_string s ) with Failure _ -> None
let compare ( x : t ) ( y : t ) = Stdlib . compare x y
let equal ( x : t ) ( y : t ) = compare x y = 0
let unsigned_compare n m = compare ( sub n min_int ) ( sub m min_int )
let unsigned_div n d = if d < zero then if unsigned_compare n d < 0 then zero else one else let q = shift_left ( div ( shift_right_logical n 1 ) d ) 1 in let r = sub n ( mul q d ) in if unsigned_compare r d >= 0 then succ q else q
let unsigned_rem n d = sub n ( mul ( unsigned_div n d ) d )
[ @@@ ocaml . flambda_o3 ] = " caml_int64_of_float " " caml_int64_of_float_unboxed " [ @@ unboxed ] [ @@ noalloc ] = " caml_int64_to_float " " caml_int64_to_float_unboxed " [ @@ unboxed ] [ @@ noalloc ]
let succ n = add n 1L
let pred n = sub n 1L
let abs n = if n >= 0L then n else neg n
let lognot n = logxor n ( - 1L )
let unsigned_to_int = let max_int = of_int Stdlib . max_int in fun n -> if compare zero n <= 0 && compare n max_int <= 0 then Some ( to_int n ) else None
let to_string n = format " % d " n
let of_string_opt s = try Some ( of_string s ) with Failure _ -> None = " caml_int64_bits_of_float " " caml_int64_bits_of_float_unboxed " [ @@ unboxed ] [ @@ noalloc ] = " caml_int64_float_of_bits " " caml_int64_float_of_bits_unboxed " [ @@ unboxed ] [ @@ noalloc ]
let compare ( x : t ) ( y : t ) = Stdlib . compare x y
let equal ( x : t ) ( y : t ) = compare x y = 0
let unsigned_compare n m = compare ( sub n min_int ) ( sub m min_int )
let unsigned_div n d = if d < zero then if unsigned_compare n d < 0 then zero else one else let q = shift_left ( div ( shift_right_logical n 1 ) d ) 1 in let r = sub n ( mul q d ) in if unsigned_compare r d >= 0 then succ q else q
let unsigned_rem n d = sub n ( mul ( unsigned_div n d ) d )
module Gates = struct type t = int list [ @@ deriving compare ] let equal = [ % compare . equal : t ] let empty = [ ] let is_empty = List . is_empty let width x = List . length x let of_constant = Constant . to_bit_list let to_constant = Constant . of_bit_list let concat_msb l = List ....
module Primitives = struct include Comb . Make_primitives ( Gates ) let mux sel vals = let len = List . length vals in let idx = to_constant sel |> Constant . to_int64 |> Int64 . to_int_trunc in List . nth_exn vals ( if idx >= len then len - 1 else idx ) ; ; end
let produce brokers topic_name keyed_messages = let producer = Kafka_lwt . new_producer [ " metadata . broker . list " , brokers ] in let topic = Kafka . new_topic producer topic_name [ ] in let send ( key , msg ) = Kafka_lwt . produce topic ~ key msg in let loop ( ) = Lwt_list ....
let cache c ( k , v ) = Cache . add k v c
let consume brokers topic_name messages = let expected_messages = messages |> List . fold_left cache Cache . empty |> ref in let remove_received = function | Kafka . Message ( _ , _ , _ , _ , Some ( key ) ) when Cache . mem key ! expected_messages -> expected_messages := Cache . r...
let timeout s err = Lwt_unix . sleep s >>= fun ( ) -> Lwt_io . printf " % s \ n " %! err >>= fun ( ) -> Lwt . fail ( Failure " timeout " )
let expect_error expected_err action = Lwt . catch action ( function | Kafka . Error ( err , _ ) when err = expected_err -> return ( ) | exn -> Lwt . fail exn )
let _ = Random . self_init ( )
let random_str prefix = prefix ^ ( string_of_int ( Random . int 1000000 ) )
let random_msg ( ) = ( random_str " k_ " , random_str " msg_ " )
let test_produce_consume ( ) = let messages = [ random_msg ( ) ; random_msg ( ) ; random_msg ( ) ; random_msg ( ) ; random_msg ( ) ] in Lwt . join [ produce brokers topic_name messages ; Lwt . pick [ consume brokers topic_name messages ; timeout 2 . 0 " Fail to co...
let test_consume_error ( ) = Lwt . pick [ expect_error Kafka . TIMED_OUT ( fun ( ) -> consume brokers topic_name [ random_msg ( ) ] ) ; timeout 2 . 0 " Fail to detect the error . " ]
let ( ) = Lwt_main . run ( List . fold_left Lwt . bind ( return ( ) ) [ ( fun ( ) -> Lwt_io . printf " % s \ n " %! " Start LWT tests " ) ; test_produce_consume ; test_consume_error ; ( fun ( ) -> Lwt_io . printf " % s \ n " %! " Done LWT tests " ) ...
module IntPairSet = Set . Make ( struct type t = int * int let compare ( ( a1 , b1 ) : t ) ( a2 , b2 ) = match compare a1 a2 with | 0 -> compare b1 b2 | c -> c end )
let build_graph fundecl = let mat = ref IntPairSet . empty in let add_interf ri rj = if Proc . register_class ri = Proc . register_class rj then begin let i = ri . stamp and j = rj . stamp in if i <> j then begin let p = if i < j then ( i , j ) else ( j , i ) in if not ( IntPairSet . ...
open Interface_intf module type Pre_partial = Pre_partial module type Pre = Pre module type S = S module type S_Of_signal = S_Of_signal module type Ast = Ast module type Empty = Empty module type Comb = Comb end
module Create_fn ( I : S ) ( O : S ) = struct type ' a t = ' a I . t -> ' a O . t let sexp_of_t _ _ = [ % message " " ~ inputs ( : I . t : ( string * int ) I . t ) ~ outputs ( : O . t : ( string * int ) O . t ) ] ; ; end
module Ast = struct module rec Ast : sig type t = Field . t list [ @@ deriving sexp_of ] end = struct type t = Field . t list [ @@ deriving sexp_of ] end and Field : sig type t = { name : string ; type_ : Type . t ; sequence : Sequence . t option ; doc : string option } [ @@ de...
module type S_enum = Interface_intf . S_enum with module Ast := Ast
module type S_enums = Interface_intf . S_enums with module Ast := Ast
type ' a with_valid = ' a Comb_intf . with_valid
type ( ' a , ' b ) with_valid2 = ( ' a , ' b ) Comb_intf . with_valid2
module Make ( X : Pre ) : S with type ' a t := ' a X . t = struct include X let port_names = map t ~ f : fst let port_widths = map t ~ f : snd let to_list_rev x = to_list x |> List . rev let to_alist x = to_list ( map2 port_names x ~ f ( : fun name x -> name , x ) ) let of_alist x ...
module Make_enums ( Enum : Interface_intf . Enum ) = struct module Enum = struct include Enum include Comparable . Make ( Enum ) end let to_rank = let mapping = List . mapi Enum . all ~ f ( : fun i x -> x , i ) |> Map . of_alist_exn ( module Enum ) in fun x -> Map . find_exn mapp...
module Update ( Pre : Interface_intf . Pre ) ( M : sig val t : ( string * int ) Pre . t end ) = struct module T = struct include Pre let t = M . t end include ( T : Interface_intf . Pre with type ' a t = ' a T . t ) include Make ( T ) end
module Empty = struct type ' a t = None [ @@ deriving sexp_of ] include Make ( struct type nonrec ' a t = ' a t [ @@ deriving sexp_of ] let t = None let iter _ ~ f : _ = ( ) let iter2 _ _ ~ f : _ = ( ) let map _ ~ f : _ = None let map2 _ _ ~ f : _ = None let to_list _...
module Make_interface_with_conversion ( Repr : S ) ( M : sig type ' a t [ @@ deriving sexp_of ] val t_of_repr : ' a Repr . t -> ' a t val repr_of_t : ' a t -> ' a Repr . t end ) = struct type ' a t = ' a M . t [ @@ deriving sexp_of ] include Make ( struct type nonrec ' ...
module Value ( S : sig val port_name : string val port_width : int end ) = struct module T = struct type ' a t = ' a let sexp_of_t sexp_of_a a = [ % sexp_of : string * a ] ( S . port_name , a ) let t = S . port_name , S . port_width let map t ~ f = f t let iter t ~ f = f t let m...
module type S_with_ast = sig include S val ast : Ast . t end
module type Pre_partial = sig type ' a t [ @@ deriving sexp_of ] val iter : ' a t -> f ( ' : a -> unit ) -> unit val iter2 : ' a t -> ' b t -> f ( ' : a -> ' b -> unit ) -> unit val map : ' a t -> f ( ' : a -> ' b ) -> ' b t val map2 : ' a t -> ' b t -> f ...
module type Pre = sig include Pre_partial val t : ( string * int ) t end
module type Ast = sig module rec Ast : sig type t = Field . t list [ @@ deriving sexp_of ] end and Field : sig type t = { name : string ; type_ : Type . t ; sequence : Sequence . t option ; doc : string option } [ @@ deriving sexp_of ] end and Type : sig type t = | Signal of { bi...
module type Comb_monomorphic = sig type comb type t [ @@ deriving sexp_of ] val assert_widths : t -> unit val of_int : int -> t val const : int -> t [ @@ deprecated " [ since 2019 - 11 ] interface const " ] val pack : ? rev : bool -> t -> comb val unpack : ? rev : bool -> comb -> t...
module type Comb = sig type ' a interface type comb type t = comb interface [ @@ deriving sexp_of ] include Comb_monomorphic with type t := comb interface and type comb := comb val widths : t -> int interface val of_ints : int interface -> t val consts : int interface -> t [ @@ deprecated " [ si...
module type Names_and_widths = sig val t : ( string * int ) list val port_names : string list val port_widths : int list end
module type Of_signal_functions = sig type t val wires : ? named : bool -> ? from : t -> unit -> t val reg : ? enable : Signal . t -> Reg_spec . t -> t -> t val pipeline : ? attributes : Rtl_attribute . t list -> ? enable : Signal . t -> n : int -> Reg_spec . t -> t -> t val assign ...
module type S = sig include Pre include Equal . S1 with type ' a t := ' a t val port_names : string t val port_widths : int t val to_alist : ' a t -> ( string * ' a ) list val of_alist : ( string * ' a ) list -> ' a t val zip : ' a t -> ' b t -> ( ' a * ' b ) t val zip3 ...
module type S_monomorphic = sig type a type t val iter : t -> f ( : a -> unit ) -> unit val iter2 : t -> t -> f ( : a -> a -> unit ) -> unit val map : t -> f ( : a -> a ) -> t val map2 : t -> t -> f ( : a -> a -> a ) -> t val to_list : t -> a list val to_alist : t -> ( str...
module type S_Of_signal = sig module Of_signal : sig include Comb_monomorphic with type comb := Signal . t include Of_signal_functions with type t := t end include S_monomorphic with type t := Of_signal . t and type a := Signal . t end
module type Empty = sig type ' a t = None include S with type ' a t := ' a t end
module type Enum = sig type t [ @@ deriving compare , enumerate , sexp_of ] end
module type S_enum = sig module Ast : Ast module Enum : Enum include S val ast : Ast . t val of_enum : ( module Comb . S with type t = ' a ) -> Enum . t -> ' a t val to_enum : Bits . t t -> Enum . t Or_error . t val to_enum_exn : Bits . t t -> Enum . t val ( ==: ) : ( module ...
module type S_enums = sig module Ast : Ast module Enum : Enum module Binary : S_enum with module Enum := Enum and module Ast := Ast module One_hot : S_enum with module Enum := Enum and module Ast := Ast end
module type Interface = sig module type Pre_partial = Pre_partial module type Pre = Pre module type S = S module type S_Of_signal = S_Of_signal module type Ast = Ast module type Empty = Empty module Ast : Ast module Empty : Empty module type S_with_ast = sig include S val ast : Ast . t end module Create_fn...
let anon_fn_with_loc ( sloc : Lambda . scoped_location ) = let loc = Debuginfo . Scoped_location . to_location sloc in let ( file , line , startchar ) = Location . get_pos_info loc . loc_start in let endchar = loc . loc_end . pos_cnum - loc . loc_start . pos_bol in let pp_chars ppf ...
let of_primitive : Lambda . primitive -> string = function | Pidentity -> pidentity | Pbytes_of_string -> pbytes_of_string | Pbytes_to_string -> pbytes_to_string | Pignore -> pignore | Prevapply _ -> prevapply | Pdirapply _ -> pdirapply | Pgetglobal _ -> pgetglobal | Psetglobal _ -> psetglobal ...
let of_primitive_arg : Lambda . primitive -> string = function | Pidentity -> pidentity_arg | Pbytes_of_string -> pbytes_of_string_arg | Pbytes_to_string -> pbytes_to_string_arg | Pignore -> pignore_arg | Prevapply _ -> prevapply_arg | Pdirapply _ -> pdirapply_arg | Pgetglobal _ -> pgetglobal_arg ...
let verbose = ref false
type store = address -> value | REF of address | INT of int | BOOL of bool | UNIT | PAIR of value * value | INL of value | INR of value | FUN of ( ( value * store ) -> ( value * store ) )
type env = var -> value
type binding = var * value
type bindings = binding list
let rec string_of_value = function | REF a -> " address ( " ^ ( string_of_int a ) ^ " ) " | BOOL b -> string_of_bool b | INT n -> string_of_int n | UNIT -> " ( ) " | PAIR ( v1 , v2 ) -> " ( " ^ ( string_of_value v1 ) ^ " , " ^ ( string_of_value v2 ) ^ "...
let update ( env , ( x , v ) ) = fun y -> if x = y then v else env y
let readint ( ) = let _ = print_string " input > " in read_int ( )
let do_unary = function | ( NOT , BOOL m ) -> BOOL ( not m ) | ( NEG , INT m ) -> INT ( - m ) | ( READ , UNIT ) -> INT ( readint ( ) ) | ( op , _ ) -> complain ( " malformed unary operator : " ^ ( string_of_unary_oper op ) )
let do_oper = function | ( AND , BOOL m , BOOL n ) -> BOOL ( m && n ) | ( OR , BOOL m , BOOL n ) -> BOOL ( m || n ) | ( EQB , BOOL m , BOOL n ) -> BOOL ( m = n ) | ( LT , INT m , INT n ) -> BOOL ( m < n ) | ( EQI , INT m , INT n ) -> BOOL ( m = n...
let do_deref = function | ( REF a , store ) -> ( store a , store ) | ( _ , _ ) -> complain " deref expecting address "
let next_address = ref 0
let new_address ( ) = let a = ! next_address in ( next_address := a + 1 ; a )
let do_ref = function | ( v , store ) -> let a = new_address ( ) in ( REF a , update ( store , ( a , v ) ) )
let do_assign a = function | ( v , store ) -> ( UNIT , update ( store , ( a , v ) ) )
let rec interpret ( e , env , store ) = match e with | Unit -> ( UNIT , store ) | Var x -> ( env x , store ) | Integer n -> ( INT n , store ) | Boolean b -> ( BOOL b , store ) | Seq [ ] -> ( UNIT , store ) | Seq [ e ] -> interpret ( e , env , store ) |...