text
stringlengths
12
786k
let ( ) ++ x f = f x
let compile_fundecl ~ ppf_dump fd_cmm = Proc . init ( ) ; Reg . reset ( ) ; fd_cmm ++ Profile . record ~ accumulate : true " cmm_invariants " ( cmm_invariants ppf_dump ) ++ Profile . record ~ accumulate : true " selection " Selection . fundecl ++ pass_dump_if ppf_dump dump_sel...
let compile_data dl = dl ++ save_data ++ emit_data
let compile_phrase ~ ppf_dump p = if ! dump_cmm then fprintf ppf_dump " % a . " @ Printcmm . phrase p ; match p with | Cfunction fd -> compile_fundecl ~ ppf_dump fd | Cdata dl -> compile_data dl
let compile_genfuns ~ ppf_dump f = List . iter ( function | ( Cfunction { fun_name = name } ) as ph when f name -> compile_phrase ~ ppf_dump ph | _ -> ( ) ) ( Cmm_helpers . generic_functions true [ Compilenv . current_unit_infos ( ) ] )
let compile_unit ~ output_prefix ~ asm_filename ~ keep_asm ~ obj_filename gen = reset ( ) ; let create_asm = should_emit ( ) && ( keep_asm || not ! Emitaux . binary_backend_available ) in Emitaux . create_asm_file := create_asm ; Misc . try_finally ~ exceptionally ( : fun ( ) ->...
let end_gen_implementation ? toplevel ~ ppf_dump ( clambda : Clambda . with_constants ) = emit_begin_assembly ( ) ; clambda ++ Profile . record " cmm " Cmmgen . compunit ++ Profile . record " compile_phrases " ( List . iter ( compile_phrase ~ ppf_dump ) ) ++ ( fun ( ) ...
type middle_end = backend ( : module Backend_intf . S ) -> filename : string -> prefixname : string -> ppf_dump : Format . formatter -> Lambda . program -> Clambda . with_constants
let asm_filename output_prefix = if ! keep_asm_file || ! Emitaux . binary_backend_available then output_prefix ^ ext_asm else Filename . temp_file " camlasm " ext_asm
let compile_implementation ? toplevel ~ backend ~ filename ~ prefixname ~ middle_end ~ ppf_dump ( program : Lambda . program ) = compile_unit ~ output_prefix : prefixname ~ asm_filename ( : asm_filename prefixname ) ~ keep_asm :! keep_asm_file ~ obj_filename ( : prefixname ^ ext_obj ) ( ...
let linear_gen_implementation filename = let open Linear_format in let linear_unit_info , _ = restore filename in ( match ! Clflags . for_package , linear_unit_info . for_pack with | None , None -> ( ) | Some expected , Some saved when String . equal expected saved -> ( ) | _ , saved...
let compile_implementation_linear output_prefix ~ progname = compile_unit ~ output_prefix ~ asm_filename ( : asm_filename output_prefix ) ~ keep_asm :! keep_asm_file ~ obj_filename ( : output_prefix ^ ext_obj ) ( fun ( ) -> linear_gen_implementation progname )
let report_error ppf = function | Assembler_error file -> fprintf ppf " Assembler error , input left in file % a " Location . print_filename file | Mismatched_for_pack saved -> let msg = function | None -> " without - for - pack " | Some s -> " with - for - pack " ^ s in fprintf ppf " ...
let ( ) = Location . register_error_of_exn ( function | Error err -> Some ( Location . error_of_printer_file report_error err ) | _ -> None )
type error = File_not_found of string | Archiver_error of string
let default_ui_export_info = if Config . flambda then Cmx_format . Flambda Export_info . empty else Cmx_format . Clambda Clambda . Value_unknown
let read_info name = let filename = try Load_path . find name with Not_found -> raise ( Error ( File_not_found name ) ) in let ( info , crc ) = Compilenv . read_unit_info filename in info . ui_force_link <- info . ui_force_link || ! Clflags . link_everything ; info . ui_export_info <...
let create_archive file_list lib_name = let archive_name = Filename . remove_extension lib_name ^ ext_lib in let outchan = open_out_bin lib_name in Misc . try_finally ~ always ( : fun ( ) -> close_out outchan ) ~ exceptionally ( : fun ( ) -> remove_file lib_name ; remove_file archive_name ...
let report_error ppf = function | File_not_found name -> fprintf ppf " Cannot find file % s " name | Archiver_error name -> fprintf ppf " Error while creating the library % s " name
let ( ) = Location . register_error_of_exn ( function | Error err -> Some ( Location . error_of_printer_file report_error err ) | _ -> None )
type error = | File_not_found of filepath | Not_an_object_file of filepath | Missing_implementations of ( modname * string list ) list | Inconsistent_interface of modname * filepath * filepath | Inconsistent_implementation of modname * filepath * filepath | Assembler_error of filepath | Linking_error o...
module Cmi_consistbl = Consistbl . Make ( Misc . Stdlib . String )
let crc_interfaces = Cmi_consistbl . create ( )
let interfaces = ref ( [ ] : string list )
module Cmx_consistbl = Consistbl . Make ( Misc . Stdlib . String )
let crc_implementations = Cmx_consistbl . create ( )
let implementations = ref ( [ ] : string list )
let implementations_defined = ref ( [ ] : ( string * string ) list )
let cmx_required = ref ( [ ] : string list )
let check_consistency file_name unit crc = begin try List . iter ( fun ( name , crco ) -> interfaces := name :: ! interfaces ; match crco with None -> ( ) | Some crc -> if name = unit . ui_name then Cmi_consistbl . set crc_interfaces name crc file_name else Cmi_consistbl . check crc_inter...
let extract_crc_interfaces ( ) = Cmi_consistbl . extract ! interfaces crc_interfaces
let extract_crc_implementations ( ) = Cmx_consistbl . extract ! implementations crc_implementations
let lib_ccobjs = ref [ ]
let lib_ccopts = ref [ ]
let add_ccobjs origin l = if not ! Clflags . no_auto_link then begin lib_ccobjs := l . lib_ccobjs @ ! lib_ccobjs ; let replace_origin = Misc . replace_substring ~ before " :$ CAMLORIGIN " ~ after : origin in lib_ccopts := List . map replace_origin l . lib_ccopts @ ! lib_ccopts end
let runtime_lib ( ) = let libname = " libasmrun " ^ ! Clflags . runtime_variant ^ ext_lib in try if ! Clflags . nopervasives || not ! Clflags . with_runtime then [ ] else [ Load_path . find libname ] with Not_found -> raise ( Error ( File_not_found libname ) )
let missing_globals = ( Hashtbl . create 17 : ( string , string list ref ) Hashtbl . t )
let is_required name = try ignore ( Hashtbl . find missing_globals name ) ; true with Not_found -> false
let add_required by ( name , _crc ) = try let rq = Hashtbl . find missing_globals name in rq := by :: ! rq with Not_found -> Hashtbl . add missing_globals name ( ref [ by ] )
let remove_required name = Hashtbl . remove missing_globals name
let extract_missing_globals ( ) = let mg = ref [ ] in Hashtbl . iter ( fun md rq -> mg := ( md , ! rq ) :: ! mg ) missing_globals ; ! mg
type file = | Unit of string * unit_infos * Digest . t | Library of string * library_infos
let object_file_name_of_file = function | Unit ( fname , _ , _ ) -> Some ( Filename . chop_suffix fname " . cmx " ^ ext_obj ) | Library ( fname , infos ) -> let obj_file = Filename . chop_suffix fname " . cmxa " ^ ext_lib in if infos . lib_units = [ ] && not ( Sys ....
let read_file obj_name = let file_name = try Load_path . find obj_name with Not_found -> raise ( Error ( File_not_found obj_name ) ) in if Filename . check_suffix file_name " . cmx " then begin let ( info , crc ) = read_unit_info file_name in Unit ( file_name , info , crc ) end else ...
let scan_file file tolink = match file with | Unit ( file_name , info , crc ) -> remove_required info . ui_name ; List . iter ( add_required file_name ) info . ui_imports_cmx ; ( info , file_name , crc ) :: tolink | Library ( file_name , infos ) -> add_ccobjs ( Filename . d...
let force_linking_of_startup ~ ppf_dump = Asmgen . compile_phrase ~ ppf_dump ( Cmm . Cdata ( [ Cmm . Csymbol_address " caml_startup " ] ) )
let make_globals_map units_list ~ crc_interfaces = let crc_interfaces = String . Tbl . of_seq ( List . to_seq crc_interfaces ) in let defined = List . map ( fun ( unit , _ , impl_crc ) -> let intf_crc = String . Tbl . find crc_interfaces unit . ui_name in String . Tbl . remove crc...
let make_startup_file ~ ppf_dump units_list ~ crc_interfaces = let compile_phrase p = Asmgen . compile_phrase ~ ppf_dump p in Location . input_name := " caml_startup " ; Compilenv . reset " _startup " ; Emit . begin_assembly ( ) ; let name_list = List . flatten ( List . map ( f...
let make_shared_startup_file ~ ppf_dump units = let compile_phrase p = Asmgen . compile_phrase ~ ppf_dump p in Location . input_name := " caml_startup " ; Compilenv . reset " _shared_startup " ; Emit . begin_assembly ( ) ; List . iter compile_phrase ( Cmm_helpers . generic_function...
let call_linker_shared file_list output_name = let exitcode = Ccomp . call_linker Ccomp . Dll output_name file_list " " in if not ( exitcode = 0 ) then raise ( Error ( Linking_error exitcode ) )
let link_shared ~ ppf_dump objfiles output_name = Profile . record_call output_name ( fun ( ) -> let obj_infos = List . map read_file objfiles in let units_tolink = List . fold_right scan_file obj_infos [ ] in List . iter ( fun ( info , file_name , crc ) -> check_consistency file_name ...
let call_linker file_list startup_file output_name = let main_dll = ! Clflags . output_c_object && Filename . check_suffix output_name Config . ext_dll and main_obj_runtime = ! Clflags . output_complete_object in let files = startup_file :: ( List . rev file_list ) in let files , c_lib = if ( ...
let link ~ ppf_dump objfiles output_name = Profile . record_call output_name ( fun ( ) -> let stdlib = " stdlib . cmxa " in let stdexit = " std_exit . cmx " in let objfiles = if ! Clflags . nopervasives then objfiles else if ! Clflags . output_c_object then stdlib :: objfiles else stdli...
let report_error ppf = function | File_not_found name -> fprintf ppf " Cannot find file % s " name | Not_an_object_file name -> fprintf ppf " The file % a is not a compilation unit description " Location . print_filename name | Missing_implementations l -> let print_references ppf = function | [ ...
let ( ) = Location . register_error_of_exn ( function | Error err -> Some ( Location . error_of_printer_file report_error err ) | _ -> None )
let reset ( ) = Cmi_consistbl . clear crc_interfaces ; Cmx_consistbl . clear crc_implementations ; implementations_defined := [ ] ; cmx_required := [ ] ; interfaces := [ ] ; implementations := [ ] ; lib_ccobjs := [ ] ; lib_ccopts := [ ]
type error = Illegal_renaming of string * string * string | Forward_reference of string * string | Wrong_for_pack of string * string | Linking_error | Assembler_error of string | File_not_found of string
type pack_member_kind = PM_intf | PM_impl of unit_infos
type pack_member = { pm_file : string ; pm_name : string ; pm_kind : pack_member_kind }
let read_member_info pack_path file = ( let name = String . capitalize_ascii ( Filename . basename ( chop_extensions file ) ) in let kind = if Filename . check_suffix file " . cmi " then PM_intf else begin let ( info , crc ) = Compilenv . read_unit_info file in if info . ui_name <> ...
let check_units members = let rec check forbidden = function [ ] -> ( ) | mb :: tl -> begin match mb . pm_kind with | PM_intf -> ( ) | PM_impl infos -> List . iter ( fun ( unit , _ ) -> if List . mem unit forbidden then raise ( Error ( Forward_reference ( mb . pm_file , u...
let make_package_object ~ ppf_dump members targetobj targetname coercion ~ backend = Profile . record_call ( Printf . sprintf " pack ( % s ) " targetname ) ( fun ( ) -> let objtemp = if ! Clflags . keep_asm_file then Filename . remove_extension targetobj ^ " . pack " ^ Config . ...
let get_export_info ui = assert ( Config . flambda ) ; match ui . ui_export_info with | Clambda _ -> assert false | Flambda info -> info
let get_approx ui = assert ( not Config . flambda ) ; match ui . ui_export_info with | Flambda _ -> assert false | Clambda info -> info
let build_package_cmx members cmxfile = let unit_names = List . map ( fun m -> m . pm_name ) members in let filter lst = List . filter ( fun ( name , _crc ) -> not ( List . mem name unit_names ) ) lst in let union lst = List . fold_left ( List . fold_left ( fun accu n -> if Lis...
let package_object_files ~ ppf_dump files targetcmx targetobj targetname coercion ~ backend = let pack_path = match ! Clflags . for_package with | None -> targetname | Some p -> p ^ " . " ^ targetname in let members = map_left_right ( read_member_info pack_path ) files in check_units members ; ...
let package_files ~ ppf_dump initial_env files targetcmx ~ backend = let files = List . map ( fun f -> try Load_path . find f with Not_found -> raise ( Error ( File_not_found f ) ) ) files in let prefix = chop_extensions targetcmx in let targetcmi = prefix ^ " . cmi " in let targetobj = ...
let report_error ppf = function Illegal_renaming ( name , file , id ) -> fprintf ppf " Wrong file naming : % a @ contains the code for \ @ % s when % s was expected " Location . print_filename file name id | Forward_reference ( file , ident ) -> fprintf ppf " Forward reference to % s i...
let ( ) = Location . register_error_of_exn ( function | Error err -> Some ( Location . error_of_printer_file report_error err ) | _ -> None )
module type S = Asm_directives_intf . S
module type Arg = Asm_directives_intf . Arg
module Cached_string = struct type t = { section : Asm_section . t ; str : string ; comment : string option } include Identifiable . Make ( struct type nonrec t = t let compare { section = section1 ; str = str1 ; comment = comment1 } { section = section2 ; str = str2 ; comment = ...
module Make ( A : Asm_directives_intf . Arg ) : Asm_directives_intf . S = struct module Int8 = Numbers . Int8 module Int16 = Numbers . Int16 module Uint8 = Numbers . Uint8 module Uint16 = Numbers . Uint16 module Uint32 = Numbers . Uint32 module Uint64 = Numbers . Uint64 module D = A . D ...
module type Arg = sig val emit_line : string -> unit val get_file_num : string -> int module D : sig type constant val const_int64 : int64 -> constant val const_label : string -> constant val const_add : constant -> constant -> constant val const_sub : constant -> constant -> constant type data_type = ...
module type S = sig val switch_to_section : Asm_section . t -> unit val initialize : unit -> unit val int8 : ? comment : string -> Numbers . Int8 . t -> unit val int16 : ? comment : string -> Numbers . Int16 . t -> unit val int32 : ? comment : string -> Int32 . t -> unit val int64 : ? ...
type label = | Int of int | String of string
type t = { section : Asm_section . t ; label : label } type nonrec t = t let compare t1 t2 = Stdlib . compare t1 . label t2 . label let equal t1 t2 = compare t1 t2 = 0 let hash t = Hashtbl . hash t . label let print ppf t = match t . label with | Int i -> Format . fprintf ppf " L % ...
let create_int section label = assert ( label >= 0 ) ; { section ; label = Int label }
let contains_escapable_char label = let found_escapable_char = ref false in String . iter ( fun c -> if Asm_symbol . should_be_escaped c then found_escapable_char := true ) label ; ! found_escapable_char
let create_string section label = assert ( not ( contains_escapable_char label ) ) ; { section ; label = String label }
let label_prefix = match Target_system . assembler ( ) with MacOS -> " L " | MASM | GAS_like -> " . L "
let encode ( t : t ) = match t . label with | Int label -> label_prefix ^ string_of_int label | String label -> label_prefix ^ label
let section t = t . section
let new_label_ref = ref ( fun _section -> Misc . fatal_error " [ Asm_label . initialize ] has not been called " )
let initialize ~ new_label = new_label_ref := fun section -> create_int section ( new_label ( ) )
let create ( section : Asm_section . t ) = ! new_label_ref section
let debug_info_label = lazy ( create ( DWARF Debug_info ) )
let debug_abbrev_label = lazy ( create ( DWARF Debug_abbrev ) )
let debug_aranges_label = lazy ( create ( DWARF Debug_aranges ) )
let debug_addr_label = lazy ( create ( DWARF Debug_addr ) )
let debug_loc_label = lazy ( create ( DWARF Debug_loc ) )
let debug_ranges_label = lazy ( create ( DWARF Debug_ranges ) )
let debug_loclists_label = lazy ( create ( DWARF Debug_loclists ) )
let debug_rnglists_label = lazy ( create ( DWARF Debug_rnglists ) )
let debug_str_label = lazy ( create ( DWARF Debug_str ) )
let debug_line_label = lazy ( create ( DWARF Debug_line ) )
let for_dwarf_section ( dwarf_section : Asm_section . dwarf_section ) = match dwarf_section with | Debug_info -> Lazy . force debug_info_label | Debug_abbrev -> Lazy . force debug_abbrev_label | Debug_aranges -> Lazy . force debug_aranges_label | Debug_addr -> Lazy . force debug_addr_label | De...
let for_section ( section : Asm_section . t ) = match section with DWARF dwarf_section -> for_dwarf_section dwarf_section
type dwarf_section = | Debug_info | Debug_abbrev | Debug_aranges | Debug_addr | Debug_loc | Debug_ranges | Debug_loclists | Debug_rnglists | Debug_str | Debug_line
type t = DWARF of dwarf_section