text
stringlengths
0
601k
module type LatticeWithIsTopBotValue = sig include Lattice . S val is_bot_value : t -> bool val is_top_value : t -> typ -> bool end
module Simple ( Val : Lattice . S ) = struct include Printable . Std module M = MapDomain . MapTop_LiftBot ( Basetype . CilField ) ( Val ) let name ( ) = " simple structs " type t = M . t [ @@ deriving to_yojson ] type field = fieldinfo type value = M . value let show mapping = let assoclist = M . fold ( fun x y rest -...
module SetsCommon ( Val : LatticeWithIsTopBotValue ) = struct include Printable . Std module SS = Simple ( Val ) module HS = HoareDomain . Set ( SS ) type field = fieldinfo type value = SS . value type variant = SS . t type set = HS . t let join_ss s = match HS . elements s with | [ ] -> raise ( Unsupported " join_ss o...
module Sets ( Val : LatticeWithIsTopBotValue ) = struct include SetsCommon ( Val ) let name ( ) = " set structs " type t = HS . t [ @@ deriving to_yojson ] let show mapping = HS . show mapping let pretty = HS . pretty let top = hs_top let is_top = hs_is_top let bot = hs_bot let is_bot = hs_is_bot let create = hs_create...
module KeyedSets ( Val : LatticeWithIsTopBotValue ) = struct include SetsCommon ( Val ) module F = Basetype . CilField let name ( ) = " keyed set structs " type t = HS . t * Basetype . CilField . t option [ @@ deriving to_yojson ] let show ( s , k ) = match k with | Some k -> HS . show s ^ " with key " ^ F . show k | N...
module FlagConfiguredStructDomain ( Val : LatticeWithIsTopBotValue ) = struct include Printable . Std module S = Simple ( Val ) module HS = Sets ( Val ) module KS = KeyedSets ( Val ) type field = fieldinfo type value = S . value module P = struct let msg = " FlagConfiguredStructDomain received a value where not exactly...
type t = { offset : int ; data_words : int ; pointer_words : int ; }
let offset_mask = Int64 . shift_left 0x3fffffffL offset_shift
let offset_mask_int = 0x3fffffff lsl offset_shift
let data_size_mask = Int64 . shift_left 0xffffL data_size_shift
let data_size_mask_int = 0xffff lsl data_size_shift
let decode ( pointer64 : Int64 . t ) t : t = let pointers_size = let shifted64 = Int64 . shift_right_logical pointer64 pointers_size_shift in Int64 . to_int shifted64 in if Sys . word_size = 64 then let pointer = Int64 . to_int pointer64 in let offset = let v = ( pointer land offset_mask_int ) offset_mask_int lsr offse...
let encode ( storage_descr : t ) t : Int64 . t = if Sys . word_size = 64 && storage_descr . pointer_words <= 0x7fff then let offset = Util . encode_signed 30 storage_descr . offset in let data_size = storage_descr . data_words in let ptr_size = storage_descr . pointer_words in let tag_val_struct_int = 0 in Int64 . of_i...
type signal = | Empty | Module_input of id * name * width | Module_output of id * name * width * signal ref | Module_tristate of id * name * width * signal list ref | Internal_wire of id * width * signal ref | Internal_triwire of id * width * signal list ref | Instantiation_output of id * name | Instantiation_tristate ...
type circuit = { name : string ; id : id ; mutable signals : signal list ; }
let id ' = ref 0
let const_map = ref StringMap . empty
let circuit ' = ref None
let circuits ' = ref [ ]
let id ( ) = let id = ! id ' in incr id ' ; id
let name t = match t with | Module_input ( _ , name , _ ) | Module_output ( _ , name , _ , _ ) | Module_tristate ( _ , name , _ , _ ) | Instantiation ( _ , name , _ , _ , _ , _ ) -> name | Internal_triwire ( id , _ , _ ) | Internal_wire ( id , _ , _ ) | Rtl_op ( id , _ , _ ) -> " _ " ^ string_of_int id | Empty | Instan...
let width t = match t with | Module_input ( _ , _ , width ) | Module_output ( _ , _ , width , _ ) | Module_tristate ( _ , _ , width , _ ) | Internal_triwire ( _ , width , _ ) | Internal_wire ( _ , width , _ ) | Rtl_op ( _ , width , _ ) -> width | Empty | Instantiation _ | Instantiation_output _ | Instantiation_tristate...
let get_id t = match t with | Empty | Instantiation_output _ | Instantiation_tristate _ -> raise ( Invalid_id t ) | Module_input ( i , _ , _ ) | Module_output ( i , _ , _ , _ ) | Module_tristate ( i , _ , _ , _ ) | Internal_triwire ( i , _ , _ ) | Internal_wire ( i , _ , _ ) | Rtl_op ( i , _ , _ ) | Instantiation ( i ,...
let empty name = { name = name ; id = id ( ) ; signals = [ ] ; }
let circuit_exists name = try ignore ( List . assoc name ! circuits ' ) ; true with _ -> false
let circuit name = match ! circuit ' with | Some ( x ) -> raise Circuit_already_started | None -> if circuit_exists name then raise ( Circuit_already_exists name ) else begin id ' := 0 ; const_map := StringMap . empty ; circuit ' := Some ( empty name ) end
let check_unique_io_names c = let ios , _ = List . partition ( function Module_input _ | Module_output _ | Module_tristate _ -> true | _ -> false ) c . signals in let _ = List . fold_left ( fun set io -> let name = name io in if StringSet . mem name set then raise ( IO_name_already_exists name ) else StringSet . add na...
let end_circuit ( ) = match ! circuit ' with | None -> raise No_circuit | Some ( x ) -> begin check_unique_io_names x ; circuits ' := ( x . name , x ) :: ! circuits ' ; circuit ' := None end
let get_circuit ( ) = match ! circuit ' with | None -> raise No_circuit | Some ( x ) -> x
let find_circuit name = List . assoc name ! circuits '
let add_sig s = let c = get_circuit ( ) in c . signals <- s :: c . signals ; s
let ( ) >> a b = b a
let mk_input name width = Module_input ( id ( ) , name , width ) >> add_sig
let mk_output name width = Module_output ( id ( ) , name , width , ref Empty ) >> add_sig
let mk_tristate name width = Module_tristate ( id ( ) , name , width , ref [ ] ) >> add_sig
let mk_wire width = Internal_wire ( id ( ) , width , ref Empty ) >> add_sig
let mk_triwire width = Internal_triwire ( id ( ) , width , ref [ ] ) >> add_sig
let is_z s = try let is_z = function ' z ' -> ( ) | _ -> raise Not_found in let ( ) = String . iter is_z s in true with Not_found -> false
let ( ) <== a b = match a with | Module_output ( _ , _ , _ , con ) | Internal_wire ( _ , _ , con ) -> ( match ! con with | Empty -> ( match b with | Internal_wire _ | Module_input _ | Instantiation_output _ | Rtl_op _ -> con := b | _ -> raise ( Cant_assign_wire_with ( b ) ) ) | _ -> raise ( Wire_already_assigned ( a ) ...
let is_readable = function Module_input _ | Internal_wire _ | Rtl_op _ -> true | _ -> false
let is_writeable = function Module_output _ | Internal_wire _ -> true | _ -> false
let is_readwrite = function Module_tristate _ | Internal_triwire _ -> true | _ -> false
let is_connected = function Module_output ( _ , _ , _ , con ) | Internal_wire ( _ , _ , con ) -> ! con <> Empty | Module_tristate ( _ , _ , _ , cons ) | Internal_triwire ( _ , _ , cons ) -> ! cons <> [ ] | _ -> true
let inst ( ? g [ ] ) = ( ? i [ ] ) = ( ? o [ ] ) = ( ? t [ ] ) = name = let mod_id = id ( ) in List . iter ( fun ( n , s ) -> if not ( is_readable s ) then raise ( Invalid_submodule_input_connection ( name , n , s ) ) ) i ; List . iter ( fun ( n , s ) -> if not ( is_writeable s ) then raise ( Invalid_submodule_output_c...
let ( ) ==> a b = ( a , b )
let const ' b = let _ = String . iter ( function ' 0 ' | ' 1 ' | ' z ' -> ( ) | _ -> raise ( Invalid_constant b ) ) b in let _ = if b = " " then raise ( Invalid_constant b ) in Rtl_op ( id ( ) , String . length b , Constant b ) >> add_sig
let const b = try StringMap . find b ! const_map with Not_found -> begin let c = const ' b in const_map := StringMap . add b c ! const_map ; c end
let constz w = const ( String . v ~ len : w ( fun _ -> ' z ' ) )
let check_readable l = let ok s = if not ( is_readable s ) then raise ( Rtl_op_arg_not_readable s ) in List . iter ok l
let mux sel d = let _ = check_readable ( sel :: d ) in let len = List . length d in let _ = if len < 1 then raise Too_few_mux_data_elements in let _ = if len > ( 1 lsl ( width sel ) ) then raise ( Too_many_mux_data_elements len ) in let w = width ( List . hd d ) in let _ = if not ( List . fold_left ( fun a s -> a && wi...
let concat d = let _ = check_readable d in let _ = if List . length d = 0 then raise No_elements_to_concat in Rtl_op ( id ( ) , List . fold_left ( fun a s -> a + width s ) 0 d , Concat d ) >> add_sig
let select d hi lo = let _ = check_readable [ d ] in let _ = if hi < lo then raise ( Select_index_error ( hi , lo ) ) in let _ = if lo < 0 then raise ( Select_index_error ( hi , lo ) ) in let _ = if hi >= width d then raise ( Select_index_error ( hi , lo ) ) in Rtl_op ( id ( ) , hi - lo + 1 , Select ( hi , lo , d ) ) >...
module type Config = sig val structural_const : bool val structural_mux : bool val structural_concat : bool val structural_select : bool end
module Base ( C : Config ) = struct open C type t = signal let empty = Empty let width = width let wire = mk_wire let ( ) <== = ( ) <== let ( ) -- a _ = a let lazy_const name = lazy ( let x = wire 1 in let _ = inst ( prefix ^ name ) ~ o [ : " o " ==> x ] in x ) let vdd = lazy_const " vdd " let gnd = lazy_const " gnd " ...
module Base0 = Base ( struct let structural_const = false let structural_mux = false let structural_concat = false let structural_select = false end )
module Base1 = Base ( struct let structural_const = false let structural_mux = true let structural_concat = true let structural_select = true end )
module Base2 = Base ( struct let structural_const = true let structural_mux = true let structural_concat = true let structural_select = true end )
let write_verilog os circuit = let open Printf in let declare typ signal = " " ^ typ ^ " " ^ ( if width signal = 1 then " " else sprintf " [ % i : 0 ] " ( width signal - 1 ) ) ^ ( name signal ) in let seperator sep l = List . fold_left ( fun a s -> if a " " = then s else a ^ sep ^ s ) " " l in let assign s0 s1 = os ( "...
module Lib = struct let reg ~ clock ~ en d = let q = mk_wire ( width d ) in let _ = inst ( prefix " ^ reg " ) ~ g [ : " b " ==> GInt ( width d ) ; ] ~ i [ : " clock " ==> clock ; " enable " ==> en ; " d " ==> d ] ~ o [ : " q " ==> q ] in q let reg_r ~ clock ~ reset ( ? def = 0 ) ~ en d = let q = mk_wire ( width d ) in ...
let rec compare : prim_compare ( ' : prim -> ' prim -> int ) -> ( ' annot , ' prim ) Micheline . node -> ( ' annot , ' prim ) Micheline . node -> int = fun ~ prim_compare node1 node2 -> match ( node1 , node2 ) with | ( Int ( _ , z1 ) , Int ( _ , z2 ) ) -> Z . compare z1 z2 | ( Int _ , _ ) -> - 1 | ( String _ , Int _ ) ...
type t1 = | A | B | C of t1 | D of float
let a = [ A ; B ; C A ; C ( C A ) ; D 1 . 234 ]
let ( ) = match Sys . opaque_identity a with | [ A ; B ; C A ; C ( C A ) ; D 1 . 234 ] -> ( ) | _ -> assert false
let ( ) = match a with | [ A ; B ; C A ; C ( C A ) ; D 1 . 234 ] -> ( ) | _ -> assert false
let b = [ | A ; B ; C A ; C ( C A ) ; D 1 . 234 ] |
let ( ) = match Sys . opaque_identity b with | [ | A ; B ; C A ; C ( C A ) ; D 1 . 234 ] | -> ( ) | _ -> assert false
let ( ) = match b with | [ | A ; B ; C A ; C ( C A ) ; D 1 . 234 ] | -> ( ) | _ -> assert false
let c = [ 1 . ; 2 . ]
let ( ) = match Sys . opaque_identity c with | [ 1 . ; 2 . ] -> ( ) | _ -> assert false
let ( ) = match c with | [ 1 . ; 2 . ] -> ( ) | _ -> assert false
let d = [ | 1 . ; 2 . ] |
let ( ) = match Sys . opaque_identity d with | [ | 1 . ; 2 . ] | -> ( ) | _ -> assert false
let ( ) = match d with | [ | 1 . ; 2 . ] | -> ( ) | _ -> assert false
let long_array = [ | 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ; 10 ; 11 ; 12 ; 13 ; 14 ; 15 ; 16 ; 17 ; 18 ; 19 ; 20 ; 21 ; 22 ; 23 ; 24 ; 25 ; 26 ; 27 ; 28 ; 29 ; 30 ; 31 ; 32 ; 33 ; 34 ; 35 ; 36 ; 37 ; 38 ; 39 ; 40 ; 41 ; 42 ; 43 ; 44 ; 45 ; 46 ; 47 ; 48 ; 49 ; 50 ; 51 ; 52 ; 53 ; 54 ; 55 ; 56 ; 57 ; 58 ; 59 ; 60 ; 61 ;...
let ( ) = let long_array = Sys . opaque_identity long_array in for i = 0 to Array . length long_array - 1 do assert ( long_array . ( i ) = i ) done
module type S = sig module Loc : Sig . Loc ; module Token : Sig . Token with module Loc = Loc ; module Lexer : Sig . Lexer with module Loc = Loc and module Token = Token ; module Context : Context . S with module Token = Token ; module Action : Sig . Grammar . Action ; type gram = { gfilter : Token . Filter . t ; gkeyw...
module Make ( Lexer : Sig . Lexer ) = struct module Loc = Lexer . Loc ; module Token = Lexer . Token ; module Action : Sig . Grammar . Action = struct type t = Obj . t ; value mk = Obj . repr ; value get = Obj . obj ; value getf = Obj . obj ; value getf2 = Obj . obj ; end ; module Lexer = Lexer ; type gram = { gfilter ...
type metadata = { name : string ; number : int ; type ' : string option ; version : int }
type info = | Third_party of { offset : int ; upward : bool ; extension_number : int option } | Core of int
type enum = { extend : string ; name : string ; info : info }
type bit = { extend : string ; name : string ; pos : int }
type ' a data = { metadata : ' a ; types : string list ; commands : string list ; enums : enum list ; bits : bit list ; }
type t = metadata data
type versioned = | Active of t | Promoted_to of string N . t
let only_active exts = C . List . filter_map ( function Active x -> Some x | Promoted_to _ -> None ) exts
type feature_set = string data
let pp_exttype ppf = function | None -> Fmt . pf ppf " support = disabled " | Some x -> Fmt . pf ppf " type " =\% s " " \ x
let pp_metadata ppf ( m : metadata ) = Fmt . pf ppf " [ @< hov { > name =% s ; @ number =% d ; @ % a ; @ version =% d } ] " @ m . name m . number pp_exttype m . type ' m . version
let pp_enum ppf ( e : enum ) = let pp_info ppf = function | Third_party ext -> Fmt . pf ppf " Third_party { offset =% d ; @ upward =% b } " ext . offset ext . upward | Core n -> Fmt . pf ppf " Core % d " n in Fmt . pf ppf " [ @< hov { > name =% s ; @ extend =% s ; @ info =% aa } ] " @ e . name e . extend pp_info e . in...
let pp_bit ppf ( b : bit ) = Fmt . pf ppf " [ @< hov { > name =% s ; @ extend =% s ; @ pos =% d ; } ] " @ b . name b . extend b . pos
let pp_active ppf ( t : t ) = Fmt . pf ppf " [ @< v 2 { > metadata =% a ; ; @ types [ =% a ] ; ; @ commands [ =% a ] ; ; @ enums [ =% a ] ; ; @\ bits [ =% a ] @ } ] " @ pp_metadata t . metadata Fmt . ( list string ) t . types Fmt . ( list string ) t . commands ( Fmt . list pp_enum ) t . enums ( Fmt . list pp_bit ) t . ...
let pp ppf = function | Active t -> pp_active ppf t | Promoted_to aliases -> Fmt . pf ppf " [ @< v > Promoted extension . , @ aliases [ :@% a ] ] " @@ Fmt . ( list @@ pair string string ) ( N . bindings aliases )
module Extend = struct module Bound = struct type t = { inf : int ; sup : int } let all = { inf = max_int ; sup = min_int } let add b x = { sup = max x b . sup ; inf = min x b . inf } let extrema = List . fold_left add all end module IntMap = Map . Make ( Int ) let decorate_enum = function | Refined_types . Ty . Enum c...
type id = string [ @@ deriving equal , yojson , sexp ] sexp
let id_of_string s = s
let string_of_id s = s
type repr = { id : id ; event_name : string ; arguments : String . Set . t ; log : t -> ( string * ( string * Yojson . Safe . t ) t list ) list option ; parse : ( string * Yojson . Safe . t ) t list -> t option }
module Registry = struct let reprs : repr list ref = ref [ ] let register_constructor repr = reprs := repr :: ! reprs end
let parse_exn id json_pairs = let result = List . find_map ! Registry . reprs ~ f ( : fun repr -> if equal_id id repr . id then let json_pairs = List . filter json_pairs ~ f ( : fun ( field_name , _ ) _ -> Set . mem repr . arguments field_name ) in match repr . parse json_pairs with | Some t -> Some t | None -> failwit...
let log t = let result = List . find_map ! Registry . reprs ~ f ( : fun repr -> Option . map ( repr . log t ) t ~ f ( : fun ( msg , fields ) fields -> ( msg , repr . id , fields ) fields ) fields ) in match result with | Some data -> data | None -> let [ let @ warning " - 3 ] " name = Obj . extension_name ( Obj . exten...