text stringlengths 12 786k |
|---|
module type Cyclesim = sig module Port_list = Cyclesim0 . Port_list module Digest = Cyclesim0 . Digest module Config = Cyclesim0 . Config type ( ' i , ' o ) t type t_port_list = ( Port_list . t , Port_list . t ) t val circuit : _ t -> Circuit . t option val cycle : _ t -> unit val... |
type t = { schedule : Signal . t list ; regs : Signal . t list ; mems : Signal . t list ; consts : Signal . t list ; inputs : Signal . t list ; aliases : Signal . t Hashtbl . M ( Signal . Uid ) . t } |
let find_elements circuit = Signal_graph . depth_first_search ( Circuit . signal_graph circuit ) ~ init ( [ ] , : [ ] , [ ] , [ ] , [ ] ) ~ f_before ( : fun ( regs , mems , consts , inputs , comb_signals ) signal -> if Signal . is_empty signal then regs , ... |
let rec unwrap_signal ( signal : Signal . t ) = match signal with | Wire { driver ; _ } -> if Signal . is_empty ! driver then None else ( match unwrap_signal ! driver with | Some _ as ret -> ret | None -> Some ! driver ) | _ -> Some signal ; ; |
let unwrap_wire signal = match signal with | Signal . Wire _ -> unwrap_signal signal | _ -> None ; ; |
let create_aliases signal_graph = let table = Hashtbl . create ( module Signal . Uid ) in Signal_graph . iter signal_graph ~ f ( : fun signal -> match unwrap_wire signal with | None -> ( ) | Some unwrapped -> Hashtbl . set ~ key ( : Signal . uid signal ) ~ data : unwrapped table ) ... |
let resolve_alias ( t : t ) uid = Hashtbl . find t . aliases uid |
let is_alias ( t : t ) uid = Hashtbl . mem t . aliases uid |
let scheduling_deps ( s : Signal . t ) = Signal_graph . scheduling_deps s |
let create circuit internal_ports = let regs , mems , consts , inputs , comb_signals = find_elements circuit in let outputs = Circuit . outputs circuit @ internal_ports in let signal_graph = Signal_graph . create outputs in let aliases = create_aliases signal_graph in let schedule = if List . is_em... |
type ' a dagnode = { mutable parents : ' a list ; mutable children : ' a list } |
type ' a t = { nodes : ( ' a , ' a dagnode ) Hashtbl . t } |
let init ( ) = { nodes = Hashtbl . create 16 } |
let length dag = Hashtbl . length dag . nodes |
let addEdge a b dag = let maNode = try Some ( Hashtbl . find dag . nodes a ) with Not_found -> None in let mbNode = try Some ( Hashtbl . find dag . nodes b ) with Not_found -> None in ( match ( maNode , mbNode ) with | None , None -> Hashtbl . add dag . nodes a { parents = [ ] ... |
let addNode a dag = try let _ = Hashtbl . find dag . nodes a in ( ) with Not_found -> Hashtbl . add dag . nodes a { parents = [ ] ; children = [ ] } |
let addNode_exclusive a dag = try let _ = Hashtbl . find dag . nodes a in raise DagNode_Already_Exists with Not_found -> Hashtbl . add dag . nodes a { parents = [ ] ; children = [ ] } |
let hasEdge a b dag = let maNode = try Some ( Hashtbl . find dag . nodes a ) with Not_found -> None in let mbNode = try Some ( Hashtbl . find dag . nodes b ) with Not_found -> None in match ( maNode , mbNode ) with | Some aNode , Some bNode -> List . mem b aNode . children && List . ... |
let delEdge a b dag = let maNode = try Some ( Hashtbl . find dag . nodes a ) with Not_found -> None in let mbNode = try Some ( Hashtbl . find dag . nodes b ) with Not_found -> None in ( match ( maNode , mbNode ) with | Some aNode , Some bNode -> aNode . children <- List . filter ( ... |
let addEdges l dag = List . iter ( fun ( n1 , n2 ) -> addEdge n1 n2 dag ) l |
let addEdgesConnected l dag = let rec loop parent nodes = match nodes with | [ ] -> ( ) | n :: ns -> addEdge parent n dag ; loop n ns in match l with | [ ] -> ( ) | x [ ] :: -> addNode x dag | x :: l -> loop x l |
let addChildrenEdges p l dag = List . iter ( fun x -> addEdge p x dag ) l |
let existsNode a dag = Hashtbl . mem dag . nodes a |
let getLeaves dag = Hashtbl . fold ( fun k v acc -> if v . children = [ ] then k :: acc else acc ) dag . nodes [ ] |
let getRoots dag = Hashtbl . fold ( fun k v acc -> if v . parents = [ ] then k :: acc else acc ) dag . nodes [ ] |
let getNode dag a = try Hashtbl . find dag . nodes a with Not_found -> raise DagNode_Not_found |
let getNodes dag = Hashtbl . fold ( fun k _ acc -> k :: acc ) dag . nodes [ ] |
let getChildren dag a = ( getNode dag a ) . children |
let getParents dag a = ( getNode dag a ) . parents |
let rec getChildren_full dag a = let children = getChildren dag a in children @ List . concat ( List . map ( getChildren_full dag ) children ) |
let isChildren dag a b = List . mem b ( getChildren dag a ) |
let rec isChildren_full dag a b = let children = getChildren dag a in List . mem b children || List . fold_left ( fun acc child -> acc || isChildren_full dag child b ) false children |
let subset dag roots = let subdag = init ( ) in let rec loop node = addNode node subdag ; let children = getChildren dag node in List . iter ( fun child -> addEdge node child subdag ; loop child ) children in List . iter ( fun root -> loop root ) roots ; subdag |
let copy dag = let nodes = Hashtbl . fold ( fun k _ acc -> k :: acc ) dag . nodes [ ] in let dag2 = init ( ) in let copy_node node = addNode node dag2 ; let children = getChildren dag node in addChildrenEdges node children dag2 in List . iter ( fun node -> copy_node node ) nodes ; dag... |
let merge dest src = let nodes = Hashtbl . fold ( fun k _ acc -> k :: acc ) src . nodes [ ] in let dups = ref [ ] in List . iter ( fun node -> if existsNode node dest then dups := node :: ! dups ) nodes ; let copy_node node = addNode node dest ; let children = getChildren src node ... |
let transitive_reduction dag = let reducedDag = copy dag in let nodes = Hashtbl . fold ( fun k _ acc -> k :: acc ) dag . nodes [ ] in List . iter ( fun x -> List . iter ( fun y -> List . iter ( fun z -> if hasEdge x y dag && hasEdge y z dag then delEdge x z reducedDag else ( ) ) ... |
let dump a_to_string dag = let all = getNodes dag in List . iter ( fun n -> printf " % s :\ n " ( a_to_string n ) ; printf " | parents = % s \ n " ( String . concat " , " ( List . map a_to_string ( getParents dag n ) ) ) ; printf " | children = % s \ n " ( St... |
let toDot a_to_string name fromLeaf dag = let buf = Buffer . create 1024 in let nodes = getNodes dag in let dotIndex = Hashtbl . create ( List . length nodes ) in let append = Buffer . add_string buf in let sanitizeName = bytes_of_string name in for i = 0 to String . length name - 1 do if ( b... |
let constructor_descrs ty_res cstrs priv = let num_consts = ref 0 and num_nonconsts = ref 0 in List . iter ( function ( name , [ ] ) -> incr num_consts | ( name , _ ) -> incr num_nonconsts ) cstrs ; let rec describe_constructors idx_const idx_nonconst = function [ ] -> [ ] | ... |
let exception_descr path_exc decl = { cstr_res = Predef . type_exn ; cstr_args = decl ; cstr_arity = List . length decl ; cstr_tag = Cstr_exception path_exc ; cstr_consts = - 1 ; cstr_nonconsts = - 1 ; cstr_private = Public } |
let none = { desc = Ttuple [ ] ; level = - 1 ; id = - 1 } |
let dummy_label = { lbl_name = " " ; lbl_res = none ; lbl_arg = none ; lbl_mut = Immutable ; lbl_pos = ( - 1 ) ; lbl_all = [ ] ; || lbl_repres = Record_regular ; lbl_private = Public } |
let label_descrs ty_res lbls repres priv = let all_labels = Array . create ( List . length lbls ) dummy_label in let rec describe_labels num = function [ ] -> [ ] | ( name , mut_flag , ty_arg ) :: rest -> let lbl = { lbl_name = name ; lbl_res = ty_res ; lbl_arg = ty_arg ; lbl_... |
let rec find_constr tag num_const num_nonconst = function [ ] -> raise Constr_not_found | ( name , [ ] as cstr ) :: rem -> if tag = Cstr_constant num_const then cstr else find_constr tag ( num_const + 1 ) num_nonconst rem | ( name , _ as cstr ) :: rem -> if tag = Cstr_block num_nonc... |
let find_constr_by_tag tag cstrlist = find_constr tag 0 0 cstrlist |
module Reachable_code_ids = struct type t = { live_code_ids : Code_id . Set . t ; ancestors_of_live_code_ids : Code_id . Set . t } let [ @ ocamlformat " disable " ] print ppf { live_code_ids ; ancestors_of_live_code_ids ; } = Format . fprintf ppf " [ @< hov 1 ( >\ [ @< ... |
type elt = { continuation : Continuation . t ; params : Variable . t list ; used_in_handler : Name_occurrences . t ; apply_result_conts : Continuation . Set . t ; bindings : Name_occurrences . t Name . Map . t ; code_ids : Name_occurrences . t Code_id . Map . t ; value_slots ... |
type t = { stack : elt list ; map : elt Continuation . Map . t ; extra : Continuation_extra_params_and_args . t Continuation . Map . t } |
type result = { required_names : Name . Set . t ; reachable_code_ids : Reachable_code_ids . t } |
let print_elt ppf { continuation ; params ; used_in_handler ; apply_result_conts ; bindings ; code_ids ; value_slots ; apply_cont_args } = Format . fprintf ppf " [ @< hov 1 ( [ >@< hov 1 ( > continuation % a ) ] @@ [ @< hov 1 ( > params % a ) ] @@ [ @< hov \ 1 ... |
let print_stack ppf stack = Format . fprintf ppf " [ @< v 1 ( >% a ) ] " @ ( Format . pp_print_list print_elt ~ pp_sep : Format . pp_print_space ) stack |
let print_map ppf map = Continuation . Map . print print_elt ppf map |
let print_extra ppf extra = Continuation . Map . print Continuation_extra_params_and_args . print ppf extra |
let [ @ ocamlformat " disable " ] print ppf { stack ; map ; extra } = Format . fprintf ppf " [ @< hov 1 ( >\ [ @< hov 1 ( > stack % a ) ] @@ \ [ @< hov 1 ( > map % a ) ] @@ \ [ @< hov 1 ( > extra % a ) ] @\ ) ] " @ print_stack stack print_map ... |
let _print_result ppf { required_names ; reachable_code_ids } = Format . fprintf ppf " [ @< hov 1 ( [ >@< hov 1 ( > required_names @ % a ) ] @@ [ @< hov 1 ( > reachable_code_ids @ \ % a ) ] ) ] " @@ Name . Set . print required_names Reachable_code_ids . print r... |
let empty = { stack = [ ] ; map = Continuation . Map . empty ; extra = Continuation . Map . empty } |
let add_extra_params_and_args cont extra t = let extra = Continuation . Map . update cont ( function | Some _ -> Misc . fatal_errorf " Continuation extended a second time " | None -> Some extra ) t . extra in { t with extra } |
let enter_continuation continuation params t = let elt = { continuation ; params ; bindings = Name . Map . empty ; code_ids = Code_id . Map . empty ; value_slots = Value_slot . Map . empty ; used_in_handler = Name_occurrences . empty ; apply_cont_args = Continuation . Map . empty ... |
let init_toplevel continuation params _t = enter_continuation continuation params empty |
let exit_continuation cont t = match t . stack with | [ ] -> Misc . fatal_errorf " Empty stack of variable uses " | ( { continuation ; _ } as elt ) :: stack -> assert ( Continuation . equal cont continuation ) ; let map = Continuation . Map . add cont elt t . map in { t wit... |
let update_top_of_stack ~ t ~ f = match t . stack with | [ ] -> Misc . fatal_errorf " Empty stack of variable uses " | elt :: stack -> { t with stack = f elt :: stack } |
let record_var_binding var name_occurrences ~ generate_phantom_lets t = update_top_of_stack ~ t ~ f ( : fun elt -> let bindings = Name . Map . update ( Name . var var ) ( function | None -> Some name_occurrences | Some _ -> Misc . fatal_errorf " The following variable has been bound twice ... |
let record_symbol_projection var name_occurrences t = update_top_of_stack ~ t ~ f ( : fun elt -> let bindings = Name . Map . update ( Name . var var ) ( function | None -> Some name_occurrences | Some prior_occurences as original -> if Name_occurrences . equal prior_occurences name_occurrences... |
let record_symbol_binding symbol name_occurrences t = update_top_of_stack ~ t ~ f ( : fun elt -> let bindings = Name . Map . update ( Name . symbol symbol ) ( function | None -> Some name_occurrences | Some _ -> Misc . fatal_errorf " The following symbol has been bound twice : % a " Sym... |
let record_code_id_binding code_id name_occurrences t = update_top_of_stack ~ t ~ f ( : fun elt -> let code_ids = Code_id . Map . update code_id ( function | None -> Some name_occurrences | Some _ -> Misc . fatal_errorf " The following code_id has been bound twice : % a " Code_id . print co... |
let record_value_slot src value_slot dst t = update_top_of_stack ~ t ~ f ( : fun elt -> let value_slots = Value_slot . Map . update value_slot ( function | None -> Some ( Name . Map . singleton src dst ) | Some map -> Some ( Name . Map . update src ( function | None -> Some dst | So... |
let add_used_in_current_handler name_occurrences t = update_top_of_stack ~ t ~ f ( : fun elt -> let used_in_handler = Name_occurrences . union elt . used_in_handler name_occurrences in { elt with used_in_handler } ) |
let add_apply_result_cont k t = update_top_of_stack ~ t ~ f ( : fun elt -> let apply_result_conts = Continuation . Set . add k elt . apply_result_conts in { elt with apply_result_conts } ) |
let add_apply_cont_args cont arg_name_occurrences t = update_top_of_stack ~ t ~ f ( : fun elt -> let apply_cont_args = Continuation . Map . update cont ( fun map_opt -> let map = Option . value ~ default : Numeric_types . Int . Map . empty map_opt in let map , _ = List . fold_left ( fu... |
module Dependency_graph = struct type t = { code_age_relation : Code_age_relation . t ; name_to_name : Name . Set . t Name . Map . t ; name_to_code_id : Code_id . Set . t Name . Map . t ; code_id_to_name : Name . Set . t Code_id . Map . t ; code_id_to_code_id : Code_id . Set... |
let analyze ~ return_continuation ~ exn_continuation ~ code_age_relation ~ used_value_slots { stack ; map ; extra } = Profile . record_call ~ accumulate : true " data_flow " ( fun ( ) -> assert ( stack = [ ] ) ; let deps = Dependency_graph . create map extra ~ return_continuat... |
let errmsg_to_string = function | Some msg -> msg | None -> " unknown " |
let mysql_exec dbhandle cmds = let res = exec dbhandle cmds in match status dbhandle with | StatusError _ -> let msg = errmsg dbhandle |> errmsg_to_string in let err = Printf . sprintf " MySQL Error : % s \ n " msg in failwith err | _ -> res |
let strip errmsg = function | Some s -> s | None -> failwith errmsg |
let get_int_result errmsg res = match fetch res with | None -> failwith errmsg | Some row -> strip errmsg row . ( 0 ) |> int_of_string |
let null_str dbhandle = ml2rstr dbhandle " " |
let bool_to_tinyint = function | true -> 1 | false -> 0 |
let get_insert_id dbhandle = let res = mysql_exec dbhandle " SELECT LAST_INSERT_ID ( ) ; " in get_int_result " failed to get insert id " res |
let rec reader bzch inch buf pos total = let full_pass = ( total - pos ) >= bz_block_size in let read_size = if full_pass then bz_block_size else total - pos in Pervasives . really_input inch buf 0 read_size ; Bz2 . write bzch buf 0 read_size ; if full_pass then reader bzch inch buf ( pos + bz_bl... |
let bzip_a_file origin bzfile = let inch = Pervasives . open_in origin in let outch = Pervasives . open_out bzfile in let bzch = Bz2 . open_out outch in let n = in_channel_length inch in let buf = Bytes . create bz_block_size in reader bzch inch buf 0 n ; Bz2 . close_out bzch ; Pervasives . close... |
let load_blob state = let logfile = get_logfile state . working_dir in let bzfile = Filename . concat ( Filename . dirname logfile ) " log . bz2 " in let ( ) = bzip_a_file logfile bzfile in let ch = open_in bzfile in let n = in_channel_length ch in let s = Bytes . create n in really_input c... |
let insert_campaign state dbhandle = let log = load_blob state in let _ = mysql_exec dbhandle ( Printf . sprintf " INSERT INTO campaign_tbl VALUES % s ; " ( values [ null_str dbhandle ; ml2rstr dbhandle ( time_string state . initial_time ) ; ml2rstr dbhandle ( schedule_to_string state . ... |
let insert_client state dbhandle = let new_client state dbhandle = let _ = mysql_exec dbhandle ( Printf . sprintf " INSERT INTO client_tbl VALUES % s " ( values [ null_str dbhandle ; ml2rstr dbhandle Envmanager . os ; ml2rstr dbhandle Envmanager . kernel ; ml2rstr dbhandle Envmanager . arch... |
let insert_seed dbhandle conf = let seed_hash = Digest . file conf . seed_file |> Digest . to_hex in let new_seed dbhandle conf = let _ = mysql_exec dbhandle ( Printf . sprintf " INSERT INTO seed_tbl VALUES % s " ( values [ null_str dbhandle ; ml2int conf . input_size ; ml2rstr dbhandle c... |
let insert_program dbhandle conf = let prog_path = List . hd conf . cmds in let prog_name = Filename . basename prog_path in let prog_hash = Digest . file prog_path |> Digest . to_hex in let prog_size = get_filesize prog_path in let new_prog dbhandle conf = let _ = mysql_exec dbhandle ( Printf . ... |
let insert_conf state dbhandle conf sid pid = let seed_start , seed_end = state . knobs . seed_range in let mratio_start , mratio_end = conf . mratio in let _ = mysql_exec dbhandle ( Printf . sprintf " INSERT INTO fuzz_conf_tbl VALUES % s " ( values [ null_str dbhandle ; ml2rstr dbhandle (... |
let insert_fuzzing dbhandle stats conf cpid clid cfid = let _ = mysql_exec dbhandle ( Printf . sprintf " INSERT INTO fuzzing_tbl VALUES % s " ( values [ null_str dbhandle ; ml2rstr dbhandle ( time_string stats . ( conf . confid ) . start_time ) ; ml2rstr dbhandle ( time_string stats ... |
let insert_stats dbhandle stats conf fid = let _ = mysql_exec dbhandle ( Printf . sprintf " INSERT INTO stats_tbl VALUES % s " ( values [ null_str dbhandle ; ml2int ( Hashtbl . length stats . ( conf . confid ) . unique_set ) ; ml2int stats . ( conf . confid ) . num_crashes ... |
let insert_crash_case dbhandle stats conf stid = let new_crash dbhandle crashid = let _ = mysql_exec dbhandle ( Printf . sprintf " INSERT INTO crash_case_tbl VALUES % s " ( values [ null_str dbhandle ; ml2rstr dbhandle crashid . hashval ; ml2rstr dbhandle crashid . backtrace ] ) ) in get_... |
let insert_crash_case dbhandle state conf stid = if state . knobs . triage_on_the_fly then insert_crash_case dbhandle state . stats conf stid else ( ) |
let insert_per_conf with_seed state dbhandle confs cpid clid = List . iter ( fun conf -> let sid = if with_seed then insert_seed dbhandle conf else null in let pid = insert_program dbhandle conf in let cfid = insert_conf state dbhandle conf sid pid in let fid = insert_fuzzing dbhandle state . stats conf cpi... |
let insert_per_conf state dbhandle confs cpid clid = match state . knobs . testgen_alg with | BallMutational | SurfaceMutational | ZzufMutational -> insert_per_conf true state dbhandle confs cpid clid | _ -> insert_per_conf false state dbhandle confs cpid clid |
let push_result state dbhandle confs = let _ = mysql_exec dbhandle " START TRANSACTION ; " in let cpid = insert_campaign state dbhandle in let clid = insert_client state dbhandle in let _ = insert_per_conf state dbhandle confs cpid clid in let _ = mysql_exec dbhandle " COMMIT ; " in ( ) |
let push_result state confs = let dbhandle = dbconnect state . knobs in match dbhandle with | None -> ( ) | Some dbhandle -> push_result state dbhandle confs |
type open_flag = Dbm_rdonly | Dbm_wronly | Dbm_rdwr | Dbm_create |
type dbm_flag = DBM_INSERT | DBM_REPLACE = " caml_dbm_open " |
let opendbm file flags mode = try raw_opendbm file flags mode with Dbm_error msg -> raise ( Dbm_error ( " Can ' t open file " ^ file ) ) |
let _ = Callback . register_exception " dbmerror " ( Dbm_error " " ) |
let iter f t = let rec walk = function None -> ( ) | Some k -> f k ( find t k ) ; walk ( try Some ( nextkey t ) with Not_found -> None ) in walk ( try Some ( firstkey t ) with Not_found -> None ) |
let later = ref [ ] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.