text stringlengths 0 601k |
|---|
let alloc_set fpad descr size tag = if size = 0 then ( fpad . need_xalloc <- true ; let ptr = " xalloc " in let young = false in ( alloc_atom fpad tag @ push_local ptr , ptr , young ) ) else alloc_non_atom fpad descr size tag |
let grab_helper gpad = let fpad = empty_fpad ( ) in let descr = empty_descr in assert ( descr . stack_save_accu = false ) ; [ L ( [ [ K " func " ; ID " grab_helper " ; L [ K " param " ; ID " envptr " ; K " i32 " ] ; L [ K " param " ; ID " extra_args " ; K " i32 " ] ; L [ K " param " ; ID " codeptr " ; K " i32 " ] ; L [... |
let restart_helper gpad = [ L ( [ [ K " func " ; ID " restart_helper " ; L [ K " param " ; ID " envptr " ; K " i32 " ] ; L [ K " param " ; ID " extra_args " ; K " i32 " ] ; L [ K " param " ; ID " fp " ; K " i32 " ] ; BR ; L [ K " result " ; C " out_extra_args " ; K " i32 " ] ; ] ; if ! enable_multireturn then [ L [ K "... |
let call_restart_helper ( ) = [ L [ K " call " ; ID " restart_helper " ] ] @ if ! enable_multireturn then [ ] else [ L [ K " global . get " ; ID " retval2 " ] ] |
let reinit_frame = [ L [ K " func " ; ID " reinit_frame " ; L [ K " param " ; ID " fp " ; K " i32 " ] ; L [ K " param " ; ID " depth " ; K " i32 " ] ; L [ K " param " ; ID " old_num_args " ; K " i32 " ] ; L [ K " param " ; ID " new_num_args " ; K " i32 " ] ; BR ; L [ K " result " ; C " out_fp " ; K " i32 " ] ; L [ K " ... |
let reinit_frame_k new_num_args = [ L ( [ K " func " ; ID ( sprintf " reinit_frame_ % d " new_num_args ) ; L [ K " param " ; ID " fp " ; K " i32 " ] ; L [ K " param " ; ID " depth " ; K " i32 " ] ; L [ K " param " ; ID " old_num_args " ; K " i32 " ] ; BR ; L [ K " result " ; C " out_fp " ; K " i32 " ] ; L [ K " local "... |
let return_helper = [ L ( [ [ K " func " ; ID " return_helper " ; L [ K " param " ; ID " envptr " ; K " i32 " ] ; L [ K " param " ; ID " extra_args " ; K " i32 " ] ; L [ K " param " ; ID " fp " ; K " i32 " ] ; L [ K " param " ; ID " accu " ; K " i32 " ] ; BR ; L [ K " result " ; K " i32 " ] ; L [ K " local " ; ID " cod... |
let appterm_helper ( ) = [ L ( [ [ K " func " ; ID " appterm_helper " ; L [ K " param " ; ID " envptr " ; K " i32 " ] ; L [ K " param " ; ID " codeptr " ; K " i32 " ] ; L [ K " param " ; ID " accu " ; K " i32 " ] ; L [ K " param " ; ID " extra_args " ; K " i32 " ] ; L [ K " param " ; ID " new_num_args " ; K " i32 " ] ;... |
let call_appterm_helper ( ) = [ L [ K " call " ; ID " appterm_helper " ] ] @ if ! enable_multireturn then [ ] else [ L [ K " global . get " ; ID " retval2 " ] ] |
let mlookup = [ L ( [ [ K " func " ; ID " mlookup " ; L [ K " param " ; ID " obj " ; K " i32 " ] ; L [ K " param " ; ID " tag " ; K " i32 " ] ; L [ K " param " ; ID " cache " ; K " i32 " ] ; BR ; L [ K " result " ; C " method " ; K " i32 " ] ; L [ K " local " ; ID " meths " ; K " i32 " ] ; L [ K " local " ; ID " ofs " ... |
let wasicaml_get_data = [ L [ K " func " ; ID " wasicaml_get_data " ; L [ K " result " ; K " i32 " ] ; BR ; L [ K " i32 . const " ; ID " data " ] ; L [ K " return " ] ] ] |
let wasicaml_get_data_size size = [ L [ K " func " ; ID " wasicaml_get_data_size " ; L [ K " result " ; K " i32 " ] ; BR ; L [ K " i32 . const " ; N ( I32 ( Int32 . of_int size ) ) ] ; L [ K " return " ] ] ] |
let wasicaml_init = [ L [ K " func " ; ID " wasicaml_init " ; BR ; L [ K " call " ; ID " wasicaml_get_global_data " ] ; L [ K " global . set " ; ID " wasicaml_global_data " ] ; L [ K " call " ; ID " wasicaml_get_domain_state " ] ; L [ K " global . set " ; ID " wasicaml_domain_state " ] ; L [ K " call " ; ID " wasicaml_... |
let tovalue_alloc fpad repr descr_opt = match repr with | RValue | RIntVal -> [ ] | RInt | RIntUnclean -> [ L [ K " i32 . const " ; N ( I32 1l ) ; ] ; L [ K " i32 . shl " ] ; L [ K " i32 . const " ; N ( I32 1l ) ; ] ; L [ K " i32 . or " ] ; ] | RFloat -> ( match descr_opt with | None -> failwith " cannot convert to dou... |
let tovalue fpad repr = tovalue_alloc fpad repr None |
let toint repr = match repr with | RInt -> [ ] | RIntUnclean -> [ L [ K " i32 . const " ; N ( I32 1l ) ] ; L [ K " i32 . shl " ] ; L [ K " i32 . const " ; N ( I32 1l ) ] ; L [ K " i32 . shr_s " ] ; ] | RValue | RIntVal -> [ L [ K " i32 . const " ; N ( I32 1l ) ] ; L [ K " i32 . shr_s " ] ; ] | _ -> assert false |
let tointunclean repr = match repr with | RIntUnclean -> [ ] | _ -> toint repr |
let tofloat repr = match repr with | RValue -> load_double | _ -> assert false |
let convert fpad repr_from repr_to descr_opt = match repr_to with | RValue | RIntVal -> tovalue_alloc fpad repr_from descr_opt | RInt -> toint repr_from | RIntUnclean -> tointunclean repr_from | RFloat -> tofloat repr_from | _ -> assert false |
let push_global offset = [ L [ K " global . get " ; ID " wasicaml_global_data " ; ] ; L [ K " i32 . load " ] ; L [ K " i32 . load " ; K ( sprintf " offset = 0x % lx " ( Int32 . of_int ( 4 * offset ) ) ) ; K " align = 2 " ; ] ] |
let follow_path path = List . map ( fun field -> L [ K " i32 . load " ; K ( sprintf " offset = 0x % lx " ( Int32 . of_int ( 4 * field ) ) ) ; K " align = 2 " ; ] ) path |
let push fpad store = match store with | RealAccu _ -> push_local " accu " | Local ( repr , name ) -> push_local name | Const x -> push_const ( Int32 . of_int x ) | RealStack pos -> push_stack fpad pos | Atom tag -> alloc_atom fpad tag | TracedGlobal ( Glb glb_offset , path , _ ) -> push_global glb_offset @ follow_path... |
let push_alloc_as fpad store req_repr descr_opt = match store , req_repr with | Const x , ( RValue | RIntVal ) -> push_const ( Int32 . logor ( Int32 . shift_left ( Int32 . of_int x ) 1 ) 1l ) | Local ( RInt , name ) , ( RValue | RIntVal ) -> push_local name @ push_local name @ [ L [ K " i32 . add " ] ; L [ K " i32 . co... |
let push_as fpad store req_repr = push_alloc_as fpad store req_repr None |
let pop_to fpad store repr descr_opt code_value = match store with | RealAccu _ -> code_value @ tovalue_alloc fpad repr descr_opt @ pop_to_local " accu " | Local ( lrepr , name ) -> code_value @ convert fpad repr lrepr descr_opt @ pop_to_local name | RealStack pos -> ( code_value @ tovalue_alloc fpad repr descr_opt ) |... |
let copy fpad src dest descr_opt = match dest with | RealAccu _ -> push_alloc_as fpad src RValue descr_opt @ pop_to_local " accu " | Local ( repr , name ) -> push_as fpad src repr @ pop_to_local name | RealStack pos -> push_alloc_as fpad src RValue descr_opt |> pop_to_stack fpad pos | _ -> assert false |
let rec drop n l = if n > 0 then match l with | _ :: l -> drop ( n - 1 ) l | [ ] -> [ ] else l |
let emit_unary gpad fpad op src1 dest = match op with | Pnegint -> ( push_as fpad src1 RIntVal @ [ L [ K " i32 . const " ; N ( I32 ( 0xffff_fffel ) ) ; ] ; L [ K " i32 . xor " ] ; L [ K " i32 . const " ; N ( I32 2l ) ; ] ; L [ K " i32 . add " ] ; ] ) |> pop_to fpad dest RIntVal None | Pboolnot -> ( push_as fpad src1 RI... |
let emit_unaryeffect fpad op src1 = match op with | Poffsetref offset -> let local = req_tmp1_i32 fpad in push_as fpad src1 RIntVal @ [ L [ K " local . tee " ; ID local ] ; L [ K " local . get " ; ID local ] ; L [ K " i32 . load " ; K " align = 2 " ] ; L [ K " i32 . const " ; N ( I32 ( Int32 . shift_left ( Int32 . of_i... |
let emit_int_binary fpad src1 src2 dest instrs_repr instrs_int = ( push_as fpad src1 RInt @ push_as fpad src2 RInt @ instrs_int ) |> pop_to fpad dest instrs_repr None |
let emit_int_binary_unclean_ok fpad src1 src2 dest instrs_int = ( push_as fpad src1 RIntUnclean @ push_as fpad src2 RIntUnclean @ instrs_int ) |> pop_to fpad dest RIntUnclean None |
let emit_intval_binary fpad src1 src2 dest instrs_int instrs_intval = if repr_of_store src1 = RInt && repr_of_store src2 = RInt then ( push_as fpad src1 RInt @ push_as fpad src2 RInt @ instrs_int @ tovalue fpad RIntUnclean ) |> pop_to fpad dest RIntVal None else ( push_as fpad src1 RIntVal @ push_as fpad src2 RIntVal @... |
let emit_intval_binary_unclean_ok fpad src1 src2 dest instrs_int instrs_intval = let is_ok st = let repr = repr_of_store st in repr = RInt || repr = RIntUnclean in if is_ok src1 && is_ok src2 then ( push_as fpad src1 RIntUnclean @ push_as fpad src2 RIntUnclean @ instrs_int @ tovalue fpad RIntUnclean ) |> pop_to fpad de... |
let emit_intval_int_binary fpad src1 src2 dest instrs_int instrs_intval = if repr_of_store src1 = RInt then ( push_as fpad src1 RInt @ push_as fpad src2 RInt @ instrs_int @ tovalue fpad RIntUnclean ) |> pop_to fpad dest RIntVal None else ( push_as fpad src1 RIntVal @ push_as fpad src2 RInt @ instrs_intval ) |> pop_to f... |
let emit_binary gpad fpad op src1 src2 dest = match op with | Paddint -> emit_intval_binary_unclean_ok fpad src1 src2 dest [ L [ K " i32 . add " ] ] [ L [ K " i32 . add " ] ; L [ K " i32 . const " ; N ( I32 1l ) ] ; L [ K " i32 . sub " ] ] | Psubint -> emit_intval_binary_unclean_ok fpad src1 src2 dest [ L [ K " i32 . s... |
let emit_binaryeffect fpad op src1 src2 = match op with | Psetfield field -> push_as fpad src1 RValue @ ( if field <> 0 then [ L [ K " i32 . const " ; N ( I32 ( Int32 . of_int ( 4 * field ) ) ) ; ] ; L [ K " i32 . add " ] ] else [ ] ) @ push_as fpad src2 RValue @ [ L [ K " call " ; ID " caml_modify " ] ] | Psetfloatfie... |
let emit_ternaryeffect fpad op src1 src2 src3 = match op with | Psetvectitem -> push_as fpad src1 RValue @ ( match src2 , repr_of_store src2 with | Const c , _ -> [ L [ K " i32 . const " ; N ( I32 ( Int32 . shift_left ( Int32 . of_int c ) 2 ) ) ] ; L [ K " i32 . add " ] ] | _ , ( RInt | RIntUnclean ) -> push_as fpad sr... |
type mb_elem = | MB_store of store | MB_const of int32 | MB_code of sexp list |
let push_mb_elem fpad = function | MB_store src -> push_as fpad src RValue | MB_const n -> push_const n | MB_code code -> code |
let makeblock fpad descr src_list tag = let size = List . length src_list in let sexpl_alloc , ptr , young = alloc_set fpad descr size tag in let sexpl_init = if young then List . mapi ( fun field src -> push_mb_elem fpad src |> pop_to_field ptr field ) src_list else List . mapi ( fun field src -> push_field_addr ptr f... |
let makefloatblock fpad descr src_list = let size = List . length src_list in let wosize = size * double_size in let sexpl_alloc , ptr , _ = alloc_set fpad descr wosize double_array_tag in let sexpl_init = List . mapi ( fun field src -> ( push_as fpad src RValue @ load_double ) |> pop_to_double_field ptr field ) src_li... |
let lookup_label gpad lab = let letrec_label , subfunc = try Hashtbl . find gpad . funcmapping lab with Not_found -> assert false in let wasmindex = try Hashtbl . find gpad . wasmindex letrec_label with Not_found -> assert false in ( wasmindex , letrec_label , subfunc ) |
let push_wasmptr gpad lab = let wasmindex , letrec_label , subfunc = lookup_label gpad lab in [ L [ K " i32 . const " ; ID ( Hashtbl . find gpad . letrec_name letrec_label ) ] ] |
let push_codeptr gpad lab = let wasmindex , letrec_label , subfunc = lookup_label gpad lab in push_wasmptr gpad lab @ [ L [ K " i32 . const " ; N ( I32 ( Int32 . of_int code_pointer_shift ) ) ] ; L [ K " i32 . shl " ] ; L [ K " i32 . const " ; N ( I32 ( Int32 . of_int ( ( subfunc lsl 2 ) + 1 ) ) ) ] ; L [ K " i32 . or ... |
let closurerec gpad fpad descr src_list dest_list = let nfuncs = List . length dest_list in let envofs = nfuncs * 3 - 1 in let mb_src_list = ( List . mapi ( fun i ( _ , label ) -> ( if i > 0 then [ MB_const ( Int32 . of_int ( make_header ( 3 * i ) infix_tag ) ) ] else [ ] ) @ [ MB_code ( push_codeptr gpad label ) ] @ [... |
let c_call gpad fpad descr src_list name = let descr = { descr with stack_save_accu = false } in let sexpl_setup = setup_for_gc fpad descr in let sexpl_restore = restore_after_gc fpad descr in let sexpl_args = List . map ( fun src -> push_as fpad src RValue ) src_list in let sexpl_call = [ L [ K " call " ; ID name ] ] ... |
let c_call_vector gpad fpad descr numargs depth name = let descr = { descr with stack_save_accu = false } in let sexpl_setup = setup_for_gc fpad descr in let sexpl_restore = restore_after_gc fpad descr in let sexpl_call = push_field_addr " fp " ( - depth ) @ push_const ( Int32 . of_int numargs ) @ [ L [ K " call " ; ID... |
let string_label = function | Label k -> sprintf " label % d " k | Loop k -> sprintf " loop % d " k |
let switch fpad src labls_ints labls_blocks = fpad . need_panic <- true ; let value = req_tmp1_i32 fpad in push_as fpad src RValue @ pop_to_local value @ [ L [ K " local . get " ; ID value ] ; L [ K " i32 . const " ; N ( I32 1l ) ] ; L [ K " i32 . and " ] ; L [ K " if " ; L [ K " then " ; L [ K " local . get " ; ID val... |
let grab fpad num = let sexpl = [ L [ K " local . get " ; ID " codeptr " ] ; L [ K " i32 . const " ; N ( I32 code_pointer_restart_mask ) ] ; L [ K " i32 . and " ] ; L [ K " if " ; L ( [ K " then " ; L [ K " local . get " ; ID " envptr " ] ; L [ K " local . get " ; ID " extra_args " ] ; L [ K " local . get " ; ID " fp "... |
let return = [ C " $ return " ; L [ K " local . get " ; ID " extra_args " ] ; L [ K " if " ; L [ K " then " ; L [ K " local . get " ; ID " envptr " ] ; L [ K " local . get " ; ID " extra_args " ] ; L [ K " local . get " ; ID " fp " ] ; L [ K " local . get " ; ID " accu " ] ; L [ K " call " ; ID " return_helper " ] ; L ... |
let throw fpad = if fpad . fpad_scope . cfg_main && fpad . fpad_scope . cfg_try_labels = [ ] then [ L [ K " call " ; ID " wasicaml_throw " ] ; L [ K " unreachable " ] ] else if fpad . fpad_scope . cfg_try_labels = [ ] then [ L [ K " i32 . const " ; N ( I32 0l ) ] ; L [ K " return " ] ] else [ L [ K " i32 . const " ; N ... |
let apply_direct gpad fpad funlabel numargs depth = let _ , letrec_label , _ = lookup_label gpad funlabel in let letrec_name = Hashtbl . find gpad . letrec_name letrec_label in let env_pos = ( - depth + numargs + 1 ) in ( push_local " accu " |> pop_to_stack fpad env_pos ) @ push_field_addr " fp " env_pos @ [ L [ K " i3... |
let apply fpad numargs depth = let env_pos = ( - depth + numargs + 1 ) in let codeptr = req_tmp1_i32 fpad in ( push_local " accu " |> pop_to_stack fpad env_pos ) @ push_field_addr " fp " env_pos @ [ L [ K " i32 . const " ; N ( I32 ( Int32 . of_int ( numargs - 1 ) ) ) ] ; ] @ push_field " accu " 0 @ ( if ! enable_deadbe... |
let appterm_common fpad = [ C " $ appterm_common " ; L [ K " local . get " ; ID " envptr " ] ; L [ K " local . get " ; ID " codeptr " ] ; L [ K " local . get " ; ID " accu " ] ; L [ K " local . get " ; ID " extra_args " ] ; L [ K " local . get " ; ID " appterm_new_num_args " ] ; ] @ call_appterm_helper ( ) @ [ L [ K " ... |
let appterm gpad fpad numargs oldnumargs depth = let sexpl = if numargs <= 10 then ( gpad . need_reinit_frame_k <- ISet . add numargs gpad . need_reinit_frame_k ; push_local " fp " @ push_const ( Int32 . of_int depth ) @ push_const ( Int32 . of_int oldnumargs ) @ [ L [ K " call " ; ID ( sprintf " reinit_frame_ % d " nu... |
let trap gpad fpad trylabel catchlabel depth = let local1 = req_tmp1_i32 fpad in let local2 = req_tmp2_i32 fpad in let sexpl_stack = ( push_const 0l |> pop_to_stack fpad ( - depth - 1 ) ) @ ( push_const 0l |> pop_to_stack fpad ( - depth - 2 ) ) @ ( push_const 0l |> pop_to_stack fpad ( - depth - 3 ) ) @ ( push_local " e... |
let rec emit_instr gpad fpad instr = match instr with | Wcomment s -> [ ] | Wblock arg -> ( match arg . label with | Label lab -> [ L ( [ K " block " ; ID ( sprintf " label % d " lab ) ; BR ] @ emit_instrs gpad fpad arg . body ) ] | Loop lab -> [ L ( [ K " loop " ; ID ( sprintf " loop % d " lab ) ; BR ] @ emit_instrs g... |
let emit_fblock gpad fpad fblock = let maxdepth = Wc_tracestack . max_stack_depth_of_fblock fblock in fpad . maxdepth <- if maxdepth > 0 then maxdepth + 2 else 0 ; let instrs = Wc_unstack . transl_fblock fpad . lpad fblock |> emit_instrs gpad fpad in set_bp fpad @ ( if ! enable_deadbeef_check && fpad . maxdepth > 0 the... |
let get_funcmapping scode = let open Wc_control in let funcmapping = Hashtbl . create 7 in let subfunction_num = Hashtbl . create 7 in let subfunctions = Hashtbl . create 7 in IMap . iter ( fun func_label fblock -> let letrec_func_label = match fblock . scope . cfg_letrec_label with | None -> 0 | Some label -> label in... |
let block_cascade start_sexpl label_sexpl_pairs = let rec shift prev_sexpl pairs = match pairs with | ( label , lsexpl ) :: pairs ' -> ( prev_sexpl , Some label ) :: shift lsexpl pairs ' | [ ] -> [ prev_sexpl , None ] in let rec arrange inner_sexpl shifted = match shifted with | ( sexpl , label_opt ) :: shifted ' -> le... |
let cond_section cond label sexpl_section sexpl_users = if cond then [ L ( [ K " block " ; ID label ; BR ] @ sexpl_users ) ] @ sexpl_section else sexpl_users |
let cond_loop cond label sexpl = if cond then [ L ( [ K " loop " ; ID label ; BR ] @ sexpl ) ] else sexpl |
let eff_label = function | Func l -> l | Main l -> l |
let init_lpad_for_subfunc gpad fpad func_label = let func_offset , environment = ( try Hashtbl . find gpad . glbfun_table func_label with Not_found -> 0 , [ | ] | ) in fpad . lpad . environment <- environment ; fpad . lpad . func_offset <- func_offset |
let generate_function scode gpad letrec_label func_name subfunc_labels export_flag = let fpad = { ( empty_fpad ( ) ) with fpad_letrec_label = letrec_label } in Hashtbl . add fpad . lpad . locals " accu " RValue ; Hashtbl . add fpad . lpad . locals " bp " RValue ; fpad . lpad . avoid_locals <- export_flag ; fpad . lpad ... |
let generate_letrec scode gpad letrec_label = let subfunc_labels = try Hashtbl . find gpad . subfunctions letrec_label with Not_found -> assert false in assert ( subfunc_labels <> [ ] ) ; let func_name = Hashtbl . find gpad . letrec_name letrec_label in let export = ( letrec_label = Main 0 ) in generate_function scode ... |
let globals ( ) = [ " wasicaml_global_data " , true , TI32 ; " wasicaml_domain_state " , true , TI32 ; " wasicaml_atom_table " , true , TI32 ; " wasicaml_stack_threshold " , true , TI32 ; " exn_result " , true , TI32 ; ] @ if ! enable_multireturn then [ ] else [ " retval2 " , true , TI32 ; " retval3 " , true , TI32 ; ] |
let imp_functions = [ " env " , " caml_alloc_small_dispatch " , [ L [ K " param " ; K " i32 " ] ; L [ K " param " ; K " i32 " ] ; L [ K " param " ; K " i32 " ] ; L [ K " param " ; K " i32 " ] ; ] ; " env " , " caml_alloc_small " , [ L [ K " param " ; K " i32 " ] ; L [ K " param " ; K " i32 " ] ; L [ K " result " ; K " ... |
let sanitize = String . map ( fun c -> match c with | ' A ' . . ' Z ' | ' a ' . . ' z ' | ' 0 ' . . ' 9 ' | ' _ ' | ' . ' -> c | _ -> ' ' ? ) |
let bigarray_to_string_list limit ba = let n = Array1 . dim ba in let l = ref [ ] in let p = ref 0 in while ! p < n do let q = min ( n - ! p ) limit in let by = Bytes . create q in for i = 0 to q - 1 do Bytes . set by i ba . { ! p + i } done ; l := Bytes . to_string by :: ! l ; p := ! p + q done ; List . rev ! l |
let generate scode exe get_defname globals_table = let ( funcmapping , subfunctions ) = get_funcmapping scode in let letrec_name = Hashtbl . create 7 in Hashtbl . iter ( fun _ ( letrec_label , _ ) -> match letrec_label with | Main 0 -> Hashtbl . add letrec_name letrec_label " letrec_main " | Main lab -> Hashtbl . add l... |
type repr = | RValue | RInt | RIntUnclean | RIntVal | RNatInt | RInt32 | RInt64 | RFloat |
type global_lookup = | Glb of int | Env of int |
type store = | RealStack of int | RealAccu of { no_function : bool } | Const of int | Local of repr * string | Atom of int | TracedGlobal of global_lookup * int list * Wc_traceglobals . initvalue | Invalid |
type global = Global of int |
type label = Label of int | Loop of int |
type stack_descriptor = { stack_uninit : int list ; stack_depth : int ; stack_save_accu : bool ; } |
type unop = | Pnegint | Pboolnot | Poffsetint of int | Pisint | Pgetfield of int | Pgetfloatfield of int | Pvectlength | Pgetpubmet of int |
type uneffect = | Poffsetref of int | Psetglobal of global |
type binop = | Paddint | Psubint | Pmulint | Pdivint | Pmodint | Pandint | Porint | Pxorint | Plslint | Plsrint | Pasrint | Pintcomp of Lambda . integer_comparison | Puintcomp of Lambda . integer_comparison | Pgetvectitem | Pgetstringchar | Pgetbyteschar | Pgetmethod | Pgetdynmet |
type bineffect = | Psetfield of int | Psetfloatfield of int |
type terneffect = | Psetvectitem | Psetbyteschar |
type winstruction = | Wcomment of string | Wblock of { label : label ; body : winstruction list } | Wcond of { cond : bool ref ; ontrue : winstruction ; onfalse : winstruction } | Wcopy of { src : store ; dest : store } | Walloc of { src : store ; dest : store ; descr : stack_descriptor } | Wenv of { field : int } | Wc... |
let repr_comparable_as_i32 r1 r2 = match r1 , r2 with | ( RValue | RIntVal ) , ( RValue | RIntVal ) -> true | ( RInt | RNatInt | RInt32 ) , ( RInt | RNatInt | RInt32 ) -> true | _ -> false |
let repr_of_store = function | RealStack _ -> RValue | Const _ -> RInt | Local ( repr , _ ) -> repr | RealAccu _ -> RValue | Atom _ -> RValue | TracedGlobal _ -> RValue | Invalid -> assert false |
let empty_descr = { stack_uninit = [ ] ; stack_depth = 0 ; stack_save_accu = false ; } |
let string_of_store = function | RealStack pos -> sprintf " fp [ % d ] " pos | RealAccu _ -> " accu " | Const k -> sprintf " % d " k | Local ( repr , name ) -> name | Atom k -> sprintf " atom % d " k | TracedGlobal ( glb , path , _ ) -> let s_glb = match glb with | Glb i -> sprintf " global % d " i | Env i -> sprintf "... |
let string_label = function | Label k -> sprintf " label % d " k | Loop k -> sprintf " loop % d " k |
let extract_directly_callable_function st = match st with | TracedGlobal ( glb , path , FuncInEnv { func_offset ; env } ) -> let func = env . ( func_offset ) in ( match func with | Function { label } -> Some ( glb , path , label , env ) | _ -> None ) | _ -> None |
let rec string_of_winstruction = function | Wcomment s -> s | Wblock arg -> ( match arg . label with | Label k -> sprintf " Wblock ( . . . , label % d ) " k | Loop k -> sprintf " Wblock ( loop % d , . . . ) " k ) | Wcond { cond ; ontrue ; onfalse } -> string_of_winstruction ( if ! cond then ontrue else onfalse ) | Wcop... |
let mk_table l = let tab = Hashtbl . create 7 in List . iter ( fun k -> Hashtbl . add tab k ( ) ) l ; tab |
let prims_non_func_result = [ " caml_abs_float " ; " caml_acos_float " ; " caml_add_debug_info " ; " caml_add_float " ; " caml_alloc_dummy_float " ; " caml_array_append " ; " caml_array_blit " ; " caml_array_concat " ; " caml_array_fill " ; " caml_array_get_float " ; " caml_array_set " ; " caml_array_set_addr " ; " cam... |
type executable = { dll_paths : string list ; dll_names : string list ; primitives : string array ; code : string ; data : ( char , int8_unsigned_elt , c_layout ) Array1 . t ; symbols : Symtable . global_map ; debug : ( int , string ) Hashtbl . t ; } |
let read_bigstring f len = let ba = Array1 . create Char c_layout len in let by = Bytes . create 4096 in let n = ref len in let k = ref 0 in while ! n > 0 do let p = min ! n 4096 in really_input f by 0 p ; for i = 0 to p - 1 do ba . { ! k + i } <- Bytes . get by i done ; k := ! k + p ; n := ! n - p ; done ; ba |
let input_stringlist f section = try let s = Bytesections . read_section_string f section in let l = String . split_on_char ' \ 000 ' s in List . filter ( fun elem -> elem <> " " ) l with | Not_found -> [ ] |
let input_objarray_as_bigstring f section = try let _len = Bytesections . seek_section f section in let p1 = pos_in f in let _dummay = Marshal . from_channel f in let p2 = pos_in f in let _len = Bytesections . seek_section f section in read_bigstring f ( p2 - p1 ) with | Not_found -> Array1 . create Char c_layout 0 |
let input_symbols f section : Symtable . global_map = try let _len = Bytesections . seek_section f section in Marshal . from_channel f with | Not_found -> Symtable . empty_global_map |
let input_debug f section = let ht = Hashtbl . create 7 in try let _len = Bytesections . seek_section f section in let n = input_binary_int f in for k = 1 to n do let ofs = input_binary_int f in let evl = input_value f in let _ = input_value f in List . iter ( fun ev -> Hashtbl . add ht I . ( ( ofs + ev . ev_pos ) / 4 ... |
let read_executable name = let f = open_in name in Bytesections . read_toc f ; let dll_paths = input_stringlist f " DLPT " in let dll_names = input_stringlist f " DLLS " in let primitives = input_stringlist f " PRIM " |> Array . of_list in let code = Bytesections . read_section_string f " CODE " in let data = input_obj... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.