text
stringlengths
0
601k
let rec pp_identifier fmt id = fprintf fmt " ' % s ' " id pp_string fmt ( string_of_number num ) let escape_char d fmt = function | ' \ r ' -> pp_string fmt " \\ r " | ' \ n ' -> pp_string fmt " \\ n " | ' ' \\ -> pp_string fmt " " \\\\ | ' " ' when d -> pp_string fmt " " " \\\ | ' ' ' \ when not d -> pp_string fmt " '...
let pp_print_mod fmt modl = pp_mod fmt modl
let pp_print_stmt fmt stmt = pp_stmt fmt stmt
let pp_print_expr fmt expr = pp_expr fmt expr
let print_mod modl = pp_print_mod std_formatter modl
let print_stmt stmt = pp_print_stmt std_formatter stmt
let print_expr expr = pp_print_expr std_formatter expr
let print_to_string pp node = let buf = Buffer . create 4096 in let fmt = formatter_of_buffer buf in pp fmt node ; pp_print_flush fmt ( ) ; Buffer . contents buf
let dump_mod modl = print_to_string pp_print_mod modl
let dump_stmt stmt = print_to_string pp_print_stmt stmt
let dump_expr expr = print_to_string pp_print_expr expr
module Id = struct value name = " Camlp4Printers . DumpCamlp4Ast " ; value version = Sys . ocaml_version ; end ;
module Make ( Syntax : Sig . Syntax ) include Syntax ; value with_open_out_file x f = match x with [ Some file -> do { let oc = open_out_bin file ; f oc ; flush oc ; close_out oc } | None -> do { set_binary_mode_out stdout True ; f stdout ; flush stdout } ] ; value dump_ast magic ast oc = do { output_string oc magic ; ...
let inputu ic = let b1 = input_byte ic in let b2 = input_byte ic in let b3 = input_byte ic in let b4 = input_byte ic in ( b4 lsl 24 ) + ( b3 lsl 16 ) + ( b2 lsl 8 ) + b1
let inputs ic = let b1 = input_byte ic in let b2 = input_byte ic in let b3 = input_byte ic in let b4 = input_byte ic in let b4 ' = if b4 >= 128 then b4 - 256 else b4 in ( b4 ' lsl 24 ) + ( b3 lsl 16 ) + ( b2 lsl 8 ) + b1
type global_table_entry = Empty | Global of Ident . t | Constant of Obj . t
let start = ref 0
let reloc = ref ( [ ] : ( reloc_info * int ) list )
let globals = ref ( [ ] || : global_table_entry array )
let primitives = ref ( [ ] || : string array )
let objfile = ref false
let event_table = ( Hashtbl . create 253 : ( int , debug_event ) Hashtbl . t )
let relocate_event orig ev = ev . ev_pos <- orig + ev . ev_pos ; match ev . ev_repr with Event_parent repr -> repr := ev . ev_pos | _ -> ( )
let record_events orig evl = List . iter ( fun ev -> relocate_event orig ev ; Hashtbl . add event_table ev . ev_pos ev ) evl
let print_float f = if String . contains f ' . ' then printf " % s " f else printf " % s . " f ; ;
let rec print_struct_const = function Const_base ( Const_int i ) -> printf " % d " i | Const_base ( Const_float f ) -> print_float f | Const_base ( Const_string s ) -> printf " % S " s | Const_immstring s -> printf " % S " s | Const_base ( Const_char c ) -> printf " % C " c | Const_base ( Const_int32 i ) -> printf " % ...
let same_custom x y = Obj . field x 0 = Obj . field ( Obj . repr y ) 0
let rec print_obj x = if Obj . is_block x then begin let tag = Obj . tag x in if tag = Obj . string_tag then printf " % S " ( Obj . magic x : string ) else if tag = Obj . double_tag then printf " . % 12g " ( Obj . magic x : float ) else if tag = Obj . double_array_tag then begin let a = ( Obj . magic x : float array ) ...
let currpos ic = pos_in ic - ! start
let rec rassoc key = function [ ] -> raise Not_found | ( a , b ) :: l -> if b = key then a else rassoc key l
let find_reloc ic = rassoc ( pos_in ic - ! start ) ! reloc
let print_getglobal_name ic = if ! objfile then begin begin try match find_reloc ic with Reloc_getglobal id -> print_string ( Ident . name id ) | Reloc_literal sc -> print_struct_const sc | _ -> print_string " < wrong reloc " > with Not_found -> print_string " < no reloc " > end ; ignore ( inputu ic ) ; end else begin ...
let print_setglobal_name ic = if ! objfile then begin begin try match find_reloc ic with Reloc_setglobal id -> print_string ( Ident . name id ) | _ -> print_string " < wrong reloc " > with Not_found -> print_string " < no reloc " > end ; ignore ( inputu ic ) ; end else begin let n = inputu ic in if n >= Array . length ...
let print_primitive ic = if ! objfile then begin begin try match find_reloc ic with Reloc_primitive s -> print_string s | _ -> print_string " < wrong reloc " > with Not_found -> print_string " < no reloc " > end ; ignore ( inputu ic ) ; end else begin let n = inputu ic in if n >= Array . length ! primitives || n < 0 th...
let currpc ic = currpos ic / 4
type shape = | Nothing | Uint | Sint | Uint_Uint | Disp | Uint_Disp | Sint_Disp | Getglobal | Getglobal_Uint | Setglobal | Primitive | Uint_Primitive | Switch | Closurerec | Pubmet ; ;
let op_shapes = [ opACC0 , Nothing ; opACC1 , Nothing ; opACC2 , Nothing ; opACC3 , Nothing ; opACC4 , Nothing ; opACC5 , Nothing ; opACC6 , Nothing ; opACC7 , Nothing ; opACC , Uint ; opPUSH , Nothing ; opPUSHACC0 , Nothing ; opPUSHACC1 , Nothing ; opPUSHACC2 , Nothing ; opPUSHACC3 , Nothing ; opPUSHACC4 , Nothing ; o...
let print_event ev = let ls = ev . ev_loc . loc_start in let le = ev . ev_loc . loc_end in printf " File " \% s " , \ line % d , characters % d -% d :\ n " ls . Lexing . pos_fname ls . Lexing . pos_lnum ( ls . Lexing . pos_cnum - ls . Lexing . pos_bol ) ( le . Lexing . pos_cnum - ls . Lexing . pos_bol )
let print_instr ic = let pos = currpos ic in List . iter print_event ( Hashtbl . find_all event_table pos ) ; printf " % 8d " ( pos / 4 ) ; let op = inputu ic in if op >= Array . length names_of_instructions || op < 0 then ( print_string " *** unknown opcode : " ; print_int op ) else print_string names_of_instructions ...
let print_code ic len = start := pos_in ic ; let stop = ! start + len in while pos_in ic < stop do print_instr ic done
let print_reloc ( info , pos ) = printf " % d ( % d ) " pos ( pos / 4 ) ; match info with Reloc_literal sc -> print_struct_const sc ; printf " \ n " | Reloc_getglobal id -> printf " require % s \ n " ( Ident . name id ) | Reloc_setglobal id -> printf " provide % s \ n " ( Ident . name id ) | Reloc_primitive s -> printf...
let dump_obj filename ic = let buffer = String . create ( String . length cmo_magic_number ) in really_input ic buffer 0 ( String . length cmo_magic_number ) ; if buffer <> cmo_magic_number then begin prerr_endline " Not an object file " ; exit 2 end ; let cu_pos = input_binary_int ic in seek_in ic cu_pos ; let cu = ( ...
let read_primitive_table ic len = let p = String . create len in really_input ic p 0 len ; let rec split beg cur = if cur >= len then [ ] else if p . [ cur ] = ' \ 000 ' then String . sub p beg ( cur - beg ) :: split ( cur + 1 ) ( cur + 1 ) else split beg ( cur + 1 ) in Array . of_list ( split 0 0 )
let dump_exe ic = Bytesections . read_toc ic ; let prim_size = Bytesections . seek_section ic " PRIM " in primitives := read_primitive_table ic prim_size ; ignore ( Bytesections . seek_section ic " DATA " ) ; let init_data = ( input_value ic : Obj . t array ) in globals := Array . create ( Array . length init_data ) Em...
let main ( ) = for i = 1 to Array . length Sys . argv - 1 do let filnam = Sys . argv . ( i ) in let ic = open_in_bin filnam in if i > 1 then print_newline ( ) ; printf " ## start of ocaml dump of % S \ n " %! filnam ; begin try objfile := false ; dump_exe ic with Bytesections . Bad_magic_number -> objfile := true ; see...
let _ = main ( )
module Id : Sig . Id = struct value name = " Camlp4Printers . DumpOCamlAst " ; value version = Sys . ocaml_version ; end ;
module Make ( Syntax : Sig . Camlp4Syntax ) include Syntax ; module Ast2pt = Struct . Camlp4Ast2OCamlAst . Make Ast ; value with_open_out_file x f = match x with [ Some file -> do { let oc = open_out_bin file ; f oc ; flush oc ; close_out oc } | None -> do { set_binary_mode_out stdout True ; f stdout ; flush stdout } ]...
let ( ** ) = Int64 . mul
type nonrec t = t
let compare_zero ( f : int -> int -> _ ) a b = f ( compare a b ) 0 [ @@ inlined ]
let ( + ) = Mtime . Span . add
let ( < ) = compare_zero ( < )
let ( <= ) = compare_zero ( <= )
let ( = ) = compare_zero ( = )
let ( >= ) = compare_zero ( >= )
let ( > ) = compare_zero ( > )
let zero = v 0L
let nanosecond = v 1L
let microsecond = v 1_000L
let millisecond = v 1_000_000L
let second = v 1_000_000_000L
let minute = v ( 60L ** 1_000_000_000L )
let hour = v ( 60L ** 60L ** 1_000_000_000_000L )
let day = v ( 24L ** 60L ** 60L ** 1_000_000_000_000L )
let of_ns x = v ( Int64 . of_float x )
let of_us x = v ( Int64 . of_float ( x . * 1e3 ) )
let of_ms x = v ( Int64 . of_float ( x . * 1e6 ) )
let of_sec x = v ( Int64 . of_float ( x . * 1e9 ) )
let of_int64_ms x = v ( x ** 1_000_000L )
let of_int_ms x = of_int64_ms ( Int64 . of_int x )
let of_int64_sec x = v ( x ** 1_000_000_000L )
let of_int_sec x = of_int64_sec ( Int64 . of_int x )
let of_min = let f = 60 . . * 1e9 in fun x -> v ( Int64 . of_float ( x . * f ) )
let of_int64_min = let f = 60L ** 1_000_000_000L in fun x -> v ( x ** f )
let of_int_min x = of_int64_min ( Int64 . of_int x )
let of_hour = let f = 60 . . * 60 . . * 1e9 in fun x -> v ( Int64 . of_float ( x . * f ) )
let of_int64_hour = let f = 60L ** 60L ** 1_000_000_000L in fun x -> v ( x ** f )
let of_int_hour x = of_int64_hour ( Int64 . of_int x )
let of_day = let f = 24 . . * 60 . . * 60 . . * 1e9 in fun x -> v ( Int64 . of_float ( x . * f ) )
module Of_int = struct let ms = of_int_ms let sec = of_int_sec let min = of_int_min let hour = of_int_hour let ( + ) = ( + ) end
type t = { state : DS . t ; asm_directives : ( module Asm_directives . S ) ; get_file_id : string -> int ; mutable emitted : bool }
let create ~ sourcefile ~ unit_name ~ asm_directives ~ get_file_id = begin match ! Dwarf_flags . gdwarf_format with | Thirty_two -> Dwarf_format . set Thirty_two | Sixty_four -> Dwarf_format . set Sixty_four end ; let compilation_unit_proto_die = Dwarf_compilation_unit . compile_unit_proto_die ~ sourcefile ~ unit_name ...
let dwarf_for_fundecl t fundecl = Dwarf_concrete_instances . for_fundecl ~ get_file_id : t . get_file_id t . state fundecl
let emit t = if t . emitted then Misc . fatal_error " Cannot call [ Dwarf . emit ] more than once on a given value of type \ [ Dwarf . t ] " ; t . emitted <- true ; Dwarf_world . emit ~ asm_directives : t . asm_directives ~ compilation_unit_proto_die ( : DS . compilation_unit_proto_die t . state ) ~ compilation_unit_he...
let emit t = Profile . record " emit_dwarf " emit t
type t = { name : Asm_label . t ; entries : Dwarf_4_location_list_entry . t list }
let sort entries = List . sort Dwarf_4_location_list_entry . compare_ascending_vma entries
let create ~ location_list_entries = { name = Asm_label . create ( DWARF Debug_loc ) ; entries = sort location_list_entries }
let label t = t . name
let end_marker ( ) = Dwarf_value . absolute_address ~ comment " : end marker " Targetint . zero
let size t = let ( + ) = Dwarf_int . add in let body_size = List . fold_left ( fun size entry -> size + Dwarf_4_location_list_entry . size entry ) ( Dwarf_int . zero ( ) ) t . entries in let end_marker = end_marker ( ) in body_size + Dwarf_value . size end_marker + Dwarf_value . size end_marker
let compare_increasing_vma t1 t2 = match t1 . entries , t2 . entries with | t1_entry :: _ , t2_entry :: _ -> Dwarf_4_location_list_entry . compare_ascending_vma t1_entry t2_entry | _ -> failwith " Location_list . compare on empty location list ( s ) "
let emit ~ asm_directives t = let module A = ( val asm_directives : Asm_directives . S ) in A . new_line ( ) ; A . comment " Location list " ; : A . define_label t . name ; List . iter ( fun entry -> Dwarf_4_location_list_entry . emit ~ asm_directives entry ) t . entries ; let end_marker = end_marker ( ) in Dwarf_value...
module Location_list_entry = struct type t = { start_of_code_symbol : Asm_symbol . t ; beginning_address_label : Asm_label . t ; beginning_address_offset : int option ; ending_address_label : Asm_label . t ; ending_address_offset : int option ; expr : Single_location_description . t } let create ~ start_of_code_symbol ...
module Base_address_selection_entry = struct type t = Asm_symbol . t let create ~ base_address_symbol = base_address_symbol let to_dwarf_values t = [ Dwarf_value . absolute_address ~ comment " : largest representable addr . offset " Targetint . minus_one ; Dwarf_value . code_address_from_symbol ~ comment " : base addre...
type t = | Location_list_entry of Location_list_entry . t | Base_address_selection_entry of Base_address_selection_entry . t
let create_location_list_entry ~ start_of_code_symbol ~ first_address_when_in_scope ~ first_address_when_in_scope_offset ~ first_address_when_not_in_scope ~ first_address_when_not_in_scope_offset ~ single_location_description = Location_list_entry ( Location_list_entry . create ~ start_of_code_symbol ~ first_address_wh...
let create_base_address_selection_entry ~ base_address_symbol = Base_address_selection_entry ( Base_address_selection_entry . create ~ base_address_symbol )
let size = function | Location_list_entry entry -> Location_list_entry . size entry | Base_address_selection_entry entry -> Base_address_selection_entry . size entry