text stringlengths 12 786k |
|---|
let print_standard_library ( ) = print_string Config . standard_library ; print_newline ( ) ; raise ( Exit_with_status 0 ) |
let fatal err = prerr_endline err ; raise ( Exit_with_status 2 ) |
let extract_output = function | Some s -> s | None -> fatal " Please specify the name of the output file , using option - o " |
let default_output = function | Some s -> s | None -> Config . default_executable_name |
let first_include_dirs = ref [ ] |
let last_include_dirs = ref [ ] |
let first_ccopts = ref [ ] |
let last_ccopts = ref [ ] |
let first_ppx = ref [ ] |
let last_ppx = ref [ ] |
let first_objfiles = ref [ ] |
let last_objfiles = ref [ ] |
let stop_early = ref false |
let is_unit_name name = try if name = " " then raise Exit ; begin match name . [ 0 ] with | ' A ' . . ' Z ' -> ( ) | _ -> raise Exit ; end ; for i = 1 to String . length name - 1 do match name . [ i ] with | ' A ' . . ' Z ' | ' a ' . . ' z ' ... |
let check_unit_name filename name = if not ( is_unit_name name ) then Location . prerr_warning ( Location . in_file filename ) ( Warnings . Bad_module_name name ) ; ; |
let module_of_filename inputfile outputprefix = let basename = Filename . basename outputprefix in let name = try let pos = String . index basename ' . ' in String . sub basename 0 pos with Not_found -> basename in let name = String . capitalize_ascii name in check_unit_name inputfile name ; name... |
type readenv_position = Before_args | Before_compile of filename | Before_link |
let print_error ppf msg = Location . print_warning Location . none ppf ( Warnings . Bad_env_variable ( " OCAMLPARAM " , msg ) ) |
let parse_args s = let args = let len = String . length s in if len = 0 then [ ] else match s . [ 0 ] with | ( ' ' : | ' ' | | ' ; ' | ' ' | ' , ' ) as c -> List . tl ( String . split_on_char c s ) | _ -> String . split_on_char ' , ' s in let rec ... |
let setter ppf f name options s = try let bool = match s with | " 0 " -> false | " 1 " -> true | _ -> raise Not_found in List . iter ( fun b -> b := f bool ) options with Not_found -> Printf . ksprintf ( print_error ppf ) " bad value % s for % s " s name |
let int_setter ppf name option s = try option := int_of_string s with _ -> Printf . ksprintf ( print_error ppf ) " non - integer parameter % s for % S " s name |
let int_option_setter ppf name option s = try option := Some ( int_of_string s ) with _ -> Printf . ksprintf ( print_error ppf ) " non - integer parameter % s for % S " s name |
let check_bool ppf name s = match s with | " 0 " -> false | " 1 " -> true | _ -> Printf . ksprintf ( print_error ppf ) " bad value % s for % s " s name ; false |
let check_int ppf name s = match int_of_string s with | i -> Some i | exception _ -> Printf . ksprintf ( print_error ppf ) " bad value % s for % s " s name ; None |
let decode_compiler_pass ppf v ~ name ~ filter = let module P = Clflags . Compiler_pass in let passes = P . available_pass_names ~ filter ~ native :! native_code in begin match List . find_opt ( String . equal v ) passes with | None -> Printf . ksprintf ( print_error ppf ) " bad value % s... |
let set_compiler_pass ppf ~ name v flag ~ filter = match decode_compiler_pass ppf v ~ name ~ filter with | None -> ( ) | Some pass -> match ! flag with | None -> flag := Some pass | Some p -> if not ( p = pass ) then begin Printf . ksprintf ( print_error ppf ) " Please specify at most on... |
let can_discard = ref [ ] |
let warnings_for_discarded_params = ref false |
let extra_params = ref None |
let set_extra_params params = extra_params := params |
let read_one_param ppf position name v = let set name options s = setter ppf ( fun b -> b ) name options s in let clear name options s = setter ppf ( fun b -> not b ) name options s in let handled = match ! extra_params with | Some h -> h ppf position name v | None -> false in if not handled then mat... |
let read_OCAMLPARAM ppf position = try let s = Sys . getenv " OCAMLPARAM " in if s <> " " then let ( before , after ) = try parse_args s with SyntaxError s -> print_error ppf s ; [ ] , [ ] in List . iter ( fun ( name , v ) -> read_one_param ppf position name v ) ( match p... |
type pattern = | Filename of string | Any |
type file_option = { pattern : pattern ; name : string ; value : string ; } |
let scan_line ic = Scanf . bscanf ic " [ % 0 - 9a - zA - Z_ . ] * : [ % a - zA - Z_ ] - = % s " ( fun pattern name value -> let pattern = match pattern with | " " * -> Any | _ -> Filename pattern in { pattern ; name ; value } ) |
let load_config ppf filename = match open_in_bin filename with | exception e -> Location . errorf ~ loc ( : Location . in_file filename ) " Cannot open file % s " ( Printexc . to_string e ) |> Location . print_report ppf ; raise Exit | ic -> let sic = Scanf . Scanning . from_channel ... |
let matching_filename filename { pattern } = match pattern with | Any -> true | Filename pattern -> let filename = String . lowercase_ascii filename in let pattern = String . lowercase_ascii pattern in filename = pattern |
let apply_config_file ppf position = let config_file = Filename . concat Config . standard_library " ocaml_compiler_internal_params " in let config = if Sys . file_exists config_file then load_config ppf config_file else [ ] in let config = match position with | Before_compile filename -> List . f... |
let readenv ppf position = last_include_dirs := [ ] ; last_ccopts := [ ] ; last_ppx := [ ] ; last_objfiles := [ ] ; apply_config_file ppf position ; read_OCAMLPARAM ppf position ; all_ccopts := ! last_ccopts @ ! first_ccopts ; all_ppx := ! last_ppx @ ! first_ppx |
let get_objfiles ~ with_ocamlparam = if with_ocamlparam then List . rev ( ! last_objfiles @ ! objfiles @ ! first_objfiles ) else List . rev ! objfiles |
type deferred_action = | ProcessImplementation of string | ProcessInterface of string | ProcessCFile of string | ProcessOtherFile of string | ProcessObjects of string list | ProcessDLLs of string list |
let c_object_of_filename name = Filename . chop_suffix ( Filename . basename name ) " . c " ^ Config . ext_obj |
let process_action ( ppf , implementation , interface , ocaml_mod_ext , ocaml_lib_ext ) action ~ keep_symbol_tables = let impl ~ start_from name = readenv ppf ( Before_compile name ) ; let opref = output_prefix name in implementation ~ start_from ~ source_file : name ~ output_prefix : opref ... |
let action_of_file name = if Filename . check_suffix name " . ml " || Filename . check_suffix name " . mlt " then ProcessImplementation name else if Filename . check_suffix name ! Config . interface_suffix then ProcessInterface name else if Filename . check_suffix name " . c " then Proces... |
let deferred_actions = ref [ ] |
let defer action = deferred_actions := action :: ! deferred_actions |
let anonymous filename = defer ( action_of_file filename ) |
let impl filename = defer ( ProcessImplementation filename ) |
let intf filename = defer ( ProcessInterface filename ) |
let process_deferred_actions env = let final_output_name = ! output_name in if not ! compile_only then output_name := None ; begin match final_output_name with | None -> ( ) | Some output_name -> if ! compile_only then begin if List . filter ( function | ProcessCFile name -> c_object_of_filename n... |
type t = { id : Ident . t ; linkage_name : Linkage_name . t ; hash : int ; } |
let string_for_printing t = Ident . name t . id type nonrec t = t let compare v1 v2 = if v1 == v2 then 0 else let c = compare v1 . hash v2 . hash in if c = 0 then let v1_id = Ident . name v1 . id in let v2_id = Ident . name v2 . id in let c = String . compare v1_id v2_id in if c = 0 then ... |
let create ( id : Ident . t ) linkage_name = if not ( Ident . persistent id ) then begin Misc . fatal_error " Compilation_unit . create with non - persistent Ident . t " end ; { id ; linkage_name ; hash = Hashtbl . hash ( Ident . name id ) ; } |
let get_persistent_ident cu = cu . id |
let get_linkage_name cu = cu . linkage_name |
let current = ref None |
let is_current arg = match ! current with | None -> Misc . fatal_error " Current compilation unit is not set " ! | Some cur -> equal cur arg |
let set_current t = current := Some t |
let get_current ( ) = ! current |
let get_current_exn ( ) = match ! current with | Some current -> current | None -> Misc . fatal_error " Compilation_unit . get_current_exn " |
let get_current_id_exn ( ) = get_persistent_ident ( get_current_exn ( ) ) |
let with_info = Compile_common . with_info ~ native : false ~ tool_name |
let interface ~ source_file ~ output_prefix = with_info ~ source_file ~ output_prefix ~ dump_ext " : cmi " @@ fun info -> Compile_common . interface ~ hook_parse_tree ( : fun _ -> ( ) ) ~ hook_typed_tree ( : fun _ -> ( ) ) info |
let to_bytecode i ( typedtree , coercion ) = ( typedtree , coercion ) |> Profile . ( record transl ) ( Translmod . transl_implementation i . module_name ) |> Profile . ( record ~ accumulate : true generate ) ( fun { Lambda . code = lambda ; required_globals } -> lambda ... |
let emit_bytecode i ( bytecode , required_globals ) = let cmofile = cmo i in let oc = open_out_bin cmofile in Misc . try_finally ~ always ( : fun ( ) -> close_out oc ) ~ exceptionally ( : fun ( ) -> Misc . remove_file cmofile ) ( fun ( ) -> bytecode |> Profile . ( record ... |
let implementation ~ start_from ~ source_file ~ output_prefix ~ keep_symbol_tables : _ = let backend info typed = let bytecode = to_bytecode info typed in emit_bytecode info bytecode in with_info ~ source_file ~ output_prefix ~ dump_ext " : cmo " @@ fun info -> match ( start_from : Clflags . Com... |
type error = Not_a_unit_info of string | Corrupted_unit_info of string | Illegal_renaming of string * string * string |
let global_infos_table = ( Hashtbl . create 17 : ( string , unit_infos option ) Hashtbl . t ) |
let export_infos_table = ( Hashtbl . create 10 : ( string , Export_info . t ) Hashtbl . t ) |
let imported_sets_of_closures_table = ( Set_of_closures_id . Tbl . create 10 : Simple_value_approx . function_declarations option Set_of_closures_id . Tbl . t ) |
module CstMap = Map . Make ( struct type t = Clambda . ustructured_constant let compare = Clambda . compare_structured_constants end ) |
type structured_constants = { strcst_shared : string CstMap . t ; strcst_all : Clambda . ustructured_constant SymMap . t ; } |
let structured_constants_empty = { strcst_shared = CstMap . empty ; strcst_all = SymMap . empty ; } |
let structured_constants = ref structured_constants_empty |
let exported_constants = Hashtbl . create 17 |
let merged_environment = ref Export_info . empty |
let default_ui_export_info = if Config . flambda then Cmx_format . Flambda Export_info . empty else Cmx_format . Clambda Value_unknown |
let current_unit = { ui_name = " " ; ui_symbol = " " ; ui_defines = [ ] ; ui_imports_cmi = [ ] ; ui_imports_cmx = [ ] ; ui_curry_fun = [ ] ; ui_apply_fun = [ ] ; ui_send_fun = [ ] ; ui_force_link = false ; ui_export_info = default_ui_export_info } |
let symbolname_for_pack pack name = match pack with | None -> name | Some p -> let b = Buffer . create 64 in for i = 0 to String . length p - 1 do match p . [ i ] with | ' . ' -> Buffer . add_string b " __ " | c -> Buffer . add_char b c done ; Buffer . add_string b " __ " ... |
let unit_id_from_name name = Ident . create_persistent name |
let concat_symbol unitname id = unitname ^ " __ " ^ id |
let make_symbol ( ? unitname = current_unit . ui_symbol ) idopt = let prefix = " caml " ^ unitname in match idopt with | None -> prefix | Some id -> concat_symbol prefix id |
let current_unit_linkage_name ( ) = Linkage_name . create ( make_symbol ~ unitname : current_unit . ui_symbol None ) |
let reset ? packname name = Hashtbl . clear global_infos_table ; Set_of_closures_id . Tbl . clear imported_sets_of_closures_table ; let symbol = symbolname_for_pack packname name in current_unit . ui_name <- name ; current_unit . ui_symbol <- symbol ; current_unit . ui_defines <- [ symbol ] ... |
let current_unit_infos ( ) = current_unit |
let current_unit_name ( ) = current_unit . ui_name |
let symbol_in_current_unit name = let prefix = " caml " ^ current_unit . ui_symbol in name = prefix || ( let lp = String . length prefix in String . length name >= 2 + lp && String . sub name 0 lp = prefix && name . [ lp ] = ' _ ' && name . [ lp + 1 ] = ' _ ' ) |
let read_unit_info filename = let ic = open_in_bin filename in try let buffer = really_input_string ic ( String . length cmx_magic_number ) in if buffer <> cmx_magic_number then begin close_in ic ; raise ( Error ( Not_a_unit_info filename ) ) end ; let ui = ( input_value ic : unit_infos ) in... |
let read_library_info filename = let ic = open_in_bin filename in let buffer = really_input_string ic ( String . length cmxa_magic_number ) in if buffer <> cmxa_magic_number then raise ( Error ( Not_a_unit_info filename ) ) ; let infos = ( input_value ic : library_infos ) in close_in ic ; in... |
let get_global_info global_ident = ( let modname = Ident . name global_ident in if modname = current_unit . ui_name then Some current_unit else begin try Hashtbl . find global_infos_table modname with Not_found -> let ( infos , crc ) = if Env . is_imported_opaque modname then ( None , None ) ... |
let cache_unit_info ui = Hashtbl . add global_infos_table ui . ui_name ( Some ui ) |
let get_clambda_approx ui = assert ( not Config . flambda ) ; match ui . ui_export_info with | Flambda _ -> assert false | Clambda approx -> approx |
let toplevel_approx : ( string , Clambda . value_approximation ) Hashtbl . t = Hashtbl . create 16 |
let record_global_approx_toplevel ( ) = Hashtbl . add toplevel_approx current_unit . ui_name ( get_clambda_approx current_unit ) |
let global_approx id = if Ident . is_predef id then Clambda . Value_unknown else try Hashtbl . find toplevel_approx ( Ident . name id ) with Not_found -> match get_global_info id with | None -> Clambda . Value_unknown | Some ui -> get_clambda_approx ui |
let symbol_for_global id = if Ident . is_predef id then " caml_exn_ " ^ Ident . name id else begin let unitname = Ident . name id in match try ignore ( Hashtbl . find toplevel_approx unitname ) ; None with Not_found -> get_global_info id with | None -> make_symbol ~ unitname ( : Ident . na... |
let unit_for_global id = let sym_label = Linkage_name . create ( symbol_for_global id ) in Compilation_unit . create id sym_label |
let predefined_exception_compilation_unit = Compilation_unit . create ( Ident . create_persistent " __dummy__ " ) ( Linkage_name . create " __dummy__ " ) |
let is_predefined_exception sym = Compilation_unit . equal predefined_exception_compilation_unit ( Symbol . compilation_unit sym ) |
let symbol_for_global ' id = let sym_label = Linkage_name . create ( symbol_for_global id ) in if Ident . is_predef id then Symbol . of_global_linkage predefined_exception_compilation_unit sym_label else Symbol . of_global_linkage ( unit_for_global id ) sym_label |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.