text
stringlengths
12
786k
let emit ~ asm_directives ? comment t = let module A = ( val asm_directives : Asm_directives . S ) in match t with | Thirty_two i -> A . int32 ? comment i | Sixty_four i -> A . int64 ? comment i
type t = | C89 | C | Ada83 | C_plus_plus | Cobol74 | Cobol85 | Fortran77 | Fortran90 | Pascal83 | Modula2 | Java | C99 | Ada95 | Fortran95 | PLI | ObjC | ObjC_plus_plus | UPC | D | Python | OpenCL | Go | Modula3 | Haskell | C_plus_plus_03 | C_plus_plus_11 | OCaml | Rust | C11 | Swift | J...
let name t = match t with | C89 -> " C89 " | C -> " C " | Ada83 -> " Ada83 " | C_plus_plus -> " C_plus_plus " | Cobol74 -> " Cobol74 " | Cobol85 -> " Cobol85 " | Fortran77 -> " Fortran77 " | Fortran90 -> " Fortran90 " | Pascal83 -> " Pascal83 " | Modula2 -> " M...
let encode = function | C89 -> 0x01 | C -> 0x02 | Ada83 -> 0x03 | C_plus_plus -> 0x04 | Cobol74 -> 0x05 | Cobol85 -> 0x06 | Fortran77 -> 0x07 | Fortran90 -> 0x08 | Pascal83 -> 0x09 | Modula2 -> 0x0a | Java -> 0x0b | C99 -> 0x0c | Ada95 -> 0x0d | Fortran95 -> 0x0e | PLI -> 0x...
let as_dwarf_value t = Dwarf_value . int8 ~ comment ( : name t ) ( Numbers . Int8 . of_int_exn ( encode t ) )
type implicit_value = | Int of Targetint . t | Symbol of Asm_symbol . t
type t = | DW_op_lit0 | DW_op_lit1 | DW_op_lit2 | DW_op_lit3 | DW_op_lit4 | DW_op_lit5 | DW_op_lit6 | DW_op_lit7 | DW_op_lit8 | DW_op_lit9 | DW_op_lit10 | DW_op_lit11 | DW_op_lit12 | DW_op_lit13 | DW_op_lit14 | DW_op_lit15 | DW_op_lit16 | DW_op_lit17 | DW_op_lit18 | DW_op_lit19 | DW_op_lit20 | DW...
let opcode_name t = match t with | DW_op_lit0 -> " DW_op_lit0 " | DW_op_lit1 -> " DW_op_lit1 " | DW_op_lit2 -> " DW_op_lit2 " | DW_op_lit3 -> " DW_op_lit3 " | DW_op_lit4 -> " DW_op_lit4 " | DW_op_lit5 -> " DW_op_lit5 " | DW_op_lit6 -> " DW_op_lit6 " | DW_op_lit7 -> " DW_op...
let opcode = function | DW_op_lit0 -> 0x30 | DW_op_lit1 -> 0x31 | DW_op_lit2 -> 0x32 | DW_op_lit3 -> 0x33 | DW_op_lit4 -> 0x34 | DW_op_lit5 -> 0x35 | DW_op_lit6 -> 0x36 | DW_op_lit7 -> 0x37 | DW_op_lit8 -> 0x38 | DW_op_lit9 -> 0x39 | DW_op_lit10 -> 0x3a | DW_op_lit11 -> 0x3b | DW_o...
module Make ( M : sig type param type result val unit_result : unit -> result val opcode : param -> t -> result val value : param -> V . t -> result val ( >>> ) : param -> result -> ( unit -> result ) -> result struct let run param t = let unit_result = M . unit_result ( ) in let opco...
module Print = Make ( struct type param = Format . formatter type result = unit let unit_result ( ) = ( ) let opcode ppf t = Format . pp_print_string ppf ( opcode_name t ) let value ppf v = V . print ppf v let ( >>> ) ppf ( ) f = Format . pp_print_string ppf " " ; f ( ) e...
module Size = Make ( struct type param = unit type result = I . t let unit_result ( ) = I . zero ( ) let opcode ( ) _ = I . one ( ) let value ( ) v = V . size v let ( >>> ) ( ) size f = I . add size ( f ( ) ) end )
module Emit = Make ( struct type param = ( module Asm_directives . S ) type result = unit let unit_result ( ) = ( ) let opcode asm_directives t = let comment = opcode_name t in V . emit ~ asm_directives ( V . uint8 ~ comment ( Uint8 . of_nonnegative_int_exn ( opcode t ) ) ) let...
let print ppf t = Print . run ppf t
let size t = Size . run ( ) t
let emit ~ asm_directives t = Emit . run asm_directives t
type dwarf_4 = | GNU_call_site | GNU_call_site_parameter
type t = | Array_type | Class_type | Entry_point | Enumeration_type | Formal_parameter | Imported_declaration | Label | Lexical_block | Member | Pointer_type | Reference_type | Compile_unit | String_type | Structure_type | Subroutine_type | Typedef | Union_type | Unspecified_parameters | Variant | ...
let tag_name t = let name = match t with | Array_type -> " array_type " | Class_type -> " class_type " | Entry_point -> " entry_point " | Enumeration_type -> " enumeration_type " | Formal_parameter -> " formal_parameter " | Imported_declaration -> " imported_declaration " | Label ...
let dw_tag_lo_user = Int16 . of_int_exn 0x4080
let dw_tag_hi_user = Int16 . of_int_exn 0x7fff
let encode t = let code = match t with | Array_type -> 0x01 | Class_type -> 0x02 | Entry_point -> 0x03 | Enumeration_type -> 0x04 | Formal_parameter -> 0x05 | Imported_declaration -> 0x08 | Label -> 0x0a | Lexical_block -> 0x0b | Member -> 0x0d | Pointer_type -> 0x0f | Reference_type -...
let size t = Dwarf_value . size ( encode t )
let emit ~ asm_directives t = Dwarf_value . emit ~ asm_directives ( encode t )
let compare t1 t2 = Stdlib . compare t1 t2
type value = | Flag_true | Bool of bool | Int8 of Int8 . t | Int16 of Int16 . t | Int32 of Int32 . t | Int64 of Int64 . t | Uint8 of Uint8 . t | Uint16 of Uint16 . t | Uint32 of Uint32 . t | Uint64 of Uint64 . t | Uleb128 of Uint64 . t | Sleb128 of Int64 . t | String of string | Indir...
type t = { value : value ; comment : string option }
let print ppf { value ; comment = _ } = match value with | Flag_true -> Format . pp_print_string ppf " true " | Bool b -> Format . fprintf ppf " % b " b | Int8 i -> Int8 . print ppf i | Int16 i -> Int16 . print ppf i | Int32 i -> Format . fprintf ppf " % ld " i | Int64 i -> ...
let flag_true ? comment ( ) = { value = Flag_true ; comment }
let bool ? comment b = { value = Bool b ; comment }
let int8 ? comment i = { value = Int8 i ; comment }
let int16 ? comment i = { value = Int16 i ; comment }
let int32 ? comment i = { value = Int32 i ; comment }
let int64 ? comment i = { value = Int64 i ; comment }
let uint8 ? comment i = { value = Uint8 i ; comment }
let uint16 ? comment i = { value = Uint16 i ; comment }
let uint32 ? comment i = { value = Uint32 i ; comment }
let uint64 ? comment i = { value = Uint64 i ; comment }
let uleb128 ? comment i = { value = Uleb128 i ; comment }
let sleb128 ? comment i = { value = Sleb128 i ; comment }
let string ? comment str = { value = String str ; comment }
let indirect_string ? comment str = { value = Indirect_string str ; comment }
let absolute_address ? comment addr = { value = Absolute_address addr ; comment }
let code_address_from_label ? comment lbl = { value = Code_address_from_label lbl ; comment }
let code_address_from_symbol ? comment sym = { value = Code_address_from_symbol sym ; comment }
let code_address_from_label_symbol_diff ? comment ~ upper ~ lower ~ offset_upper ( ) = { value = Code_address_from_label_symbol_diff { upper ; lower ; offset_upper } ; comment }
let code_address_from_symbol_diff ? comment ~ upper ~ lower ( ) = { value = Code_address_from_symbol_diff { upper ; lower } ; comment }
let code_address_from_symbol_plus_bytes sym offset_in_bytes = { value = Code_address_from_symbol_plus_bytes { sym ; offset_in_bytes } ; comment = None }
let offset_into_debug_info ? comment lbl = { value = Offset_into_debug_info lbl ; comment }
let offset_into_debug_info_from_symbol ? comment sym = { value = Offset_into_debug_info_from_symbol sym ; comment }
let offset_into_debug_line ? comment lbl = { value = Offset_into_debug_line lbl ; comment }
let offset_into_debug_line_from_symbol ? comment sym = { value = Offset_into_debug_line_from_symbol sym ; comment }
let offset_into_debug_addr ? comment lbl = { value = Offset_into_debug_addr lbl ; comment }
let offset_into_debug_loc ? comment lbl = { value = Offset_into_debug_loc lbl ; comment }
let offset_into_debug_ranges ? comment lbl = { value = Offset_into_debug_ranges lbl ; comment }
let offset_into_debug_loclists ? comment lbl = { value = Offset_into_debug_loclists lbl ; comment }
let offset_into_debug_rnglists ? comment lbl = { value = Offset_into_debug_rnglists lbl ; comment }
let offset_into_debug_abbrev ? comment lbl = { value = Offset_into_debug_abbrev lbl ; comment }
let distance_between_labels_16_bit ? comment ~ upper ~ lower ( ) = { value = Distance_between_labels_16_bit { upper ; lower } ; comment }
let distance_between_labels_32_bit ? comment ~ upper ~ lower ( ) = { value = Distance_between_labels_32_bit { upper ; lower } ; comment }
let distance_between_labels_64_bit ? comment ~ upper ~ lower ( ) = { value = Distance_between_labels_64_bit { upper ; lower } ; comment }
let append_to_comment { value ; comment } to_append = let comment = match comment with | None -> Some to_append | Some comment -> Some ( comment ^ " " ^ to_append ) in { value ; comment }
let uleb128_size i = let rec uleb128_size i = if Int64 . compare i 128L < 0 then Dwarf_int . one ( ) else Dwarf_int . succ ( uleb128_size ( Int64 . shift_right_logical i 7 ) ) in let i = Uint64 . to_int64 i in if Int64 . compare i 0L < 0 then Misc . fatal_errorf " Cannot compute UL...
let rec sleb128_size i = if Int64 . compare i ( - 64L ) >= 0 && Int64 . compare i 64L < 0 then Dwarf_int . one ( ) else Dwarf_int . succ ( sleb128_size ( Int64 . shift_right i 7 ) )
let size { value ; comment = _ } = match value with | Flag_true -> Dwarf_int . zero ( ) | Bool _ -> Dwarf_int . one ( ) | Int8 _ | Uint8 _ -> Dwarf_int . one ( ) | Int16 _ | Uint16 _ -> Dwarf_int . two ( ) | Int32 _ | Uint32 _ -> Dwarf_int . four ( ) | Int64 _...
let emit ~ asm_directives { value ; comment } = let module A = ( val asm_directives : Asm_directives . S ) in let width_for_ref_addr_or_sec_offset = ! Dwarf_flags . gdwarf_format in match value with | Flag_true -> begin match comment with | None -> ( ) | Some comment -> A . comment ( c...
let emit ~ asm_directives ~ compilation_unit_proto_die ~ compilation_unit_header_label = let module A = ( val asm_directives : Asm_directives . S ) in let assigned_abbrevs = Profile . record " assign_abbrevs " ( fun ( ) -> Assign_abbrevs . run ~ proto_die_root : compilation_unit_proto_die ...
module Make ( Lexer : Sig . Lexer ) and module Token = Lexer . Token module Structure = Structure . Make Lexer ; module Delete = Delete . Make Structure ; module Insert = Insert . Make Structure ; module Entry = Entry . Make Structure ; module Fold = Fold . Make Structure ; module Too...
module Make ( Ast : Sig . Ast ) : Sig . DynAst with module Ast = Ast = struct module Ast = Ast ; type tag ' a = [ Tag_ctyp | Tag_patt | Tag_expr | Tag_module_type | Tag_sig_item | Tag_with_constr | Tag_module_expr | Tag_str_item | Tag_class_type | Tag_class_sig_item | Tag_class_expr | Tag...
module Bytecode = struct type filename = string module Unit_header = struct type t = Cmo_format . compilation_unit let name ( t : t ) = t . cu_name let crc _t = None let interface_imports ( t : t ) = t . cu_imports let implementation_imports ( t : t ) = let required = t . cu_required_gl...
module B = DC . Make ( Bytecode )
type global_map = { name : string ; crc_intf : Digest . t option ; crc_impl : Digest . t option ; syms : string list }
module Native = struct type handle external ndl_open : string -> bool -> handle * Cmxs_format . dynheader = " caml_sys_exit " " caml_natdynlink_open " external ndl_run : handle -> string -> unit = " caml_sys_exit " " caml_natdynlink_run " external ndl_getmap : unit -> global_map list = " ...
module N = DC . Make ( Native )
type linking_error = DT . linking_error = | Undefined_global of string | Unavailable_primitive of string | Uninitialized_global of string
type error = DT . error = | Not_a_bytecode_file of string | Inconsistent_import of string | Unavailable_unit of string | Unsafe_file | Linking_error of string * linking_error | Corrupted_interface of string | Cannot_open_dynamic_library of exn | Library ' s_module_initializers_failed of exn | Inconsiste...
let is_native = match Sys . backend_type with | Native -> true | Bytecode | Other _ -> false
let loadfile file = if is_native then N . loadfile file else B . loadfile file
let loadfile_private file = if is_native then N . loadfile_private file else B . loadfile_private file
let unsafe_get_global_value ~ bytecode_or_asm_symbol = if is_native then N . unsafe_get_global_value ~ bytecode_or_asm_symbol else B . unsafe_get_global_value ~ bytecode_or_asm_symbol
let adapt_filename file = if is_native then N . adapt_filename file else B . adapt_filename file
let set_allowed_units units = if is_native then N . set_allowed_units units else B . set_allowed_units units
let allow_only units = if is_native then N . allow_only units else B . allow_only units
let prohibit units = if is_native then N . prohibit units else B . prohibit units
let main_program_units units = if is_native then N . main_program_units units else B . main_program_units units
let public_dynamically_loaded_units units = if is_native then N . public_dynamically_loaded_units units else B . public_dynamically_loaded_units units
let all_units ( ) = if is_native then N . all_units ( ) else B . all_units ( )
let allow_unsafe_modules allow = if is_native then N . allow_unsafe_modules allow else B . allow_unsafe_modules allow
module String = struct include Misc . Stdlib . String module Map = struct include Map let keys t = fold ( fun key _data keys -> Set . add key keys ) t Set . empty end end
module Make ( P : Dynlink_platform_intf . S ) = struct module DT = Dynlink_types module UH = P . Unit_header type interface_dep = | Name | Contents of Digest . t type implem = Digest . t option * DT . filename * DT . implem_state module State = struct type t = { ifaces : ( interface_dep...
module type S = sig type handle module Unit_header : sig type t val name : t -> string val crc : t -> Digest . t option val interface_imports : t -> ( string * Digest . t option ) list val implementation_imports : t -> ( string * Digest . t option ) list val defined_symbols : t -> string lis...
type implem_state = | Loaded | Not_initialized | Check_inited of int
type linking_error = | Undefined_global of string | Unavailable_primitive of string | Uninitialized_global of string
type error = | Not_a_bytecode_file of string | Inconsistent_import of string | Unavailable_unit of string | Unsafe_file | Linking_error of string * linking_error | Corrupted_interface of string | Cannot_open_dynamic_library of exn | Library ' s_module_initializers_failed of exn | Inconsistent_implementatio...
let error_message = function | Not_a_bytecode_file name -> name ^ " is not an object file " | Inconsistent_import name -> " interface mismatch on " ^ name | Unavailable_unit name -> " no implementation available for " ^ name | Unsafe_file -> " this object file uses unsafe features " | Linki...
let ( ) = Printexc . register_printer ( function | Error err -> let msg = match err with | Not_a_bytecode_file s -> Printf . sprintf " Not_a_bytecode_file % S " s | Inconsistent_import s -> Printf . sprintf " Inconsistent_import % S " s | Unavailable_unit s -> Printf . sprintf " Unav...
type t = Queue . t string ; let q = Queue . create ( ) in do { if ocaml_stdlib then include_dir q Camlp4_config . ocaml_standard_library else ( ) ; if camlp4_stdlib then do { include_dir q Camlp4_config . camlp4_standard_library ; include_dir q ( Filename . concat Camlp4_config . camlp...
let rev_split l = let rec inner xs ys = function | ( x , y ) :: xys -> inner ( x :: xs ) ( y :: ys ) xys | [ ] -> ( xs , ys ) in inner [ ] [ ] l
type wrap = [ | ` Wrap_atoms | ` Always_wrap | ` Never_wrap | ` Force_breaks | ` Force_breaks_rec | ` No_breaks ]
type label_break = [ | ` Auto | ` Always | ` Always_rec | ` Never ]